Skip to main content

Cohere pass-through

The /cohere route forwards Cohere API paths such as /v2/chat, /v2/embed and /v2/rerank to Cohere unchanged. Teams keep the Cohere SDK while the gateway holds the Cohere key, checks the virtual key and records the spend.

A real-world scenario​

A search team reranks results with Cohere from a service that already talks to the gateway for chat. Rather than managing a second credential, the service calls /cohere/v2/rerank on the gateway with the same virtual key. The Cohere key stays on the gateway and the rerank spend lands in the same team budget as the chat spend.

Before you start​

The gateway needs a Cohere credential. It looks first for a model_list deployment of provider Cohere with use_in_pass_through: true, then for the environment below.

VariablePurpose
COHERE_API_KEYThe Cohere key the gateway sends upstream.
COHERE_API_BASEOptional. Changes the upstream address from https://api.cohere.com.
model_list:
- model_name: cohere-passthrough
spanway_params:
model: cohere/command-a-03-2025
api_key: os.environ/COHERE_API_KEY
use_in_pass_through: true

Steps​

  1. Give the gateway the credential. Open /ui/models-and-endpoints, on the Add Model tab pick Cohere under Provider, pick a model, open Advanced Settings, turn on Use in pass through routes and click Add Model. Or set COHERE_API_KEY and restart the gateway.

  2. Issue a virtual key on /ui/api-keys with + Create New Key, then Create Key.

  3. Call Cohere through the gateway.

    curl -X POST http://localhost:4000/cohere/v2/rerank \
    -H "Authorization: Bearer $SPANWAY_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{"model": "rerank-v4.0-pro", "query": "refund for a duplicate charge", "documents": ["Refunds are issued within five business days.", "Our office is closed on Mondays."], "top_n": 1}'
  4. Open /ui/logs and click the newest row to see the request, the key and its cost.

Expected result​

Cohere's own response, with Cohere's status code and headers. Streaming chat is streamed through as it arrives.

{"id": "rerank-7b3f", "results": [{"index": 0, "relevance_score": 0.98}], "meta": {"billed_units": {"search_units": 1}}}

The spend log row carries the key, team and user and the cost from the billed units.

Errors​

StatusMessageWhat it means and how to fix it
401Authentication Error, Invalid proxy server token passedThe virtual key is missing, wrong, expired or blocked.
403Key/team denied access to passthrough route /cohere/...The key or team lists the route in denied_passthrough_routes. The message goes on with Matched <pattern> in denied_passthrough_routes, naming the pattern to remove from the key or team.
401 from Cohereinvalid api tokenThe gateway forwarded the call with no usable Cohere key. Add a deployment with Use in pass through routes on, or set COHERE_API_KEY.
Any otherCohere's own error bodyCohere refused the request. The message is returned unchanged.

Pass-through endpoints lists every built-in route. The unified rerank endpoint works with every rerank provider and runs guardrails. The Cohere provider page covers the unified integration.