We designed the Cerebras API to be mostly compatible with OpenAI’s client libraries, making it simple to configure your existing applications to run on Cerebras and take advantage of our inference capabilities. We also offer dedicated Cerebras Python and Cerebras TypeScript SDKs.

Configuring OpenAI to Use Cerebras API

To start using Cerebras with OpenAI’s client libraries, simply pass your Cerebras API key to the apiKey parameter and change the baseURL to https://api.cerebras.ai/v1:
import os
import openai

client = openai.OpenAI(
    base_url="https://api.cerebras.ai/v1",
    api_key=os.environ.get("CEREBRAS_API_KEY")
)

Developer Role

This info is only applicable to the gpt-oss-120b model.
For gpt-oss-120b, our API maps the “system” role to a “developer” level in our prompt hierarchy. When you send messages with role: "system", we insert these instructions into our system prompt behind the scenes, giving you significant control over model behavior while preserving core safety guidelines.

Key Difference from OpenAI

Unlike OpenAI’s direct API, your “system” role messages have enhanced influence in our implementation. This means you may see different behavior compared to calling OpenAI directly - this is expected and by design.

Common Issues

If you’re seeing accuracy degradation, check if you’re providing conflicting instructions in both reasoning effort and system role messages. Remove redundant guidance. If you’re seeing unexpected behavior, remember that our API processes “system” role messages differently than OpenAI’s direct API. Adjust your instructions accordingly.

Currently Unsupported OpenAI Features

Note that although Cerebras API is mostly OpenAI compatible, there are a few features we don’t support just yet: Text Completions
The following fields are currently not supported and will result in a 400 error if they are supplied:
  • frequency_penalty
  • logit_bias
  • presence_penalty
  • parallel_tool_calls
  • service_tier
Streaming with JSON Mode
While Cerebras supports a stream parameter, note that JSON mode is not compatible with streaming.