Cerebras
Access 3 Cerebras models through Mastra’s model router. Authentication is handled automatically using the CEREBRAS_API_KEY
environment variable.
Learn more in the Cerebras documentation .
CEREBRAS_API_KEY=your-api-key
import { Agent } from "@mastra/core";
const agent = new Agent({
name: "my-agent",
instructions: "You are a helpful assistant",
model: "cerebras/gpt-oss-120b"
});
// Generate a response
const response = await agent.generate("Hello!");
// Stream a response
const stream = await agent.stream("Tell me a story");
for await (const chunk of stream) {
console.log(chunk);
}
Mastra uses the OpenAI-compatible /chat/completions
endpoint. Some provider-specific features may not be available. Check the Cerebras documentation for details.
Models
Model | Context | Tools | Reasoning | Image | Audio | Video | Input $/1M | Output $/1M |
---|---|---|---|---|---|---|---|---|
cerebras/qwen-3-235b-a22b-instruct-2507 | 131K | $0.60 | $1 | |||||
cerebras/qwen-3-coder-480b | 131K | $2 | $2 | |||||
cerebras/gpt-oss-120b | 131K | $0.25 | $0.69 |
Advanced Configuration
Custom Headers
const agent = new Agent({
name: "custom-agent",
model: {
url: "https://api.cerebras.ai/v1/chat/completions",
modelId: "gpt-oss-120b",
apiKey: process.env.CEREBRAS_API_KEY,
headers: {
"X-Custom-Header": "value"
}
}
});
Dynamic Model Selection
const agent = new Agent({
name: "dynamic-agent",
model: ({ runtimeContext }) => {
const useAdvanced = runtimeContext.task === "complex";
return useAdvanced
? "cerebras/gpt-oss-120b"
: "cerebras/qwen-3-235b-a22b-instruct-2507";
}
});
Direct Provider Installation
This provider can also be installed directly as a standalone package, which can be used instead of the Mastra model router string. View the package documentation for more details.
npm install @ai-sdk/cerebras