Model providers
Gateway
Cerebras
Route Cerebras requests through Inference for full observability.
Route your Cerebras requests through the Inference gateway to get cost tracking, latency monitoring, and analytics. Cerebras has a dedicated provider routing ID, so you use the OpenAI SDK with x-inference-provider: cerebras.
Prefer automatic setup? Run
inf instrument to instrument your codebase in seconds. Learn moreSetup
Get your API keys
You need two keys:
- Inference project API key — from your dashboard under API Keys
- Cerebras API key — from your Cerebras dashboard
Set environment variables
export INFERENCE_API_KEY=<your-project-api-key>
export CEREBRAS_API_KEY=<your-cerebras-api-key>Update your code
Point the SDK at the gateway. Your project API key goes in apiKey, and your Cerebras key goes in x-inference-provider-api-key.
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.inference.net/v1",
apiKey: process.env.INFERENCE_API_KEY,
defaultHeaders: {
"x-inference-provider-api-key": process.env.CEREBRAS_API_KEY,
"x-inference-provider": "cerebras",
"x-inference-environment": process.env.NODE_ENV,
},
});
const response = await client.chat.completions.create({
model: "llama3.1-8b",
messages: [{ role: "user", content: "Hello" }],
}, {
headers: { "x-inference-task-id": "default" },
});