All 22 chapters
- Part 01 — Your First Day with AI
- Part 02 — The Developer's Toolkit
- Part 03 — Building Your First Project
- Part 04 — Leveling Up
- Part 05 — The Agent Era
- Part 06 — The Big Picture
OpenRouter
One API, every model. The switchboard for AI.
I was building a prototype for a client. The first feature needed Claude for complex reasoning. The second needed GPT-4o for vision. The third needed a fast, cheap model for classification. Three features. Three different API providers. Three accounts, three API keys, three billing dashboards, three SDKs.
I spent a morning on credential management and hadn’t written a single line of product code. Then someone on my team said: “Just use OpenRouter.”
One account. One API key. One line of code to switch between models. Same billing dashboard for everything. I changed the model name in a single parameter and went from Claude to GPT to Llama without touching anything else.
What OpenRouter is
A unified API gateway for AI models. Access to 300+ models from every major provider (Anthropic, OpenAI, Google, Meta, Mistral, xAI, DeepSeek, and dozens more) through a single endpoint. The API is fully OpenAI-compatible — if you have code that calls the OpenAI API, you change two things (the base URL and the API key) and it works.
OpenRouter is to AI models what Stripe is to payment processors. One integration handles everything. Founded by Alex Atallah (co-founder of OpenSea), it serves 250,000+ applications and processes over 750 billion tokens per week from Anthropic alone.
When it matters
Comparing models. Last month I settled an internal debate about which model handles contract analysis best. Ran the same three contracts through Claude Sonnet, GPT-4o, and Gemini Pro. Same prompt, same temperature. Changed one string each time. Claude caught a liability cap issue the others missed. GPT-4o was faster. Gemini was cheapest. The comparison that would have taken a day with separate APIs took twenty minutes.
Automatic fallbacks. Your app uses Claude. Anthropic goes down. With a direct integration, your app breaks. With OpenRouter, fallback routing tries alternative providers automatically. During an Anthropic outage in March, our client-facing chatbot routed to GPT-4o without the client noticing. We only knew because the dashboard showed a spike in fallback routing.
Cost optimization. Not every task needs a $15/million-token model. Classification, formatting, routing decisions — these can run on models costing a fraction. One credit balance covers everything from Claude Opus to free models.
Claude Code without a subscription. Point Claude Code at OpenRouter’s API with environment variables, and you pay per token with no Anthropic subscription. OpenRouter’s protocol translation handles thinking blocks, tool use, everything natively.
Team controls. Workspaces with separate API keys, routing defaults, spending caps, and Zero Data Retention policies. Development keys limited to $5/day. Production keys at $50/day. No surprise bills.
Model variants
OpenRouter uses a provider/model-name format. What makes it interesting is suffixes that change routing: :free uses the zero-cost version (great for prototyping), :nitro optimizes for speed, :floor optimizes for price, :exacto sorts by tool-calling reliability, :thinking enables reasoning mode. A special openrouter/free model randomly selects from available free models that support your request’s features.
Pricing
Per-token prices pass through at provider cost. No per-token markup. The business model is a 5.5% fee on credit purchases. Add $100, pay $105.50, get $100 of inference. Bring-your-own-key is also supported — first million requests per month free, then 5% fee.
What OpenRouter is NOT
Not cheaper than going direct. You pay for convenience through the 5.5% fee. For high-volume single-model workloads, direct API access may save money. We have one client project using exclusively Claude Sonnet at high volume — for that, we use Anthropic directly.
Not a privacy risk by default (they don’t log prompts or completions), but requests pass through their infrastructure. Enable Zero Data Retention for sensitive workloads.
Adds minimal latency — approximately 15ms. Negligible for most applications.
The cost optimization strategy
The biggest win isn’t convenience — it’s using the right model for each task. Use a cheap model (Gemini Flash at $0.15/M tokens) to classify incoming requests. Route complex reasoning to Claude Sonnet ($3/M). Route simple lookups to Haiku ($1/M). Prototype on free models.
We cut a client project’s monthly AI spend by about 40% with this pattern. The app was using Claude Sonnet for everything, including tasks that amounted to “is this email a support request or a sales inquiry?” Routing classification to Gemini Flash and keeping Sonnet for actual responses was a one-afternoon change. Quality didn’t drop. The bill did.
The bottom line
OpenRouter solves a real problem. The AI model market is fragmented. If you’re building anything that uses more than one model, or want the flexibility to switch without rewriting integrations, OpenRouter is the answer.
Setup takes five minutes. Use Claude for reasoning. GPT for vision. Gemini Flash for speed. DeepSeek for cost. Free models for prototyping. One key, one bill, one dashboard. That’s a simpler way to build.
This is the free web edition of Chapter 14. The full text — with integration code examples, provider routing configurations, BYOK setup guides, and CI/CD pipeline patterns — is available in 42: The AI Builder’s Stack, coming Q3 2026 on Amazon in hardcover, paperback, and digital.