# Cohere

[Cohere](https://docs.cohere.com/) provides Command models and APIs for generation, embeddings, and reranking. AISIX places these capabilities behind gateway-managed credentials, caller access, rate limits, and usage accounting.

Cohere publishes a native API and a [compatibility API](https://docs.cohere.com/docs/compatibility-api) for OpenAI-shaped requests. This guide uses the compatibility API for chat completions and embeddings, then configures the native API separately for reranking.

## 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 Cohere API key from the [Cohere dashboard](https://dashboard.cohere.com/api-keys).

* `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 Cohere-backed chat-completions route.

AISIX connects to Cohere's compatibility API through the `openai` adapter. Chat completions and embeddings need no request translation. Cohere rerank uses the native API, and the same provider key serves it, as shown in [Add a Rerank Model](#add-a-rerank-model).

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

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

```
# Replace with your value

export COHERE_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": "cohere-prod",

    "provider": "cohere",

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

    "api_base": "https://api.cohere.ai/compatibility/v1",

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

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



echo "$PROVIDER_KEY_ID"
```

❶ `provider` is `cohere`. 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 Cohere API key. It follows the credential-handling behavior in [Provider Keys](https://docs.api7.ai/ai-gateway/models/provider-keys.md#credential-handling).

❸ `api_base` points at Cohere's compatibility API. The path carries a `/compatibility` segment before the `/v1` version segment, because the OpenAI-shaped routes are served on a separate prefix from Cohere's native API. The bare host root, such as `https://api.cohere.com`, works as well: see [How AISIX Builds Cohere URLs](#how-aisix-builds-cohere-urls). For the `cohere` catalog provider the field is optional — the AISIX Cloud Admin API fills in the same value when you omit it — but the examples set it explicitly so the surface 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")

Cohere model IDs combine a family name with a release date: `command-a-03-2025` is the March 2025 snapshot of the `command-a` family, and capability variants add a suffix before the date, as in `command-a-reasoning-08-2025` or `command-a-vision-07-2025`. Because the date is part of the ID, a model alias created from a catalog ID pins one snapshot. Check the [Cohere models list](https://docs.cohere.com/docs/models) for current IDs.

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": "cohere-command-a-prod",

    "model_name": "command-a-03-2025",

    "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 Cohere model ID, for example `command-a-03-2025`, `command-a-plus-05-2026`, or `command-a-reasoning-08-2025`.

❸ `provider_key_id` attaches the alias to the Cohere 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 response — store it securely:

```
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": "cohere-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 COHERE_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: 6727a6a7-c889-498e-b6c6-583515deb531

    display_name: "cohere-prod"

    provider: "cohere"

    adapter: "openai"

    api_key: ${COHERE_API_KEY}

    api_base: "https://api.cohere.ai/compatibility/v1"



models:

  - id: dc5d1a0e-632d-4846-8e6f-def2636093f0

    display_name: "cohere-command-a-prod"

    provider: "cohere"

    model_name: "command-a-03-2025"

    provider_key_id: 6727a6a7-c889-498e-b6c6-583515deb531



api_keys:

  - id: 74a9cff4-2c5e-4d28-b4f8-211b09164d55

    display_name: "cohere-caller"

    key_hash: ${CALLER_API_KEY_SHA256}

    allowed_models:

      - "cohere-command-a-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": "cohere-command-a-prod",

    "messages": [

      {

        "role": "user",

        "content": "Say hello from Cohere."

      }

    ]

  }'
```

The gateway returns an OpenAI-compatible response that echoes the caller-facing alias `cohere-command-a-prod`. If the request fails, check the provider key `api_key`, `api_base`, and the Cohere model ID in `model_name`. A 404 from the upstream usually means `api_base` carries a path other than the forms listed in [How AISIX Builds Cohere URLs](#how-aisix-builds-cohere-urls).

## How AISIX Builds Cohere URLs[​](#how-aisix-builds-cohere-urls "Direct link to How AISIX Builds Cohere URLs")

A Cohere provider key reaches the right endpoint for chat completions, embeddings, and rerank with either form of `api_base`: the bare host root, such as `https://api.cohere.com`, or the compatibility base, such as `https://api.cohere.ai/compatibility/v1`. AISIX removes a trailing `/compatibility/v1`, `/v1`, or `/v2` from `api_base` to get the host root, then builds each route from that root:

| Route                  | Upstream URL                                    |
| ---------------------- | ----------------------------------------------- |
| `/v1/chat/completions` | `<host root>/compatibility/v1/chat/completions` |
| `/v1/embeddings`       | `<host root>/compatibility/v1/embeddings`       |
| `/v1/rerank`           | `<host root>/v2/rerank`                         |

A base with any other path, such as a private forwarding proxy, keeps that path, and AISIX appends `/compatibility/v1` or `/v2/rerank` to it as written.

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

Cohere's reasoning-capable Command models, such as `command-a-reasoning-08-2025` and `command-a-plus-05-2026`, expose thinking differently on each API surface. Because AISIX routes to the compatibility API, callers control it with the OpenAI-shaped `reasoning_effort` field:

```
{

  "reasoning_effort": "none"

}
```

Cohere's compatibility API accepts `none` and `high` on this field, which map to disabled and enabled thinking. The native API's token-budget control is not documented on this surface, so a request cannot cap the reasoning token count through the compatibility route. See Cohere's [Reasoning](https://docs.cohere.com/docs/reasoning) documentation for the current field behavior.

AISIX preserves `reasoning_content` in responses and normalizes `reasoning` to that canonical field. The Cohere provider key carries no reasoning-field override. If your model streams reasoning under 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.

## Add a Rerank Model[​](#add-a-rerank-model "Direct link to Add a Rerank Model")

The `/v1/rerank` route accepts a model whose provider value is `openai`, `cohere`, or `jina`, so a Cohere-backed alias is admitted on this route. Cohere rerank is not part of the compatibility API; AISIX sends it to Cohere's native [v2 rerank endpoint](https://docs.cohere.com/reference/rerank) under the host root of the provider key's `api_base`, as described in [How AISIX Builds Cohere URLs](#how-aisix-builds-cohere-urls). The provider key you created for chat completions therefore serves rerank too.

In AISIX Enterprise and AISIX Cloud, create the rerank model alias on that provider key and a caller key scoped to it:

```
RERANK_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": "cohere-rerank-prod",

    "model_name": "rerank-v3.5",

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

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



RERANK_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": "cohere-rerank-caller",

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

  }' | jq -r '.plaintext')
```

For the open-source AISIX gateway, add `cohere-rerank-prod` to `models` on the existing `cohere-prod` provider key. Replace the existing `cohere-caller` entry with the updated entry below so it allows both model aliases. Preserve unrelated entries and collections:

resources.yaml (rerank resources)

```
models:

  - id: 6d97723f-36ac-4714-8dcc-288f89e80af4

    display_name: "cohere-rerank-prod"

    provider: "cohere"

    model_name: "rerank-v3.5"

    provider_key_id: 6727a6a7-c889-498e-b6c6-583515deb531



api_keys:

  - id: 74a9cff4-2c5e-4d28-b4f8-211b09164d55

    display_name: "cohere-caller"

    key_hash: ${CALLER_API_KEY_SHA256}

    allowed_models:

      - "cohere-command-a-prod"

      - "cohere-rerank-prod"
```

Validate and reload or restart the declarative resources file as described above, then use the existing caller key for the rerank request:

```
export RERANK_API_KEY="$CALLER_API_KEY"
```

Rerank model IDs follow their own naming, separate from the Command families: `rerank-v3.5`, and the two Rerank 4.0 variants `rerank-v4.0-fast` and `rerank-v4.0-pro`. Because this route resolves to Cohere's v2 rerank endpoint, confirm on the [rerank model overview](https://docs.cohere.com/docs/rerank-overview) that the ID you pick is served there before you point a production alias at it.

Send a rerank request through the proxy:

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

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

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

  -d '{

    "model": "cohere-rerank-prod",

    "query": "How do I rotate a provider credential?",

    "documents": [

      "Provider keys store the upstream credential.",

      "Caller API keys authorize model access.",

      "Rate limits apply per caller key."

    ],

    "top_n": 2

  }'
```

AISIX rewrites only the `model` field to `rerank-v3.5` and forwards the body unchanged, so Cohere's `top_n` parameter reaches the upstream as written. The response keeps Cohere's rerank shape: a `results` array ordered by `relevance_score`, plus a `meta` object. Cohere's rerank models report usage as `meta.billed_units.search_units`, with no token count. AISIX does not price search units, so each rerank request is recorded in the usage log with zero tokens. In AISIX Enterprise and AISIX Cloud, it appears in the control plane's Request Logs alongside chat traffic but adds no cost to budget totals. When a Cohere response does include `meta.billed_units.input_tokens`, AISIX records that count.

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

The routes below behave as follows for a model alias backed by a Cohere provider key, with `api_base` in either form described in [How AISIX Builds Cohere URLs](#how-aisix-builds-cohere-urls).

| Route                    | Behavior with a Cohere-backed model                                                                                                                                                                                                                                                                                                       |
| ------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `/v1/chat/completions`   | Supported through the compatibility API.                                                                                                                                                                                                                                                                                                  |
| `/v1/embeddings`         | Supported through Cohere's OpenAI-shaped embeddings route on the compatibility API. Use a Cohere [embedding model](https://docs.cohere.com/docs/cohere-embed) ID such as `embed-v4.0` in `model_name`.                                                                                                                                    |
| `/v1/responses`          | Bridged through the chat adapter. AISIX returns a Responses-shaped result rather than forwarding to a native Responses API, and ignores OpenAI-specific Responses fields without a chat equivalent. See [Responses API](https://docs.api7.ai/ai-gateway/endpoints/responses-api.md).                                                      |
| `/v1/rerank`             | Supported through Cohere's native v2 rerank endpoint, on the same provider key. See [Add a Rerank Model](#add-a-rerank-model).                                                                                                                                                                                                            |
| `/v1/images/generations` | Not supported. 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/videos`             | Not supported. Cohere is not in the video route's provider allowlist.                                                                                                                                                                                                                                                                     |
| `/v1/messages`           | Supported for Anthropic-shaped callers through translation. Token counting at `/v1/messages/count_tokens` requires an Anthropic-backed model.                                                                                                                                                                                             |
| `/passthrough/cohere/*`  | Available through a configured [passthrough route](https://docs.api7.ai/ai-gateway/endpoints/provider-passthrough.md); grant the route on the caller key's `allowed_routes`. A route binds one fixed `target_url` and provider key, so reaching both the compatibility base and the native root takes two routes under distinct prefixes. |

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

You have now connected AISIX to Cohere, verified the model alias, and added a rerank route. Continue with these guides:

* [Model Aliases](https://docs.api7.ai/ai-gateway/models/model-aliases.md): configure routing, retry behavior, or cost metadata for these aliases.
* [Rerank](https://docs.api7.ai/ai-gateway/endpoints/rerank.md): review the rerank request contract and its provider requirement.
* [Routing and Failover](https://docs.api7.ai/ai-gateway/routing/routing-and-failover.md): fail over between Cohere and a second provider.
* [Provider Compatibility](https://docs.api7.ai/ai-gateway/providers/compatibility.md): review supported proxy endpoints and provider-specific boundaries.
