OpenRouter routes OpenAI, Anthropic, Google, and more through a single OpenAI-compatible API: change base_url and model to switch between GPT, Claude, and Gemini without opening separate vendor accounts. This 2026 walkthrough covers openrouter.ai signup, adding credits, creating an API key, picking models in the catalog, and your first calls with curl and Python. For per-token rates and monthly math, see OpenRouter pricing comparison; for Claude Code subscriptions, see Claude Code 2026 costs.
https://openrouter.ai/api/v1Who OpenRouter is for vs. direct vendor APIs
OpenRouter is a hosted aggregator: you prepay credits; requests are routed to providers and billed at the listed input/output token rates. Good fit when you want:
- One key, many models (e.g. cheap Gemini Flash by day, Claude Sonnet for coding at night)
- One billing path when separate OpenAI / Anthropic / Google accounts are awkward
- Agents or scripts already built on the
openaiSDK—only the endpoint changes
Poor fit when data must not pass a third-party proxy, or you have enterprise discounts with a single vendor—use direct APIs or a self-hosted gateway instead.
OpenRouter vs. Claude Pro only?
Claude Code Pro/Max is flat monthly + usage pools—great for daily terminal coding. OpenRouter is pure usage—better for scripts, multi-model routing, or spiky experiments. Stack both if needed. See real monthly AI programming costs.
Sign up and sign in
- Go to openrouter.ai and click Sign in.
- Use Google, GitHub, or email; teams should use a company email and enable 2FA under Account → Security.
- After login, the Dashboard shows Credits, Keys, and Activity.
Signup is free; some free models may work with zero balance, but production should assume paid models need credits.
Credits, balance, and usage
Use Settings → Credits or Add Credits on the dashboard. Payment methods depend on what the console offers at checkout.
- Prepaid: requests fail when balance is empty—no post-paid invoice.
- Top-up fees: some payment rails add ~5.5%—factor that into effective $/M tokens; see our pricing article.
- Activity: filter by key, model, and time to debug spend.
Create and manage API keys
- Keys → Create Key.
- Name keys (
cursor-dev,ci-nightly) for Activity attribution. - Set limits or expiry for CI or intern keys when the UI allows it.
- Store the secret in a password manager—never commit to Git.
Authorization: Bearer <OPENROUTER_API_KEY>
Recommended optional headers:
HTTP-Referer: https://your-app.example
X-Title: Your App Name
Pick GPT, Claude, and Gemini in the catalog
Open Models and use slash IDs in model:
| Family | Example model ID (2026 catalog) | Notes |
|---|---|---|
| Claude | anthropic/claude-sonnet-4.5 | Balanced coding; verify latest ID in catalog |
| GPT | openai/gpt-5 or openai/gpt-5-mini | Flagship vs. cost-saving mini |
| Gemini | google/gemini-2.5-pro, google/gemini-2.5-flash | Flash for throughput |
First call: curl and Python
POST https://openrouter.ai/api/v1/chat/completions
Call Claude
curl https://openrouter.ai/api/v1/chat/completions \
-H "Authorization: Bearer $OPENROUTER_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"anthropic/claude-sonnet-4.5","messages":[{"role":"user","content":"Explain OpenRouter in three sentences"}]}'
Call GPT
curl https://openrouter.ai/api/v1/chat/completions \
-H "Authorization: Bearer $OPENROUTER_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"openai/gpt-5-mini","messages":[{"role":"user","content":"Python hello world"}]}'
Call Gemini
curl https://openrouter.ai/api/v1/chat/completions \
-H "Authorization: Bearer $OPENROUTER_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"google/gemini-2.5-flash","messages":[{"role":"user","content":"One pro of REST vs GraphQL"}]}'
Python with the OpenAI SDK:
from openai import OpenAI
import os
client = OpenAI(
base_url="https://openrouter.ai/api/v1",
api_key=os.environ["OPENROUTER_API_KEY"],
)
resp = client.chat.completions.create(
model="anthropic/claude-sonnet-4.5",
messages=[{"role": "user", "content": "Hello"}],
)
print(resp.choices[0].message.content)
Wire up Cursor, Claude Code, and other clients
- Cursor / Cline: set OpenAI-compatible base URL to
https://openrouter.ai/api/v1, key = OpenRouter key, model = slash ID. - Claude Code: defaults to Anthropic subscription; custom OpenRouter endpoints change often—check CLI docs. Many teams use Claude Code for daily work, OpenRouter for scripts.
- CI / cloud Mac: inject
OPENROUTER_API_KEYvia secrets, not the repo.
FAQ
Does an OpenRouter key replace an OpenAI key?
In compatible clients, yes—point base URL to OpenRouter. Billing and model list follow OpenRouter, not the OpenAI dashboard.
Streaming?
Set "stream": true and consume SSE like OpenAI.
Cost control?
Per-environment keys, limits, default to Flash/mini, upgrade only after eval—see pricing.
Same as Anthropic /v1/messages?
Primary path is /v1/chat/completions; check OpenRouter docs if you need Messages-native clients.