> ## Documentation Index
> Fetch the complete documentation index at: https://inference-docs.cerebras.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# OpenAI Compatibility

> Use the OpenAI Client Libraries with Cerebras Inference

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](https://api.cerebras.ai/v1):

<CodeGroup>
  ```python Python theme={null}
  import os
  import openai

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

  ```javascript Node.js theme={null}
  import OpenAI from "openai";

  const client = new OpenAI({
    apiKey: process.env.CEREBRAS_API_KEY,
    baseURL: "https://api.cerebras.ai/v1"
  });
  ```
</CodeGroup>

## Developer-Level Instructions via System and Developer Roles

<Note>This info is only applicable to the `gpt-oss-120b` model. </Note>

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`.

<Accordion title="Example: Using the OpenAI Client">
  When using the OpenAI client with Cerebras API, non-standard parameters must be passed through `extra_body`:

  <CodeGroup>
    ```python Python theme={null}
    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
        }
    )
    ```

    ```javascript Node.js theme={null}
    const client = new OpenAI({
        baseURL: "https://api.cerebras.ai/v1",
        apiKey: process.env.CEREBRAS_API_KEY
    });

    const response = await 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
        }
    });
    ```
  </CodeGroup>
</Accordion>

<Accordion title="Example: Using the Cerebras SDK Client">
  When using the Cerebras SDK client, non-standard parameters can be passed as regular parameters:

  <CodeGroup>
    ```python Python theme={null}
    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
    )
    ```

    ```javascript Node.js theme={null}
    const client = new Cerebras({
        apiKey: process.env.CEREBRAS_API_KEY
    });

    const response = await client.chat.completions.create({
        model: "zai-glm-4.7",
        messages: [...],
        reasoning_effort: "none",  // Standard parameter
        clear_thinking: false       // Non-standard parameter
    });
    ```
  </CodeGroup>
</Accordion>
