# Cerebras

[Cerebras Inference](https://inference-docs.cerebras.ai/) hosts open-weight models on Cerebras inference systems. AISIX places those models behind one OpenAI-compatible API and centralizes upstream credentials, caller access, rate limits, and usage accounting.

## Prerequisites[​](#prerequisites "Direct link to Prerequisites")

Before starting, prepare the following:

* One AISIX setup:

  <!-- -->

  * For AISIX Enterprise or AISIX Cloud, an environment with an attached gateway and a write-scoped admin token. For AISIX Enterprise, follow the [AISIX Enterprise getting-started guide](https://docs.api7.ai/ai-gateway/getting-started/aisix-cloud-quickstart.md). To request AISIX Cloud access, [contact API7](https://api7.ai/contact).
  * For the open-source AISIX gateway, prepare either a local AISIX installation or the Docker setup from the [AISIX OSS getting-started guide](https://docs.api7.ai/ai-gateway/getting-started/gateway-quickstart.md). Configure the gateway to load a declarative resources file.

* A Cerebras API key from the [Cerebras Cloud console](https://cloud.cerebras.ai/).

* `curl` and `jq`.

## Configure with AISIX Enterprise or AISIX Cloud[​](#configure-with-aisix-enterprise-or-aisix-cloud "Direct link to Configure with AISIX Enterprise or AISIX Cloud")

Export the control-plane connection details:

```
# AISIX_CP is the Admin API base URL; include /api and omit a trailing slash

# The local AISIX Enterprise quickstart uses http://localhost:8080/api

export AISIX_CP="YOUR_AISIX_CONTROL_PLANE_API_URL"

export AISIX_TOKEN="YOUR_ADMIN_TOKEN"

export ENV_ID="YOUR_ENVIRONMENT_ID"
```

Create a provider key, model alias, and caller API key for the Cerebras-backed chat-completions route.

Because the Cerebras API is OpenAI-compatible, AISIX connects through the `openai` adapter and uses the Cerebras API root as `api_base`.

### Create a Provider Key[​](#create-a-provider-key "Direct link to Create a Provider Key")

Create the provider key that stores the Cerebras credential and API root:

```
# Replace with your value

export CEREBRAS_API_KEY="YOUR_PROVIDER_API_KEY"



PROVIDER_KEY_ID=$(curl -sS -X POST "$AISIX_CP/provider_keys" \

  -H "Authorization: Bearer $AISIX_TOKEN" \

  -H "Content-Type: application/json" \

  -d '{

    "display_name": "cerebras-prod",

    "provider": "cerebras",

    "api_key": "'"${CEREBRAS_API_KEY}"'",

    "api_base": "https://api.cerebras.ai/v1",

    "allowed_environments": ["'"${ENV_ID}"'"]

  }' | jq -r '.provider_key.id')



echo "$PROVIDER_KEY_ID"
```

❶ `provider` is `cerebras`. The AISIX Cloud Admin API derives the adapter from the catalog provider; the `adapter` field is only accepted on BYO provider keys.

❷ `api_key` stores the Cerebras API key. Cerebras authenticates with HTTP bearer authentication, which is what the `openai` adapter already sends. The value follows the credential-handling behavior in [Provider Keys](https://docs.api7.ai/ai-gateway/models/provider-keys.md#credential-handling).

❸ `api_base` is `https://api.cerebras.ai/v1`, the same root that Cerebras documents as the `baseURL` for [OpenAI client libraries](https://inference-docs.cerebras.ai/resources/openai). It already includes the `/v1` path, so AISIX appends the endpoint path, such as `/chat/completions`, directly to it. For the `cerebras` catalog provider the field is optional — the AISIX Cloud Admin API fills in this same value when you omit it — but the examples set it explicitly so the root each key targets stays visible in the configuration.

The command captures the returned provider key ID in `PROVIDER_KEY_ID`.

### Create a Model[​](#create-a-model "Direct link to Create a Model")

Cerebras model IDs are bare identifiers with no vendor prefix, even when the weights come from another vendor. The OpenAI open-weight model is `gpt-oss-120b` on Cerebras, and the Google model is `gemma-4-31b`. Check the [Cerebras model catalog](https://inference-docs.cerebras.ai/models/overview) for the current list before you create an alias; the catalog is short and rotates as models are added and retired. Current IDs include `gpt-oss-120b`, `gemma-4-31b`, and `zai-glm-4.7`.

Create the model alias callers will send in requests:

```
MODEL_ID=$(curl -sS -X POST "$AISIX_CP/environments/$ENV_ID/models" \

  -H "Authorization: Bearer $AISIX_TOKEN" \

  -H "Content-Type: application/json" \

  -d '{

    "display_name": "cerebras-gptoss-prod",

    "model_name": "gpt-oss-120b",

    "provider_key_id": "'"${PROVIDER_KEY_ID}"'"

  }' | jq -r '.model.id')



echo "$MODEL_ID"
```

❶ `display_name` is the alias callers send in `model`.

❷ `model_name` is the Cerebras model ID, for example `gpt-oss-120b` or `gemma-4-31b`. Do not carry over a prefixed ID such as `openai/gpt-oss-120b` from another provider that hosts the same weights.

❸ `provider_key_id` attaches the alias to the Cerebras provider key.

### Create a Caller API Key[​](#create-a-caller-api-key "Direct link to Create a Caller API Key")

Create the caller API key that can access the model alias. The plaintext key is server-generated and returned once in the create response, so capture it now:

```
AISIX_API_KEY=$(curl -sS -X POST "$AISIX_CP/environments/$ENV_ID/api_keys" \

  -H "Authorization: Bearer $AISIX_TOKEN" \

  -H "Content-Type: application/json" \

  -d '{

    "display_name": "cerebras-caller",

    "allowed_models": ["'"${MODEL_ID}"'"]

  }' | jq -r '.plaintext')



echo "$AISIX_API_KEY"
```

The `allowed_models` value must reference the model ID captured in the previous step. After the write, the configuration projects to attached gateways automatically.

## Configure with AISIX OSS[​](#configure-with-aisix-oss "Direct link to Configure with AISIX OSS")

Export the upstream credential and choose the caller API key that applications will send to the gateway:

```
export CEREBRAS_API_KEY="YOUR_PROVIDER_API_KEY"

export CALLER_API_KEY="YOUR_CALLER_API_KEY"

export CALLER_API_KEY_SHA256="$(printf '%s' "$CALLER_API_KEY" | sha256sum | cut -d ' ' -f 1)"
```

For a new gateway, use this complete resources file. For an existing gateway, merge the entries into its [current file](https://docs.api7.ai/ai-gateway/reference/resources-file.md#apply-resource-examples-safely), preserving its other resources:

resources.yaml

```
_format_version: "2"



provider_keys:

  - id: dde10ef0-c1cc-4e80-952d-4302974fddc9

    display_name: "cerebras-prod"

    provider: "cerebras"

    adapter: "openai"

    api_key: ${CEREBRAS_API_KEY}

    api_base: "https://api.cerebras.ai/v1"



models:

  - id: 6e604e42-38cd-4113-8eff-774250dfe281

    display_name: "cerebras-gptoss-prod"

    provider: "cerebras"

    model_name: "gpt-oss-120b"

    provider_key_id: dde10ef0-c1cc-4e80-952d-4302974fddc9



api_keys:

  - id: 3121f1e6-43a2-4b2b-b1e8-b02a989e5846

    display_name: "cerebras-caller"

    key_hash: ${CALLER_API_KEY_SHA256}

    allowed_models:

      - "cerebras-gptoss-prod"
```

If AISIX is installed locally, validate the file before loading it:

```
aisix validate --resources resources.yaml
```

After validation, start the gateway with the referenced environment variables in its process environment. Reload an existing gateway only if those variables are already available to the process; otherwise, restart it with the updated environment.

If you use Docker, adapt the validation and startup commands in the [AISIX OSS getting-started guide](https://docs.api7.ai/ai-gateway/getting-started/gateway-quickstart.md). Mount this `resources.yaml` file and pass every environment variable it references with `-e` in both commands. After the resources load, prepare the shared verification request below:

```
export AISIX_API_KEY="$CALLER_API_KEY"
```

## Verify the Provider Connection[​](#verify-the-provider-connection "Direct link to Verify the Provider Connection")

Export the AISIX gateway origin:

```
# AISIX_PROXY has no trailing slash or endpoint path

# The local quickstarts use http://127.0.0.1:3000

export AISIX_PROXY="YOUR_AISIX_GATEWAY_URL"
```

Send a chat-completions request through the AISIX proxy:

```
curl -sS -X POST "$AISIX_PROXY/v1/chat/completions" \

  -H "Authorization: Bearer ${AISIX_API_KEY}" \

  -H "Content-Type: application/json" \

  -d '{

    "model": "cerebras-gptoss-prod",

    "messages": [

      {

        "role": "user",

        "content": "Say hello from Cerebras."

      }

    ]

  }'
```

The gateway returns an OpenAI-compatible response that echoes the caller-facing alias `cerebras-gptoss-prod`. If the request fails, check the provider key `api_key`, `api_base`, and the Cerebras model ID in `model_name`.

## Send Token Limits[​](#send-token-limits "Direct link to Send Token Limits")

Cerebras follows current OpenAI parameter naming and documents `max_completion_tokens` for the generated-token cap in [Chat Completions](https://inference-docs.cerebras.ai/api-reference/chat-completions). The Cerebras entry in the AISIX provider catalog therefore configures no parameter renames, and AISIX forwards `max_completion_tokens` to Cerebras exactly as the caller sent it. Some other OpenAI-compatible upstreams still expect the older `max_tokens` name and carry a rename for it, so a request body that works against Cerebras is not automatically portable to every openai-adapter provider.

If an existing client sends the older `max_tokens` name and you need it delivered under the current name, add a rename on the provider key:

```
{

  "request": {

    "param_renames": {

      "max_tokens": "max_completion_tokens"

    }

  }

}
```

The rename applies to every model that references the provider key. See [Provider-Specific Overrides](https://docs.api7.ai/ai-gateway/models/provider-keys.md#configure-provider-specific-overrides).

## Control Reasoning Effort[​](#control-reasoning-effort "Direct link to Control Reasoning Effort")

Cerebras accepts the standard OpenAI `reasoning_effort` parameter at the top level of the chat-completions body. AISIX does not strip unrecognized top-level parameters, so the value reaches the upstream unchanged:

```
{

  "model": "cerebras-gptoss-prod",

  "messages": [

    {

      "role": "user",

      "content": "Plan a three-step migration."

    }

  ],

  "reasoning_effort": "low"

}
```

Accepted values depend on the model:

| Model          | `reasoning_effort` values       | Default           |
| -------------- | ------------------------------- | ----------------- |
| `gpt-oss-120b` | `low`, `medium`, `high`         | `medium`          |
| `gemma-4-31b`  | `none`, `low`, `medium`, `high` | `none`            |
| `zai-glm-4.7`  | `none` to disable reasoning     | Reasoning enabled |

Confirm the values for the model you configured in the [Cerebras reasoning documentation](https://inference-docs.cerebras.ai/capabilities/reasoning), because a value one model accepts can be rejected by another.

The Cerebras catalog entry sets no reasoning-field override, so AISIX preserves reasoning that the upstream already returns in the canonical `reasoning_content` field for streaming and non-streaming responses. If a Cerebras model streams reasoning at a different `delta` path, set [`response.reasoning_field`](https://docs.api7.ai/ai-gateway/models/provider-keys.md#configure-provider-specific-overrides) on the provider key.

## Route Latency-Sensitive Traffic[​](#route-latency-sensitive-traffic "Direct link to Route Latency-Sensitive Traffic")

A Cerebras alias is a useful target in a routing model that ranks targets by observed latency. Create a routing model with `strategy` set to `least_latency` and list the Cerebras alias alongside a fallback target. AISIX ranks targets by a moving average of recent upstream latency, using time to first token for streaming requests, and probes targets that have no samples yet before ranking them. See [Route by Cost, Latency, or Load](https://docs.api7.ai/ai-gateway/routing/routing-patterns.md#route-by-cost-latency-or-load).

## Endpoint Support[​](#endpoint-support "Direct link to Endpoint Support")

Cerebras is an inference-only upstream, so only part of the proxy surface applies to a Cerebras-backed alias.

| Route                     | Behavior with a Cerebras alias                                                                                                                                                                                                                                                                                                   |
| ------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `/v1/chat/completions`    | Supported, including `stream: true`.                                                                                                                                                                                                                                                                                             |
| `/v1/responses`           | Supported through the [Responses bridge](https://docs.api7.ai/ai-gateway/endpoints/responses-api.md) over the chat adapter path. OpenAI-specific Responses fields without a chat equivalent are ignored.                                                                                                                         |
| `/v1/messages`            | Supported for Anthropic-shaped callers through translation. Token counting at `/v1/messages/count_tokens` requires an Anthropic-backed model.                                                                                                                                                                                    |
| `/v1/embeddings`          | Not usable. Cerebras serves language models and does not publish embedding models, so route embeddings to a separate provider. See [Embeddings](https://docs.api7.ai/ai-gateway/endpoints/embeddings.md).                                                                                                                        |
| `/v1/images/generations`  | Rejected. The route accepts only models whose provider is `openai` or whose provider key uses the `azure-openai` adapter (see [Provider Requirement](https://docs.api7.ai/ai-gateway/endpoints/image-generation.md#provider-requirement)).                                                                                       |
| `/v1/rerank`              | Rejected. The route accepts only the `openai`, `cohere`, and `jina` provider values.                                                                                                                                                                                                                                             |
| `/v1/videos`              | Rejected. The route accepts only its own provider allowlist, which does not include `cerebras`.                                                                                                                                                                                                                                  |
| `/passthrough/cerebras/*` | Available through a configured [passthrough route](https://docs.api7.ai/ai-gateway/endpoints/provider-passthrough.md) claiming this prefix with the `https://api.cerebras.ai/v1` root as its `target_url`; grant the route on the caller key's `allowed_routes`. Provider-native paths relay with limited gateway normalization. |

## Next Steps[​](#next-steps "Direct link to Next Steps")

You have now connected AISIX to Cerebras and verified the model alias. Continue with these guides:

* [Model Aliases](https://docs.api7.ai/ai-gateway/models/model-aliases.md): configure routing, retry behavior, or cost metadata for this alias.
* [Routing and Failover](https://docs.api7.ai/ai-gateway/routing/routing-and-failover.md): fail over between Cerebras and a second provider.
* [Provider-Specific Overrides](https://docs.api7.ai/ai-gateway/models/provider-keys.md#configure-provider-specific-overrides): adapt request and response shapes when an upstream API differs from its adapter.
* [Provider Compatibility](https://docs.api7.ai/ai-gateway/providers/compatibility.md): review supported proxy endpoints and provider-specific boundaries.
