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.

Configure OpenAI to use the 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:

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.

Unsupported Parameter Combinations

Support for combining tools and response_format is model-dependent. gpt-oss-120b rejects requests containing both fields. Other models may accept the combination but prioritize tool calling, so response_format should not be relied upon. For portable behavior across Cerebras models, use one of the following approaches:
  • Tool calling only — Omit response_format and let the model invoke tools. If you need structured arguments, define them in the tool’s parameters JSON schema, which the model will follow.
  • Structured outputs only — Omit tools and use response_format with a JSON schema. See Structured Outputs.
  • Two-step pipeline — Make a first call with tools to gather data, then make a second call with response_format to format the final result.
See Tool Use and Structured Outputs for details on each capability.

Pass 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:
When using the Cerebras SDK client, non-standard parameters can be passed as regular parameters: