Skip to main content

OpenRouter

Route your OpenRouter API calls through AI SpendOps for automatic usage tracking and cost attribution.

Configuration

SettingValue
Route/v1/openrouter/*
Upstreamhttps://openrouter.ai/api
Auth headerAuthorization: Bearer sk-or-...
Streaming usageAlways 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

FieldDescription
prompt_tokensInput tokens
completion_tokensOutput tokens
total_tokensSum of prompt + completion tokens
costActual cost charged by OpenRouter (provider_cost)

Notes

  • OpenRouter is a multi-provider routing service. The provider_cost field 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).