One key · 400+ models · routing layers · six-step setup · curl/Python/Node · streaming & fallback · BYOK pricing
If you are juggling separate API keys for OpenAI, Anthropic, and Google, each with different SDKs, rate limits, and billing dashboards, OpenRouter collapses that sprawl into a single OpenAI-compatible endpoint. This 2026 guide explains what OpenRouter actually does under the hood, walks through a six-step API key setup, ships copy-paste examples in curl, Python, Node.js, and the OpenAI SDK (including streaming and fallback), compares OpenRouter vs direct vendor APIs, covers pricing, BYOK, and free-tier models, and closes with an English SEO checklist for low-traffic locales plus why long-running Agents still belong on a 24/7 Mac Mini M4 rental.
OpenRouter is a unified LLM gateway: one API key, one base URL, and access to 400+ models from OpenAI, Anthropic, Google, Meta, DeepSeek, Mistral, xAI, and dozens of open-weight providers. It speaks the OpenAI Chat Completions API format, so most existing code works by changing two lines — base_url and model.
Think of OpenRouter as a smart proxy sitting between your application and upstream inference providers. When you send a request, three routing layers decide where it lands and what happens if something fails.
You specify a model ID in the request body — for example anthropic/claude-sonnet-4, openai/gpt-5, or google/gemini-2.5-pro-preview. OpenRouter maintains a live catalog at openrouter.ai/models with per-model pricing, context limits, and modality support (text, vision, tools).
Many models have multiple upstream providers — the same meta-llama/llama-3.3-70b-instruct might be served by Together, Fireworks, or DeepInfra. OpenRouter picks the best available provider based on latency, price tier, and current capacity. You can override this with the provider field or route through BYOK (Bring Your Own Key) to bill directly with your vendor account.
When a provider returns a 429, 502, or timeout, OpenRouter can automatically retry on an alternate provider or fall back to a secondary model you define. This is the feature that turns a brittle single-vendor integration into production-grade infrastructure — especially for Agent workloads that cannot afford a hard stop mid-task.
OpenRouter does not train on your API traffic by default. For regulated workloads, pair BYOK routing with spend caps and key rotation — the same hygiene you would apply to any direct vendor key.
OpenRouter also publishes live usage rankings at openrouter.ai/rankings, showing which models developers actually run in production. That data complements this API guide — see our June 2026 rankings breakdown for volume vs quality analysis.
base_url to https://openrouter.ai/api/v1 and swap the model string. Existing LangChain, Cursor, and OpenClaw configs often need zero refactor.| Dimension | OpenRouter | Direct vendor API |
|---|---|---|
| API keys needed | One OpenRouter key (or BYOK per vendor) | One key per vendor (OpenAI, Anthropic, Google, etc.) |
| SDK compatibility | OpenAI Chat Completions format (universal) | Vendor-specific SDKs and endpoint shapes |
| Model switching | Change model field in one request | New SDK init, new billing account, new rate limits |
| Fallback on 429/502 | Built-in provider retry and model fallback chains | Custom retry logic per vendor |
| Pricing | Listed per-model rates; BYOK avoids markup | Vendor list price; enterprise discounts via sales |
| Free models | Owl Alpha, Nemotron 3 Super, and others at $0 | Limited free tiers per vendor (Gemini free, Claude trial) |
| Latency overhead | ~20–80 ms proxy hop (varies by region) | Direct to vendor edge; lowest possible |
| Observability | Unified dashboard: spend, tokens, model mix | Separate dashboards per vendor |
| Best for | Multi-model Agents, startups, cost optimization | Single-vendor enterprise, native feature needs |
This runbook gets you from account creation to a verified production call in under fifteen minutes. Follow every step before wiring OpenRouter into an Agent daemon or CI pipeline.
Create an account: Go to openrouter.ai and sign up with email or GitHub. New accounts receive a small credit for testing — enough for dozens of Sonnet calls or thousands of Flash-tier tokens.
Generate an API key: Navigate to Keys in the dashboard. Create a key with a descriptive name (e.g. prod-agent-v1). Copy it immediately — OpenRouter shows the full key only once.
Set a spend limit: Under Settings, configure a monthly budget cap and email alerts at 50%, 80%, and 100%. For Agent workloads, start with $50/month and scale after measuring token burn on your prompt set.
Store the key securely: Never commit keys to git. Use environment variables (OPENROUTER_API_KEY), macOS Keychain, or your CI secret store. Rotate keys monthly in production.
Verify with curl: Run the curl example in Section 04 below. A 200 response with a choices[0].message.content field confirms your key, routing, and model ID are correct.
Wire into your stack: Point your OpenAI SDK, LangChain, or Agent framework at https://openrouter.ai/api/v1. Add HTTP-Referer and X-Title headers so your app appears in OpenRouter analytics. Deploy the daemon on a host that stays awake — see Section 06 for Mac Mini guidance.
Security note: Treat OpenRouter keys like production database credentials. If a key leaks, revoke it in the dashboard immediately and audit recent spend. OpenRouter supports per-key rate limits — use them for public-facing endpoints.
All examples use the same endpoint: https://openrouter.ai/api/v1/chat/completions. Replace YOUR_KEY with your API key and pick any model from the catalog.
curl https://openrouter.ai/api/v1/chat/completions \
-H "Authorization: Bearer $OPENROUTER_API_KEY" \
-H "Content-Type: application/json" \
-H "HTTP-Referer: https://your-app.com" \
-H "X-Title: Your App Name" \
-d '{
"model": "anthropic/claude-sonnet-4",
"messages": [{"role": "user", "content": "Explain OpenRouter in one sentence."}]
}'
from openai import OpenAI
client = OpenAI(
base_url="https://openrouter.ai/api/v1",
api_key="YOUR_KEY",
)
response = client.chat.completions.create(
model="deepseek/deepseek-chat-v3-0324",
messages=[{"role": "user", "content": "Write a Python hello world."}],
extra_headers={
"HTTP-Referer": "https://your-app.com",
"X-Title": "Your App Name",
},
)
print(response.choices[0].message.content)
const res = await fetch("https://openrouter.ai/api/v1/chat/completions", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.OPENROUTER_API_KEY}`,
"Content-Type": "application/json",
"HTTP-Referer": "https://your-app.com",
"X-Title": "Your App Name",
},
body: JSON.stringify({
model: "google/gemini-2.5-pro-preview",
messages: [{ role: "user", content: "Summarize REST vs GraphQL." }],
}),
});
const data = await res.json();
console.log(data.choices[0].message.content);
from openai import OpenAI
client = OpenAI(
base_url="https://openrouter.ai/api/v1",
api_key="YOUR_KEY",
)
response = client.chat.completions.create(
model="openai/gpt-5",
messages=[{"role": "user", "content": "Compare GPT-5 and Claude Sonnet 4."}],
tools=[{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get weather for a city",
"parameters": {
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"],
},
},
}],
)
print(response.choices[0].message)
from openai import OpenAI
client = OpenAI(
base_url="https://openrouter.ai/api/v1",
api_key="YOUR_KEY",
)
stream = client.chat.completions.create(
model="anthropic/claude-sonnet-4",
messages=[{"role": "user", "content": "Stream this response token by token."}],
stream=True,
)
for chunk in stream:
delta = chunk.choices[0].delta.content
if delta:
print(delta, end="", flush=True)
{
"model": "anthropic/claude-sonnet-4",
"models": [
"anthropic/claude-sonnet-4",
"deepseek/deepseek-chat-v3-0324",
"google/gemini-2.5-flash-preview"
],
"messages": [{"role": "user", "content": "Handle this with automatic fallback."}],
"route": "fallback"
}
When you pass a models array with "route": "fallback", OpenRouter tries each model in order until one succeeds. This is the simplest production pattern for Agent pipelines that cannot tolerate a single point of failure. For gateway-level routing with budget caps, see our OpenClaw multi-model routing guide.
curl https://openrouter.ai/api/v1/models \
-H "Authorization: Bearer $OPENROUTER_API_KEY" | jq '.data[] | {id, pricing}'
The models endpoint returns every available model with pricing, context length, and supported modalities. Cache this response in your app and refresh daily — new models appear weekly in mid-2026.
OpenRouter charges per token at the rate listed for each model. There is no monthly platform fee. Standard routes pass through upstream list pricing — OpenRouter does not add a hidden markup on top of vendor rates. You pay only for tokens consumed.
| Model (July 2026) | Input $/M | Output $/M | Context | Notes |
|---|---|---|---|---|
| DeepSeek V4 Flash | ~0.10 | ~0.40 | 1M | Best price-performance for high-frequency coding |
| Claude Sonnet 4 | 3.00 | 15.00 | 200K | Balanced production default |
| Claude Opus 4 | 15.00 | 75.00 | 200K | Long-horizon agents, hardest reasoning |
| GPT-5 | 5.00 | 15.00 | 128K | Strong tool calling and ecosystem |
| Gemini 2.5 Pro | 1.25 | 10.00 | 1M+ | Multimodal, long context |
| Owl Alpha | 0.00 | 0.00 | 1.05M | Free tier; do not send secrets |
BYOK lets you connect your existing OpenAI, Anthropic, or Google API keys to OpenRouter. Requests route through OpenRouter infrastructure but bill directly to your vendor account. OpenRouter charges a small platform fee (typically 5% of upstream cost) for routing, observability, and fallback. BYOK is ideal when you already have enterprise pricing with a vendor but want unified routing and fallback across multiple providers.
OpenRouter hosts several models at $0 list price — including Owl Alpha and Nemotron 3 Super. New accounts also receive starter credits. Free models are excellent for prototyping and draft-tier Agent tasks, but they may log prompts for model improvement. Never route regulated data, customer PII, or production secrets through free-tier models.
VpsMesh publishes in eight languages. English pages often underperform Chinese counterparts on raw traffic — but they matter for global discoverability, backlink equity, and developer trust. If your English blog posts sit at low impressions in Google Search Console, run through this checklist before blaming content quality.
Google Search Console: Verify the /en/ property separately. Check Coverage for crawl errors, inspect URL for canonical mismatches, and review Performance filtered to /en/blog/ paths. Low impressions with zero clicks often mean indexing lag, not bad content.
hreflang tags: Every English article needs reciprocal hreflang links to zh, ja, ko, de, fr, ru, and zh-Hant versions. Missing or one-way hreflang is the most common reason Google serves the Chinese URL to English queries.
CDN and WAF tuning: Ensure Cloudflare or your CDN does not geo-block or challenge-captcha US/EU crawlers. Bot Fight Mode set to aggressive can silently drop Googlebot on new /en/ paths.
Localization, not translation: English pages must be native rewrites with English search intent — "OpenRouter API tutorial" not a literal translation of Chinese keyword clusters. Title tags, H2s, and FAQ questions should match how English developers actually search.
Internal linking from EN hub: Link new English posts from /en/blog/index.html and at least two related EN articles. Orphan pages in a low-traffic locale rarely rank.
Structured data: Ship BlogPosting and FAQPage JSON-LD on every article. FAQ schema drives rich results for long-tail queries like "Is OpenRouter free" and "OpenRouter vs direct API."
Practical tip: After publishing, submit the English URL via GSC URL Inspection and request indexing. Pair with one contextual backlink from a related EN post — internal link equity matters more than keyword density for new /en/ paths.
OpenRouter solves the inference vendor problem — one key, fallback chains, unified billing. It does not solve the host uptime problem. Agent daemons that call OpenRouter every few minutes need a machine that never sleeps, holds secrets in Keychain, and runs macOS-native tools like Claude Code, Xcode, and OpenClaw without Linux compatibility hacks.
The pattern we see in production: developers wire OpenRouter in an afternoon, then lose overnight Agent runs when a laptop closes or a free-tier cloud VM gets preempted. Linux VPS works for pure API scripts with no macOS dependency. Stacks mixing Claude Code + OpenClaw + iOS CI pay double integration tax on Linux — Metal gaps, Keychain workarounds, and Xcode absence add weeks of glue code.
VpsMesh Mac Mini M4 cloud rental bundles 24/7 uptime, remote KVM, launchd daemon supervision, and native macOS paths into predictable monthly OpEx. Point your OpenRouter config at the rental, store keys in Keychain, and let Agents run while you review diffs locally. One month is enough to validate routing, measure token burn, and confirm daemon stability before committing to a longer term.
See Mac Mini M4 rental pricing for plan comparison and help center for deployment steps, SSH setup, and daemon hardening. For multi-model gateway patterns on the same host, read our OpenClaw routing guide and persistent Agent setup walkthrough.
OpenRouter has no monthly platform fee. You pay per token at listed model rates, or $0 on free-tier models like Owl Alpha. New accounts receive starter credits for testing. Production Agent workloads should use paid routes with budget caps configured in the dashboard.
On standard routes, OpenRouter passes through upstream list pricing with no hidden markup. BYOK routes bill you directly by the vendor; OpenRouter charges a small platform fee (typically ~5%) for routing and observability. Compare rates side by side at openrouter.ai/models.
Worth it when you need multi-vendor access, automatic fallback, unified billing, or OpenAI SDK drop-in. Skip it when you have a single-vendor enterprise contract, need provider-native features (Assistants, prompt caching), or require inference in a specific cloud region without proxy hops.
400+ models from OpenAI, Anthropic, Google, Meta, DeepSeek, Mistral, xAI, and others. Use GET /api/v1/models or browse at openrouter.ai/models. Model IDs follow vendor/model-name format — e.g. anthropic/claude-sonnet-4, openai/gpt-5, google/gemini-2.5-pro-preview.
OpenRouter is SOC 2 Type II certified and does not train on API traffic by default. Route regulated data through BYOK or self-hosted open models. Rotate keys monthly, set per-key rate limits, and never commit secrets to git. Free-tier models may log prompts — keep production secrets on paid routes only.
Install the openai Python package, set base_url="https://openrouter.ai/api/v1" and api_key to your OpenRouter key. Pass any supported model ID in the model field. Add HTTP-Referer and X-Title headers via extra_headers. Full example in Section 04 above.