Cerebras runs open-weight models on its own wafer-scale chips, and its API is one of the fastest ways to get tokens back today. You call it with a small Python SDK or with the OpenAI client you already know.
This guide walks you from a fresh API key to streaming, tool calling and strict JSON output. It also covers the current models, the $5 trial, real prices and the errors you will meet.
- Models (5 Dec 2026):
gpt-oss-120bandqwen-3.8-27bare the only Shared Inference models. Others need a Dedicated endpoint. - Prices: GPT OSS 120B is $0.35 in / $0.75 out per million tokens. Qwen 3.8 27B is $0.99 / $1.49.
- Free: a one-time $5 credit after you add a payment method. It expires after 30 days. There is no permanent free tier.
- Code:
pip install cerebras_cloud_sdk(v2.0.0), or point the OpenAI SDK athttps://api.cerebras.ai/v1. - Speed: Cerebras lists about 3,000 tokens/s for GPT OSS 120B. Groq lists about 500 tokens/s for the same model. Both are vendor numbers.
What the Cerebras API Is and When to Use It
Cerebras Inference is a hosted API for open-weight language models. The models run on Cerebras CS-3 systems built around the Wafer-Scale Engine-3 chip, not on GPUs.
The API follows the OpenAI Chat Completions format. So most code written for OpenAI works after you change the key, the base URL and the model name.
It is a good fit when speed matters more than model choice:
- Coding agents: long tool loops finish faster when every step returns in a second or two.
- Voice and chat apps: fast output makes replies feel instant.
- Bulk jobs: summaries, tagging and extraction over many documents.
- Prototyping: quick feedback while you tune prompts.
It is a weaker fit if you need a frontier closed model, built-in web search, or a long list of models. For those, look at OpenRouter or the big labs’ own APIs.
Current Cerebras Models and Model IDs (December 2026)
The public model list is short right now. I checked the official Model Catalog on 5 December 2026, and only two models are on Shared Inference (the pay-as-you-go API).
| Model | Model ID | Context (free / paid) | Max output (free / paid) | Input types | Listed speed |
|---|---|---|---|---|---|
| OpenAI GPT OSS 120B | gpt-oss-120b |
65k / 131k | 32k / 40k | Text | ~3,000 tokens/s |
| Qwen 3.8 27B | qwen-3.8-27b |
64k / 128k | 32k / 40k | Text, image | ~1,850 tokens/s |
A few things changed recently, so older tutorials may be wrong:
- 3 Sep 2026:
qwen-3.8-27blaunched on public endpoints. On the same daygemma-4-31bleft public endpoints (it stays on Dedicated). - 17 Aug 2026:
zai-glm-4.7was scheduled for deprecation. - Older IDs: Llama 4, Qwen 3 Coder 480B and Qwen 3 235B Thinking were all deprecated in 2025.
- Dedicated only: Kimi K3, Kimi K3.1 Pro (added 9 Nov 2026), GLM 5.3 Flash and others need a Dedicated endpoint and an endpoint ID.
Note: Reasoning is on by default. GPT OSS 120B defaults to reasoning_effort medium. Qwen 3.8 27B defaults to high and accepts none, low, medium or high.
Get a Cerebras API Key and Set Up Python
You need Python 3.10 or newer, a terminal and an email address. The SDK I checked is cerebras_cloud_sdk 2.0.0, released on PyPI on 25 November 2026.
- Sign in to the console. Go to cloud.cerebras.ai and sign in. A magic link by email works, so you do not need a password.
- Add a payment method for the trial. New accounts get a one-time $5 credit once a verified payment method is added. You are not charged unless you buy PayGo credits.
- Create a key. Open the API Keys page and create a key. Projects let you group keys and set per-project limits if you have several apps.
- Save the key as an environment variable. On macOS or Linux run
export CEREBRAS_API_KEY="your-key". On Windows PowerShell runsetx CEREBRAS_API_KEY "your-key"and open a new terminal. - Install the SDK. Run
pip install cerebras_cloud_sdkin a virtual environment. Addopenaitoo if you want Example 2. - Run Example 1 below. If it prints a reply, your key, network and model ID are all fine.
Warning: Never paste the key into code you commit. Keep it in an environment variable or a .env file listed in .gitignore.
Example 1: Your First Chat Completion with the Cerebras SDK
The client reads CEREBRAS_API_KEY from the environment by default. Create it once and reuse it, because the SDK sends a few warm-up requests when it starts.
import os
from cerebras.cloud.sdk import Cerebras
client = Cerebras(api_key=os.environ.get("CEREBRAS_API_KEY"))
response = client.chat.completions.create(
model="gpt-oss-120b",
messages=[
{"role": "system", "content": "You are a concise assistant."},
{"role": "user", "content": "Explain what an API key is in two sentences."},
],
max_completion_tokens=400,
)
print(response.choices[0].message.content)
print(response.usage) # prompt, completion and total tokens
print(response.time_info) # Cerebras timing data
Two details are worth knowing:
- max_completion_tokens: this is the current name. Cerebras renamed it from
max_tokensto match OpenAI. - Warm-up: pass
warm_tcp_connection=Falseto the constructor if you do not want the warm-up calls to/v1/tcp_warming.
For async code, import AsyncCerebras instead and await the same call.
Example 2: Use the OpenAI SDK with the Cerebras base_url
If your app already uses the OpenAI Python SDK, you can keep it. Set base_url to https://api.cerebras.ai/v1 and pass your Cerebras key.
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.cerebras.ai/v1",
api_key=os.environ.get("CEREBRAS_API_KEY"),
)
response = client.chat.completions.create(
model="qwen-3.8-27b",
messages=[{"role": "user", "content": "Give me three names for a coffee shop."}],
reasoning_effort="none", # skip reasoning for a simple task
)
print(response.choices[0].message.content)
Cerebras says OpenAI SDK v3 for Python works with the same setup. It needs Python 3.10+ and uses HTTPX2, so check custom proxies or certificate bundles after an upgrade.
Keep these differences from OpenAI in mind:
- n: only
n=1is supported. - Images: send base64 PNG or JPEG data URIs. External HTTPS image URLs are rejected.
- System role on GPT OSS: both
systemanddevelopermap to developer-level instructions, so they may weigh more than on OpenAI. - Extra fields:
reasoning_formatandclear_thinkinggo inextra_bodywith the OpenAI client. The Cerebras SDK takes them as normal arguments.
You can also plug the same base URL into most tools that accept an “OpenAI-compatible” provider. For a full OpenAI walkthrough, see my OpenAI API Python tutorial.
Example 3: Streaming Responses
Set stream=True and loop over the chunks. Usage and timing data arrive only in the last chunk.
from cerebras.cloud.sdk import Cerebras
client = Cerebras()
stream = client.chat.completions.create(
model="gpt-oss-120b",
messages=[{"role": "user", "content": "Write a 5-line poem about fast chips."}],
stream=True,
)
for chunk in stream:
if chunk.choices and chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)
if getattr(chunk, "usage", None):
print("\n\nTokens used:", chunk.usage.total_tokens)
Cerebras sends tokens in batches, at up to 200 evenly spaced events per second. So do not write code that expects exactly one token per chunk.
The raw stream ends with a standard data: [DONE] event, which arrives exactly once. Streaming also works with tools and structured outputs.
Example 4: Tool Calling (Function Calling)
Both public models support tool calling, strict mode, parallel calls and multi-turn calls. The tool_choice options are none, auto, required or a named function.
The flow is simple. You describe a tool, the model asks for it, your code runs it, and you send the result back.
import json
from cerebras.cloud.sdk import Cerebras
client = Cerebras()
def get_weather(city):
# Replace with a real weather API call
return json.dumps({"city": city, "temp_c": 22, "condition": "sunny"})
tools = [{
"type": "function",
"function": {
"name": "get_weather",
"strict": True,
"description": "Get the current weather for a city.",
"parameters": {
"type": "object",
"properties": {
"city": {"type": "string", "description": "City and country"}
},
"required": ["city"],
"additionalProperties": False,
},
},
}]
messages = [{"role": "user", "content": "Is Toronto warmer than Montreal?"}]
response = client.chat.completions.create(
model="qwen-3.8-27b",
messages=messages,
tools=tools,
parallel_tool_calls=True,
)
msg = response.choices[0].message
if msg.tool_calls:
messages.append(msg.model_dump()) # keep the assistant turn as returned
for call in msg.tool_calls:
args = json.loads(call.function.arguments)
messages.append({
"role": "tool",
"tool_call_id": call.id,
"content": get_weather(args["city"]),
})
final = client.chat.completions.create(model="qwen-3.8-27b", messages=messages, tools=tools)
print(final.choices[0].message.content)
else:
print(msg.content)
With strict: True, every object in the schema must set additionalProperties to false. For Qwen 3.8 27B, do not use pattern, minLength or maxLength in strict tool schemas.
Tip: Cerebras warns that GPT OSS 120B may call tools you never defined. Check each tool name against your own list before you run anything.
For a deeper look at tool loops across providers, my Groq API guide uses the same OpenAI-style format.
Example 5: Structured Outputs (Strict JSON Schema)
Structured outputs force the reply to match a JSON schema. With strict: True, Cerebras uses constrained decoding, so the output always fits the supported schema subset.
import json
from pydantic import BaseModel
from cerebras.cloud.sdk import Cerebras
client = Cerebras()
class Movie(BaseModel):
title: str
director: str
year: int
schema = Movie.model_json_schema()
schema["additionalProperties"] = False # required for strict mode
completion = client.chat.completions.create(
model="gpt-oss-120b",
messages=[{"role": "user", "content": "Suggest one sci-fi movie from the 1990s."}],
response_format={
"type": "json_schema",
"json_schema": {"name": "movie", "strict": True, "schema": schema},
},
)
movie = Movie(**json.loads(completion.choices[0].message.content))
print(movie.title, movie.year)
The strict schema rules are tight, so plan for them:
- Root: must be an object with
properties. Root arrays and root unions are not allowed. - Limits: up to 10 nesting levels, 500 object properties and 500 enum values in total.
- Not supported:
oneOf,allOf, recursive schemas, stringpatternandformat, andminItemsormaxItems. - Key order: output keys follow the order in your schema.
Warning: Do not send tools and response_format in the same request. GPT OSS 120B rejects it. Call tools first, then format the result in a second request.
If you want plain valid JSON without a schema, use response_format={"type": "json_object"} and ask for JSON in the prompt. My structured outputs guide compares this with Claude, OpenAI and Gemini.
The Same Call with curl
Use this to test a key without Python. The endpoint is https://api.cerebras.ai/v1/chat/completions.
curl https://api.cerebras.ai/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $CEREBRAS_API_KEY" \
-d '{
"model": "gpt-oss-120b",
"messages": [{"role": "user", "content": "Say hello in French."}],
"max_completion_tokens": 200
}'
On Windows PowerShell, use curl.exe and $env:CEREBRAS_API_KEY, and put the command on one line.
Reported Speeds and Prompt Caching
Speed is the main reason people pick Cerebras. These numbers are what each vendor publishes for its own service. They are not my own tests, and real speed varies with prompt size, load and reasoning settings.
| Model | Cerebras (vendor figure) | Groq (vendor figure) |
|---|---|---|
| GPT OSS 120B | ~3,000 tokens/s | ~500 tokens/s |
| Qwen 3.8 27B | ~1,850 tokens/s | ~450 tokens/s |
Remember that a reasoning model spends tokens thinking before it answers. A high tokens-per-second rate shortens that hidden wait, which is why agents feel much faster here.
How prompt caching works on Cerebras
Prompt caching is automatic, so you need no code changes. The system matches the start of your prompt in 128-token blocks and reuses blocks it has seen recently in your organization.
- Lifetime: at least 5 minutes, and up to 1 hour depending on load.
- Price: cached input tokens cost the same as fresh input. The gain is speed and rate-limit headroom, not a discount.
- Rate limits: cached tokens do not count toward your uncached TPM limit.
- Routing hint: set
prompt_cache_keyto a conversation ID so turns hit the same cache (max 1,024 characters). - Check it: read
usage.prompt_tokens_details.cached_tokensin the response.
Put static content first (system prompt, tool schemas, long documents) and changing content last. A timestamp at the top of the prompt breaks the cache for everything after it.
Cerebras Free Trial and Rate Limits
Cerebras no longer has a permanent free tier. Its docs say the Free Trial is bounded by time and credit: $5 that expires 30 days after it is granted.
When the credit runs out or expires, API and Playground access pause until you buy PayGo credits. Your first purchase moves you to the Developer tier, which removes the hourly and daily token caps.

