OpenRouter
Route your OpenRouter API calls through AI SpendOps for automatic usage tracking and cost attribution.
Configuration
| Setting | Value |
|---|---|
| Route | /v1/openrouter/* |
| Upstream | https://openrouter.ai/api |
| Auth header | Authorization: Bearer sk-or-... |
| Streaming usage | Always included |
SDK base URL
https://proxy.aispendops.com/v1/openrouter/v1
Example
curl https://proxy.aispendops.com/v1/openrouter/v1/chat/completions \
-H "Authorization: Bearer sk-or-your-openrouter-key" \
-H "X-ASO-API-Key: aso_k_yourkey.secret" \
-H "Content-Type: application/json" \
-d '{"model":"anthropic/claude-sonnet-4-20250514","messages":[{"role":"user","content":"Hello"}]}'
Python SDK
from openai import OpenAI
client = OpenAI(
api_key="sk-or-your-openrouter-key",
base_url="https://proxy.aispendops.com/v1/openrouter/v1",
default_headers={"X-ASO-API-Key": "aso_k_yourkey.secret"},
)
response = client.chat.completions.create(
model="anthropic/claude-sonnet-4-20250514",
messages=[{"role": "user", "content": "Hello"}],
)
print(response.choices[0].message.content)
Usage fields
| Field | Description |
|---|---|
prompt_tokens | Input tokens |
completion_tokens | Output tokens |
total_tokens | Sum of prompt + completion tokens |
cost | Actual cost charged by OpenRouter (provider_cost) |
Notes
- OpenRouter is a multi-provider routing service. The
provider_costfield is the actual amount charged and takes precedence over token-based cost calculations. - OpenRouter always includes usage data in responses, including streaming.
- Model names use the format
provider/model(e.g.anthropic/claude-sonnet-4-20250514).