Skip to main content

OpenRouter pass-through

The /openrouter route forwards OpenRouter API paths, such as /chat/completions and /models, to OpenRouter unchanged. Teams keep OpenRouter's own API, including its provider routing options, while the gateway holds the OpenRouter key, checks the virtual key and records the spend.

A real-world scenario​

A research group compares many models through OpenRouter from notebooks. The group shares one OpenRouter account and the lead wants a budget per researcher. The notebooks call /openrouter/chat/completions on the gateway with individual virtual keys. The OpenRouter key stays on the gateway and the Logs page shows which researcher used which model.

Before you start​

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

VariablePurpose
OPENROUTER_API_KEYThe OpenRouter key the gateway sends upstream.
OPENROUTER_API_BASEOptional. Changes the upstream address from https://openrouter.ai/api/v1.

Steps​

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

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

  3. Call OpenRouter through the gateway.

    curl -X POST http://localhost:4000/openrouter/chat/completions \
    -H "Authorization: Bearer $SPANWAY_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{"model": "openai/gpt-6.1-sol", "messages": [{"role": "user", "content": "Summarise this ticket in one sentence."}]}'
  4. Open /ui/logs and click the newest row to see the request, the key and its cost.

Expected result​

OpenRouter's own response, with its status code and headers.

{
"id": "chatcmpl-9f1c",
"object": "chat.completion",
"model": "openai/gpt-6.1-sol",
"choices": [{"index": 0, "message": {"role": "assistant", "content": "The customer wants one of two duplicate charges refunded."}, "finish_reason": "stop"}],
"usage": {"prompt_tokens": 18, "completion_tokens": 12, "total_tokens": 30}
}

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

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 /openrouter/...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 OpenRouterNo auth credentials foundThe gateway forwarded the call with no usable OpenRouter key. Add a deployment with Use in pass through routes on, or set OPENROUTER_API_KEY.
Any otherOpenRouter's own error bodyOpenRouter refused the request. The message is returned unchanged.

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