| Tier and model | RPM | Uncached TPM | Total TPM | Daily tokens |
|---|---|---|---|---|
Free Trial: gpt-oss-120b |
5 | 30K | 90K | 1M (also 1M per hour) |
Free Trial: qwen-3.8-27b |
300 | 150K | 750K* | No cap |
Developer: gpt-oss-120b |
1,000 | 500K | 1.5M | No cap |
Developer: qwen-3.8-27b |
300 | 150K | 750K* | No cap |
*Qwen’s total TPM is temporarily raised from 450K to 750K. Image requests on Qwen allow 2 images on the trial and 10 on Developer, within a 10 MiB payload.
Limits use a token bucket that refills all the time, not at fixed resets. Cerebras also estimates each request up front, using your max_completion_tokens, so a huge value can trigger a 429 early.
Tip: The trial’s 5 RPM on GPT OSS 120B is the tightest limit. For quick tests on the trial, Qwen 3.8 27B gives you far more room. See my API rate limits guide for retry patterns.
Cerebras API Pricing with a Worked Example
Developer tier pricing is per million tokens, from the official pricing page and model pages. Enterprise pricing is by quote.

| Model | Input / 1M | Cached input / 1M | Output / 1M |
|---|---|---|---|
gpt-oss-120b |
$0.35 | $0.35 (same rate) | $0.75 |
qwen-3.8-27b |
$0.99 | $0.99 (same rate) | $1.49 |
Worked example: a support chatbot
Say each request has 2,000 input tokens and 500 output tokens, and you handle 10,000 requests a day. That is 20M input and 5M output tokens daily.
- GPT OSS 120B: 20 x $0.35 = $7.00 input, plus 5 x $0.75 = $3.75 output. Total $10.75 a day, or about $322.50 over 30 days.
- Qwen 3.8 27B: 20 x $0.99 = $19.80, plus 5 x $1.49 = $7.45. Total $27.25 a day, or about $817.50 over 30 days.
- One request on GPT OSS 120B: about $0.0011, so the $5 trial covers roughly 4,650 of them.
On the trial, though, the 1M daily token cap on GPT OSS 120B allows about 400 of these 2,500-token requests per day. Count reasoning tokens too, because they are billed as output.
For prices across many providers side by side, see my AI API pricing comparison.
Cerebras vs Groq: Which Fast API Fits You?
Groq is the closest rival. Both sell very fast inference of open-weight models on custom chips, and both use the OpenAI format. Data below comes from each vendor’s docs on 5 December 2026.
| Feature | Cerebras | Groq |
|---|---|---|
| Hardware | Wafer-Scale Engine (CS-3) | LPU |
| Base URL | https://api.cerebras.ai/v1 |
https://api.groq.com/openai/v1 |
| Self-serve text models | 2 (GPT OSS 120B, Qwen 3.8 27B) | More, incl. GPT OSS 20B, plus Whisper speech-to-text |
| GPT OSS 120B price (in / out) | $0.35 / $0.75 | $0.33 / $0.71 |
| Qwen 3.8 27B price (in / out) | $0.99 / $1.49 | $0.80 / $4.00 |
| GPT OSS 120B speed (vendor) | ~3,000 tokens/s | ~500 tokens/s |
| Free option | $5 trial credit, 30 days | Ongoing Free plan with low limits (GPT OSS 120B: 30 RPM, 8K TPM, 200K TPD) |
| Paid GPT OSS 120B limits | 1K RPM, 500K uncached / 1.5M total TPM | 1K RPM, 250K TPM |
| Max output, Qwen 3.8 27B (paid) | 40k | 16,384 |
| Own Python SDK | cerebras_cloud_sdk |
groq |
Since both speak the OpenAI format, you can keep one client and switch base URLs. My Groq API guide has the full Groq setup.
Troubleshooting: Common Cerebras API Errors and Fixes
All SDK errors inherit from cerebras.cloud.sdk.APIError. The SDK retries connection errors, 408, 429 and 5xx errors twice by default, with a short backoff. The default timeout is 1 minute.
| Status / error | What it usually means | Fix |
|---|---|---|
400 BadRequestError |
Bad field, unsupported parameter or a strict schema that breaks the rules | Add additionalProperties: false to every object. Do not mix tools and response_format. |
| 400 “HTTPS image URLs are not supported” | You sent an image link | Send a base64 PNG or JPEG data URI instead. |
| 400 “Model {model} does not support image inputs” | Image sent to gpt-oss-120b |
Use qwen-3.8-27b for images. |
401 AuthenticationError |
Missing or wrong key | Check CEREBRAS_API_KEY is set in the same terminal. |
| 402 Payment Required | Trial credit used up or expired | Buy PayGo credits in the console. |
404 NotFoundError |
Old or mistyped model ID | Use gpt-oss-120b or qwen-3.8-27b. |
| 413 Content Too Large | Payload, image count or image size over the limit (15,000 px per side) | Resize images and send fewer per request. |
429 RateLimitError |
RPM or TPM hit; the message says uncached or total bucket | Lower max_completion_tokens, back off, or improve cache hits. |
| 500 / 503 | Server error or service unavailable | Let the SDK retry, then check the status page. |
APIConnectionError / APITimeoutError |
Network, proxy or timeout issue | Raise timeout, check proxy and certificate settings. |
Here is a handler you can drop into any script:
import cerebras.cloud.sdk
from cerebras.cloud.sdk import Cerebras
client = Cerebras(max_retries=3, timeout=30.0)
try:
r = client.chat.completions.create(
model="gpt-oss-120b",
messages=[{"role": "user", "content": "Hi"}],
)
print(r.choices[0].message.content)
except cerebras.cloud.sdk.APIConnectionError as e:
print("Could not reach the API:", e.__cause__)
except cerebras.cloud.sdk.RateLimitError:
print("429: slow down or lower max_completion_tokens")
except cerebras.cloud.sdk.APIStatusError as e:
print("Error", e.status_code, e.response.text)
Note: Since 24 April 2026, validation errors return 400 instead of 422. If old code catches UnprocessableEntityError, switch it to BadRequestError or catch APIStatusError.
A few other gotchas:
- 429 right after buying credits: buying credits moves you to the Developer tier, but per-model limits still apply. Check the Limits page in the console for your exact numbers.
- Empty answer with reasoning on: the model may have spent the budget thinking. Raise
max_completion_tokensor lowerreasoning_effort. - Different tone than on OpenAI: on GPT OSS the system role acts at developer level, so soften strong system prompts.
Frequently Asked Questions
Is the Cerebras API free?
Not permanently. New accounts get a one-time $5 credit after adding a payment method, and it expires 30 days after it is granted. After that you pay per token.
What is the Cerebras API base URL?
It is https://api.cerebras.ai/v1. Use it as base_url in the OpenAI SDK, or the full chat endpoint https://api.cerebras.ai/v1/chat/completions with curl.
Which models can I use on Cerebras right now?
On Shared Inference, only gpt-oss-120b and qwen-3.8-27b as of 5 December 2026. Models like Kimi K3.1 Pro and Gemma 4 31B need a Dedicated endpoint.
Can I use the OpenAI Python SDK with Cerebras?
Yes. Set base_url and your Cerebras key, then use the Cerebras model ID. Pass Cerebras-only fields like reasoning_format through extra_body.
Does Cerebras support function calling and JSON mode?
Yes. Both public models support tool calling with strict mode and parallel calls, plus json_object and strict json_schema outputs. Just do not combine tools and response_format in one request.
Is prompt caching cheaper on Cerebras?
No. Cached input is billed at the normal input rate. Caching makes responses start faster and does not count toward your uncached rate limit.
Is Cerebras really faster than Groq?
On vendor figures, yes: about 3,000 tokens/s versus about 500 tokens/s for GPT OSS 120B. Treat these as vendor claims and measure with your own prompts.
Can I send images to the Cerebras API?
Yes, with qwen-3.8-27b. Send base64 PNG or JPEG data URIs through Chat Completions, up to 2 images on the trial or 10 on Developer.
Sources
- Cerebras Model Catalog
- Cerebras: OpenAI GPT OSS model page
- Cerebras: Qwen 3.8 27B model page
- Cerebras Inference pricing
- Cerebras Rate Limits
- Cerebras OpenAI Compatibility
- Cerebras Tool Calling
- Cerebras Structured Outputs
- Cerebras Prompt Caching
- Cerebras Error Codes
- Cerebras Change Log
- cerebras_cloud_sdk on PyPI
- Groq Supported Models
- Groq Rate Limits



