What is Vercel AI SDK?
The Vercel AI SDK is a powerful TypeScript toolkit for building AI-powered applications with React, Next.js, Vue, Svelte, and more. It provides a unified interface for working with different AI providers, streaming responses, and building interactive AI experiences. Learn more at sdk.vercel.ai. By integrating Cerebras with the Vercel AI SDK, you can leverage ultra-fast inference speeds while using familiar AI SDK patterns and components.Prerequisites
Before you begin, ensure you have:- Cerebras API Key - Get a free API key here
- Node.js 20 or higher - Download from nodejs.org
- npm, yarn, or pnpm - Package manager for installing dependencies
Configure Vercel AI SDK with Cerebras
1
Install required dependencies
Install the Vercel AI SDK and the OpenAI-compatible provider package:
2
Configure environment variables
Create a
.env.local file in your project root to store your Cerebras API key securely:If you’re using Next.js, avoid prefixing with
NEXT_PUBLIC_ to keep your API key private and prevent browser exposure.3
Create a Cerebras provider instance
Set up an OpenAI-compatible provider configured to use Cerebras’s API endpoint. This routes all requests through Cerebras’s infrastructure:The
baseURL parameter points to Cerebras’s API endpoint, while the custom header helps us track integration usage and provide better support.4
Generate streaming text responses
Use the The
streamText function to generate streaming text responses. This is perfect for chat interfaces where you want to show responses as they’re generated:streamText function returns an async iterable that yields text chunks as they’re generated, providing a smooth user experience with Cerebras’s ultra-fast inference.5
Generate text responses
Use the The
generateText function for non-streaming text generation:generateText function returns the complete response at once, which is useful for batch processing or when you don’t need streaming.Available Models
You can use any of the following Cerebras models with the Vercel AI SDK:| Model | Description | Best For |
|---|---|---|
llama-3.3-70b | Meta’s latest Llama model | Best for complex reasoning, long-form content, and tasks requiring deep understanding |
qwen-3-32b | Qwen’s powerful model | Balanced performance for general-purpose applications |
llama3.1-8b | Smaller, faster model | Fastest option for simple tasks and high-throughput scenarios |
gpt-oss-120b | Large open-source model | Largest model for the most demanding tasks |
zai-glm-4.6 | Advanced 357B parameter model | Advanced 357B parameter model with strong reasoning capabilities |
Advanced Features
Tool Calling
The Vercel AI SDK supports tool calling (function calling) with Cerebras models. This allows the model to call external functions and use their results:Troubleshooting
API Key Not Found
API Key Not Found
If you see an error about missing API keys:
- Verify your
.env.localfile containsCEREBRAS_API_KEY - Restart your development server after adding environment variables
- In production, ensure environment variables are set in your deployment platform (Vercel, AWS, etc.)
- Check that you’re not accidentally using
NEXT_PUBLIC_prefix
Model Not Found
Model Not Found
If you receive a “model not found” error:
- Check that you’re using a valid Cerebras model name:
llama-3.3-70b,qwen-3-32b,llama3.1-8b, orgpt-oss-120b - Ensure you’re using the correct format:
cerebras('model-name') - Verify your API key has access to the requested model
- Try a different model to isolate the issue
Streaming Not Working
Streaming Not Working
If streaming responses aren’t displaying:
- Ensure you’re using
streamTextinstead ofgenerateTextfor streaming - Check that your API route returns
result.toDataStreamResponse() - Verify your client component uses the
useChatoruseCompletionhook correctly - Check browser console for network errors
- Ensure your hosting platform supports streaming responses
TypeScript Errors
TypeScript Errors
If you encounter TypeScript errors:
- Make sure you have
@types/nodeinstalled:npm install -D @types/node - Verify your
tsconfig.jsonincludes the necessary compiler options - Check that all AI SDK packages are up to date:
npm update ai @ai-sdk/openai-compatible - Ensure you’re using TypeScript 4.5 or higher
Rate Limiting or Timeout Errors
Rate Limiting or Timeout Errors
If you experience rate limiting or timeouts:
- Check your Cerebras API key quota and usage limits
- Implement retry logic with exponential backoff
- Consider using smaller models like
llama3.1-8bfor high-volume applications - Monitor your request patterns and optimize batch processing
Next Steps
- Explore the Vercel AI SDK documentation for more features and examples
- Try different Cerebras models to find the best fit for your use case
- Check out example applications built with the AI SDK
- Switch to the latest model by following our GLM4.6 migration guide

