Skip to main content
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-Level Instructions via System and Developer Roles

This info is only applicable to the gpt-oss-120b model.
For gpt-oss-120b, the API supports both the system and developer message roles. Both are mapped to a developer-level instruction layer in the prompt hierarchy, elevated above normal user instructions and injected into the model’s internal system prompt. This gives you significant control over the assistant’s tone, style, and behavior while preserving the model’s built-in safety guardrails. The developer role is functionally equivalent to system – the system role remains supported for backwards compatibility.

Key Differences from OpenAI

OpenAI’s API distinguishes between system and developer roles with different behavior. On Cerebras, both roles act at the developer level, meaning they may have stronger influence than system messages in OpenAI’s API. As a result, the same prompt may yield different behavior here compared to OpenAI. This is expected.

Passing Non-Standard Parameters

  • OpenAI: Non-standard parameters (e.g., clear_thinking for Z.ai GLM) need to be passed through extra_body. Standard OpenAI parameters like reasoning_effort work directly.
  • Cerebras SDK: Non-standard parameters can be passed in either extra_body or as regular parameters like model.
When using the OpenAI client with Cerebras API, non-standard parameters must be passed through extra_body:
client = OpenAI(
    base_url="https://api.cerebras.ai/v1",
    api_key=os.environ.get("CEREBRAS_API_KEY")
)

response = client.chat.completions.create(
    model="zai-glm-4.7",
    messages=[...],
    reasoning_effort="none",  # Standard parameter, no extra_body needed
    extra_body={
        "clear_thinking": False  # Non-standard: must use extra_body
    }
)
When using the Cerebras SDK client, non-standard parameters can be passed as regular parameters:
client = Cerebras(
    api_key=os.environ.get("CEREBRAS_API_KEY")
)

response = client.chat.completions.create(
    model="zai-glm-4.7",
    messages=[...],
    reasoning_effort="none",  # Standard parameter
    clear_thinking=False       # Non-standard parameter
)