OpenRouter (gateway)

Point OpenAI-compatible calls at the Respan gateway and use OpenRouter model names (openrouter/openai/gpt-5.5, openrouter/anthropic/claude-sonnet-4-5, etc.).

Setup

1

Install packages

pip install openai
2

Set environment variables

export RESPAN_API_KEY="YOUR_RESPAN_API_KEY"

No OPENROUTER_API_KEY is needed when billing/routing through Respan Gateway credits. For BYOK, configure credentials in the Respan provider settings.

3

Point client to gateway

from openai import OpenAI
import os
client = OpenAI(
api_key=os.environ["RESPAN_API_KEY"],
base_url="https://api.respan.ai/api",
)
response = client.chat.completions.create(
model="openrouter/openai/gpt-5.5",
messages=[{"role": "user", "content": "Hello via Respan Gateway OpenRouter."}],
)
print(response.choices[0].message.content)
4

Switch models

client.chat.completions.create(model="openrouter/meta-llama/llama-3.3-70b-instruct", messages=[{"role":"user","content":"Compare routing options."}])
client.chat.completions.create(model="openrouter/anthropic/claude-sonnet-4-5", messages=[{"role":"user","content":"Summarize routing."}])

See OpenRouter model docs for full provider/key options and routing behavior.

Reasoning and provider routing

For openrouter/* models the unified router forwards OpenRouter’s reasoning and provider objects to OpenRouter verbatim, so you can disable reasoning or constrain provider routing without leaving the router.

response = client.chat.completions.create(
model="openrouter/deepseek/deepseek-v4-flash-0731",
messages=[{"role": "user", "content": "Summarize routing."}],
extra_body={
"reasoning": {"enabled": False},
"provider": {"zdr": True},
},
)

Only object-shaped values are forwarded. A reasoning list is treated as Respan’s own log field, which is the shape our logs use for a model’s reasoning output, and OpenRouter rejects a list outright. Both keys are forwarded for openrouter/* models only.

Native passthrough

The setup above uses the unified router, which validates the request against the Respan schema and can bill through Respan gateway credits. Call the native passthrough endpoint when you need OpenRouter’s control surface beyond reasoning and provider, such as reasoning_effort: "none", a field OpenRouter adds later, or the provider, native_finish_reason and reasoning_details fields OpenRouter returns. It relays the request with no Respan schema in between.

from openai import OpenAI
import os
client = OpenAI(
api_key=os.environ["RESPAN_API_KEY"],
base_url="https://api.respan.ai/api/openrouter/v1",
default_headers={"x-openrouter-api-key": os.environ["OPENROUTER_API_KEY"]},
)
response = client.chat.completions.create(
model="anthropic/claude-sonnet-4-5",
messages=[{"role": "user", "content": "Hello via the OpenRouter passthrough."}],
extra_body={"provider": {"order": ["anthropic"]}},
)
print(response.choices[0].message.content)

This endpoint is BYOK. Authorization carries your Respan API key and x-openrouter-api-key carries your OpenRouter API key. Both are required, and there is no fallback to Respan gateway credits. Use OpenRouter’s own model slug rather than the openrouter/-prefixed form, though the prefix is also accepted. OpenRouter’s response, status code, and event stream are relayed back unchanged, so an upstream 402, 404, or 429 reaches your client as that same status. The request is still logged in Respan.

See Routing & passthrough for a full comparison of the two shapes and how this sits alongside the Anthropic and Google passthroughs.