Cerebras
The Cerebras provider offers access to powerful language models through the Cerebras API, including their high-speed inference capabilities powered by Wafer-Scale Engines and CS-3 systems.
Start with AI Gateway for models in its catalog (recommended), or use @ai-sdk/cerebras to connect directly to Cerebras.
Using AI Gateway
The AI SDK uses AI Gateway by default for model strings. Gateway provides access to models across providers through a single API key, with usage and cost tracking. Install ai:
$ pnpm add ai
$ npm install ai
$ yarn add ai
$ bun add ai
Set an AI Gateway API key in your environment:
Vercel deployments can also use OIDC authentication. See the AI Gateway provider documentation for configuration and the model catalog for available models.
The example sets providerOptions.gateway.order to ['cerebras']. This sends the request to Cerebras first, then falls back to other available providers of the same model if Cerebras is unavailable or the request fails. order sets a preference; it does not restrict fallback to Cerebras. See provider ordering.
The dropdown lists models served by Cerebras through Gateway with a corresponding direct-provider example. Provider availability depends on the model and your team's Provider Allowlist.
Using @ai-sdk/cerebras
For direct access to Cerebras, install ai and @ai-sdk/cerebras:
$ pnpm add ai @ai-sdk/cerebras
$ npm install ai @ai-sdk/cerebras
$ yarn add ai @ai-sdk/cerebras
$ bun add ai @ai-sdk/cerebras
Set your Cerebras API credential in the CEREBRAS_API_KEY environment variable:
AI Gateway does not expose every API in @ai-sdk/cerebras. Use the direct provider for provider-specific APIs or custom connection settings.
The following sections document the direct @ai-sdk/cerebras provider,
including its model factories and settings. Gateway model and feature
availability can differ.
API keys can be obtained from the Cerebras Platform.
Provider Instance
You can import the default provider instance cerebras from @ai-sdk/cerebras:
For custom configuration, you can import createCerebras and create a provider instance with your settings:
You can use the following optional settings to customize the Cerebras provider instance:
-
baseURL string
Use a different URL prefix for API calls. The default prefix is
https://api.cerebras.ai/v1. -
apiKey string | PromiseLike<string> | (() => string | PromiseLike<string>)
API key that is being sent using the
Authorizationheader. It defaults to theCEREBRAS_API_KEYenvironment variable.A function is called before each request and may return a promise. Use it to supply refreshed credentials; a promise value resolves to the same key each time.
-
headers Record<string,string>
Custom headers to include in the requests.
-
fetch (input: RequestInfo, init?: RequestInit) => Promise<Response>
Custom fetch implementation.
Language Models
You can create language models using a provider instance:
Cerebras language models can be used in the streamText function
(see AI SDK Core).
You can create Cerebras language models using a provider instance. The first argument is the model ID, e.g. gpt-oss-120b:
You can also use the .languageModel() and .chat() methods:
Reasoning Models
Cerebras offers reasoning models including gpt-oss-120b and gemma-4-31b that generate intermediate thinking tokens before their final response. The reasoning output is streamed through the standard AI SDK reasoning parts.
For gpt-oss-120b, you can control the reasoning depth using the reasoningEffort provider option:
See AI SDK UI: Chatbot for more details on how to integrate reasoning into your chatbot.
Provider Options
The following optional provider options are available for Cerebras language models:
-
parallelToolCalls boolean
Whether to enable parallel function calling during tool use. Defaults to
true. -
logprobs boolean
Whether to return log probabilities for generated tokens. Defaults to
false. -
topLogprobs number
Number of most likely tokens to return at each token position. Accepts values from
0through20. Requireslogprobsto betrue. -
logitBias Record<string, number>
Maps token IDs to bias values from
-100through100. -
serviceTier 'auto' | 'default' | 'flex' | 'priority'
Controls request priority on a dedicated endpoint with service tiers enabled through Cerebras private preview. Service tiers are not available with Shared Inference on the Developer Tier.
defaultuses standard priority,flexuses the lowest priority,autostarts at standard priority and falls back toflexwhen needed, andpriorityrequests the highest configured priority.See the Cerebras service tiers documentation.
When the API returns
service_tier, the effective tier is surfaced onresult.providerMetadata.cerebras.serviceTier(or the awaited stream metadata). For example, anautorequest can returnflex, and apriorityrequest can returnauto. The metadata field is omitted when the response field is missing ornull; it is never inferred from the requested tier. -
queueThreshold number
Maximum acceptable queue time, in integer milliseconds, for
flex/autorequests on a supported endpoint. If the expected queue time exceeds the threshold, the request is rejected instead of queued. Sent as thequeue_thresholdheader, taking precedence over a custom header with that name. Valid range:50–20000(inclusive). -
reasoningEffort 'none' | 'low' | 'medium' | 'high'
Controls the amount of reasoning performed by supported models. Supported values and defaults depend on the model.
-
reasoningFormat 'none' | 'parsed' | 'text_parsed' | 'raw' | 'hidden'
Controls how reasoning content appears in the response. Format support depends on the model.
-
prediction { type: 'content'; content: string | Array<{ type: 'text'; text: string }> }
Supplies predicted output that can accelerate requests where most of the response is already known.
-
promptCacheKey string
Routes related requests to the same prompt cache. The value can contain up to 1024 characters and requires account-level enablement.
-
user string
A unique identifier representing your end-user, which can help with monitoring and abuse detection.
-
strictJsonSchema boolean
Whether to use strict JSON schema validation. When
true, the model uses constrained decoding to guarantee schema compliance. Defaults totrue.
For example:
Model Capabilities
| Model | Image Input | Object Generation | Tool Usage | Tool Streaming | Reasoning |
|---|---|---|---|---|---|
gpt-oss-120b | |||||
gemma-4-31b |