Source statement: OpenRouter is a unified interface for LLM APIs. One API key gives access to 300+ models from 60+ providers, and the presenter uses it as the baseline for every LLM project he builds.
The integration is one line of change: keep the OpenAI Python SDK and point base_url at https://openrouter.ai/api/v1. Any SDK or agent framework that speaks the OpenAI protocol works unchanged.
Model fallbacks ride along in extra_body={"models": [primary, *fallbacks]}. If the primary model or its provider is down, OpenRouter walks the chain, so the application stays up when a single vendor has an outage.
Providers are also redundant per model: the same model is often hosted by several providers with different pricing, latency, and uptime, and OpenRouter routes to a healthy one automatically.
The demo class (about 80 lines) covers chat, model swapping, fallbacks, multi-turn history, latency measurement, and streaming; the demos compare GPT-5 family, Gemini 2.5 Pro, and DeepSeek side by side on the same prompts.
Closing argument: with one key in one .env, an AI coding agent can build and run LLM projects end to end without a human hunting API keys from every provider, since coding agents cannot generate provider keys themselves.
Why a unified interface
Source statementwhen building production AI agent pipelines, you want models available immediately, zero downtime, multiple providers to route through, and minimal cost. Every provider has outages; when OpenAI or Azure is down, some other provider hosting the same model can serve as fallback, so "your application will never be down." [00:00-01:31]
Visual evidence at 00:45: the homepage claims 70T monthly tokens, 5M+ global users, 60+ active providers, 300+ models, with feature cards for One API for Any Model, Higher Availability, Price and Performance, and Custom Data Policies.
Inferencethe pitch is aggregation with health-aware routing, not a new model. The value scales with how many different models a project touches and how much an outage costs.
Site tour: finding models
The models page filters by input modality (text, image, file, audio, video), context length, and prompt pricing. Most current models are multimodal. New models are available on OpenRouter as soon as they appear in the catalog, including some in preview, and there are free options. [01:31-02:58]
Visual evidence at 02:05: filters on the left (634 text models, 26 embeddings, plus image/audio/video/rerank/TTS categories); cards show per-model pricing, context, and release date.Visual evidence at 02:20: the Claude Opus 4.7 card (released Apr 16, 2026, 1M context, $5/M input, $25/M output) sits alongside Alibaba Wan 2.7 and ByteDance Seedance 2.0 Fast. The speaker's point: models this new are usable instantly through the same key.Visual evidence at 02:45: the weekly LLM leaderboard has Claude Sonnet 4.6 first at 1.39T tokens, DeepSeek V3.2 second at 1.28T, with MiMo-V2-Pro, Gemini 3 Flash Preview, Claude Opus 4.6, and GPT-5.4 also in the top ten.
Inferencethe rankings page doubles as a cheap market-share signal for what production systems actually run, which is useful when picking a default model family.
Provider routing, pricing, and uptime
Source statement"That's why it's called OpenRouter. It's just going to route your API calls to some provider for the model that you have specified." Each model page lists every provider hosting it with their own pricing, latency, throughput, and uptime, and providers can act as fallbacks for each other. [02:58-04:29]
Visual evidence at 03:05: DeepSeek V3.2 (released Dec 1, 2025, 131K context, $0.252/M input, $0.378/M output) with the providers intro: OpenRouter "routes requests to the best providers that are able to handle your prompt size and parameters, with fallbacks to maximize uptime."Visual evidence at 03:35: three providers for the same model with different latency (4.30s, 3.69s, 0.96s), throughput (15, 14, 3 tps), max output, and per-token prices.Visual evidence at 03:50: effective pricing over the past hour, weighted average $0.213/M input and $0.477/M output, with per-provider input/output prices and cache hit rates.
The documentation covers the features the class uses: model fallbacks, provider selection, model variants, routers, tool calling, multimodal inputs, and streaming. The docs also expose an agent-skill file (openrouter.ai/skills/create-agent/SKILL.md) meant to be fed to a coding agent. [03:55-04:29]
Visual evidence at 04:10: the quickstart with Models & Routing sidebar entries (Model Fallbacks, Provider Selection, Auto Exacto, Model Variants, Routers) and the "Read https://openrouter.ai/skills/create-agent/SKILL.md" snippet for coding agents.
Source statement (worth remembering): you can feed the OpenRouter docs into Claude Code or Codex and have it wire up features like image input for you. [10:22-10:45]
Setup: one key, two dependencies
The whole environment is a .env with a single OPENROUTER_API_KEY and a two-line requirements.txt. No Anthropic, OpenAI, or Google accounts needed to test all their models. [04:29-05:00, 09:37-10:22]
Visual evidence at 10:08: the entire dependency list is openai>=1.54.0 and python-dotenv>=1.0.1. The OpenAI SDK is used as the client; OpenRouter is just the base URL.
The OpenRouterAgent class
The class wraps the OpenAI SDK. A Replydataclass returns text, model_used, and latency_s so demos can compare models. __init__ takes model, system prompt, and fallbacks; history starts with the system message; the client is OpenAI(base_url="https://openrouter.ai/api/v1", api_key=os.environ["OPENROUTER_API_KEY"]). [06:01-07:32]
Visual evidence at 06:00: from openai import OpenAI, load_dotenv(), the Reply dataclass, and the __init__ storing model, system prompt, fallbacks, history, and the routed client.Visual evidence at 05:45: swap(model) returns self for chaining, reset() rebuilds history from the system prompt, and _body() returns {"models": [self.model, *self.fallbacks]} if self.fallbacks else {} — the fallback chain payload.
The chat method appends the user message to history, times the call with time.perf_counter(), passes the fallback chain as extra_body=self._body(), appends the assistant reply back into history (which is what makes multi-turn work), and records which model actually served the request from response.model. [06:50-07:32]
Visual evidence at 06:50: self.client.chat.completions.create(model=self.model, messages=self.history, extra_body=self._body()), latency measurement, history append, and last_model_used = response.model.
The stream method is the same call with stream=True, yielding each chunk's delta as it arrives and recording the serving model from the first chunk. Streaming matters for user-facing chat (the typing-machine effect); backend jobs can skip it. [07:32-08:30]
Visual evidence at 07:40: the generator appends the user message, iterates the stream, captures chunk.model as served, yields deltas, then appends the joined chunks to history.
Picking a model ID and checking its providers
Model IDs are copied straight from the model page (author/slug, e.g. openai/gpt-5.4-nano). Before relying on a model, its provider list shows the redundancy you get: GPT-5.4 Nano is hosted by both Azure and OpenAI. Source statement: it is very unlikely both are down at the same time, but likely that one of them is down at some point in a given week. [09:02-10:22]
Visual evidence at 09:45: Azure at 1.75s latency / 28 tps and OpenAI at 0.63s / 83 tps, both 400K context, $0.20/M input, $1.25/M output.
First call and swapping models in a loop
DEMO 1 instantiates the agent with openai/gpt-5.4-nano and asks "What is OpenRouter? One sentence." DEMO 2 loops over models, calling agent.swap(model).reset() then the same prompt, printing each model's answer and latency. [10:22-11:54]
Visual evidence at 10:32: the first reply ("OpenRouter is a service that lets you access and route requests to multiple AI models from different providers...") above the DEMO 2 loop listing openai/gpt-5.4-nano, google/gemini-2.5-pro, deepseek/deepseek-chat.Visual evidence at 11:40: the haiku prompt about distributed systems returns from openai/gpt-5.4-nano-20260317 in 1.20s.Visual evidence at 11:55: same prompt, same code path: GPT-5.4-nano 1.20s vs Gemini 2.5 Pro 14.24s. The transcript rounds these to "1.2 seconds" and "14 seconds," with DeepSeek around 4 seconds.
Source statementlatency differences this large are prompt-dependent; these are basic prompts, and the point is how cheap it is to test which model actually fits your workload. [11:54-12:30]
Comparing models on a harder prompt
DEMO 3 runs "Explain attention in transformers in two sentences" across GPT-5, Gemini 2.5 Pro, and DeepSeek, printing model, latency, and text as structured output. [11:54-13:26]
Visual evidence at 13:30: the DEMO 3 results are on screen — openai/gpt-5-2025-08-07 in 4.59s, google/gemini-2.5-pro in 19.68s, deepseek/deepseek-chat-v3 in 9.33s — beneath the DEMO 4 fallback-chain code with its comment: "OpenRouter walks models in order, falling through on rate limits / outages / context overflow. Here the primary is healthy so it serves; the chain is what protects you in production."
Fallback chains
DEMO 4 sets model="openai/gpt-5.4-nano" with fallbacks=["openai/gpt-5.4", "google/gemini-2.5-pro"]. Since the primary is healthy, it serves the request; the chain only engages on rate limits, outages, or context overflow. Source statement: "There's nothing worse than our app being down just because some LLM provider is down." [13:26-14:10]
Visual evidence at 13:50: Served by: openai/gpt-5.4-nano-20260317 confirms the primary model answered; the fallbacks stayed idle.
Inferencebecause _body() puts the primary first in the models list, fallback behavior is pure configuration; application code never branches on provider health.
Multi-turn conversations
DEMO 5 builds a tutor agent (anthropic/claude-opus-4.7, system prompt "You are a friendly tutor. Keep answers short.") and loops three related questions through the same agent. History accumulation is what lets the second and third answers resolve "there" and "it" to Tokyo. Source statement: changing the system prompt is all it takes to specialize the agent, e.g. feeding an FAQ turns it into a customer-service agent. [14:10-16:00]
Visual evidence at 15:15: Q/A pairs — capital of Japan (Tokyo), population ("about 14 million... 37 million in the greater metro area"), famous dish (sushi, "Edomae sushi... originated there"). Context carries across turns.
Streaming with fallbacks
DEMO 6 streams two coding questions through agent.stream() with the fallback chain active, printing deltas as they arrive. After each answer, the served model is printed from last_model_used. [16:00-17:32]
Visual evidence at 16:40: the list-vs-tuple explanation streaming into the terminal token by token from the stream loop with flush=True.Visual evidence at 16:55: both answers complete, each tagged [openai/gpt-5.4-nano-20260317], showing which model actually served each turn of the streamed conversation.
Closing source statementbeyond uptime and pricing, the practical win is that one key plus centralized usage tracking removes the most annoying part of agent-built projects, hunting down and wiring API keys for each provider, because coding agents "can't go in and generate API keys for you." [16:45-17:32]
The client library, pointed at OpenRouter's base URL
All code
https://github.com/openai/openai-python
python-dotenv
Loads the single API key from .env
Setup
https://pypi.org/project/python-dotenv/
Video source
Full walkthrough and demo code
Entire playbook
https://youtu.be/sgQwF1aOu9U
Claims to verify
"Your application will never be down" is marketing-grade phrasing; fallbacks reduce, not eliminate, downtime (OpenRouter itself is a single point of failure in the chain).
OpenRouter's fee/markup structure is not mentioned in the video at all. Check current pricing terms (platform fee on credits, BYOK terms) before adopting for cost reasons; the per-token prices shown are provider passthrough.
Latency numbers (1.20s nano vs 14.24s / 19.68s Gemini 2.5 Pro) are single-run, basic-prompt measurements from the demo, not benchmarks.
"Models available instantly when you see them" — availability lag between a lab release and OpenRouter listing varies; the Opus 4.7 card shown was days old, which supports but does not prove "instant."
The presenter's class link "in the description" was not fetched during this run; the code above is transcribed from screen.
Auto-caption model names were corrected against on-screen evidence: "C-Dance 2.0" is ByteDance Seedance 2.0, "clean video one" is Kling Video O1, "Kimmy" is MoonshotAI Kimi K2.6.
Glossary
unified interface: One API endpoint and request format that fronts many different model providers, so switching models never means rewriting integration code.
SDK: A provider's official client library; here the OpenAI Python package, reused unchanged against OpenRouter's endpoint.
base URL: The root address an SDK sends requests to; changing it is how the OpenAI client gets pointed at OpenRouter instead of OpenAI.
API key: The secret token that authenticates requests; OpenRouter's whole pitch is needing only one of these for every model.
fallback chain: An ordered list of models tried in turn; if the first is down, rate-limited, or over its context limit, the request falls through to the next.
fallback: Any backup model or provider that serves a request when the primary cannot.
rate limit: A provider-imposed cap on how many requests or tokens you can send per time window; exceeding it rejects calls until the window resets.
context overflow: A request whose combined input is larger than the model's context window, so the model cannot process it.
context length: How much text (measured in tokens) a model can hold in one request, input and output combined.
tokens: The word fragments models actually read and write; API pricing is quoted per million of them.
latency: Time from sending a request to receiving the response (or its first chunk).
throughput: How fast a provider generates output once started, usually tokens per second.
tps: Tokens per second; the unit provider dashboards use for throughput.
uptime: The share of time a provider actually serves requests successfully; the metric fallbacks exist to protect.
cache hit rate: How often a provider can reuse previously processed input tokens at a discounted price instead of reprocessing them.
weighted average: A price average across providers that counts busier providers more heavily, giving a realistic effective cost.
passthrough: Pricing forwarded as-is from the underlying provider, with no visible margin added at the router layer.
markup: The router's own fee on top of provider prices; not covered in the video and worth checking before adopting.
BYOK: Bring Your Own Key; using your existing provider API keys through the router instead of the router's billing.
system prompt: The standing instruction that shapes an agent's behavior for every message; swapping it is how one class becomes a tutor or a support agent.
multi-turn: A conversation where prior questions and answers are resent as history, so the model can resolve references like "there" or "it".
streaming: Receiving the response token by token as it generates instead of waiting for the whole answer; what makes chat UIs feel live.
structured output: Model responses returned in a fixed machine-readable shape (fields like text, model, latency) instead of free prose.
dataclass: A small Python class that just holds named fields; used here to return text, model used, and latency together.
generator: A Python function that yields values one at a time as they become available; the natural shape for streaming chunks.
modality: The kind of input or output a model handles: text, image, file, audio, or video.
multimodal: A model that accepts more than one modality, for example text plus images in the same request.
agent framework: A library that orchestrates LLM calls into multi-step behavior (tools, memory, loops); OpenRouter sits below any of them.
Personal recommendations
1
Route Alexana LLM pipelines through OpenRouter as the unified key
One .env key served GPT-5 family, Claude Opus 4.7, Gemini 2.5 Pro, and DeepSeek through the unchanged OpenAI SDK.
System value
Any Alexana project that calls LLM APIs directly (scripts, PlanScout-style pipelines, client automations) could swap per-provider keys for one key with centralized usage visibility, and new models become testable without new accounts.
Proposed form
Evaluation task first (fee structure, data policy, latency overhead vs direct keys), then a scoped migration of one pipeline
Target project
Personal computer tooling (evaluation), then per-project
2
Adopt the fallback-chain pattern for any production LLM call
extra_body={"models": [primary, *fallbacks]} made outage handling pure configuration; the healthy primary served and the chain stayed idle.
System value
Client-facing automations (RR flows, form handlers, future agents) fail soft during provider outages instead of erroring, with zero branching logic in application code.
swap(model).reset() in a loop produced same-prompt, side-by-side answers with latency and served-model per reply.
System value
Before committing a client workload to a model, a five-minute harness run answers "which model is fast enough and good enough at this prompt" with evidence instead of vibes.
Proposed form
Small script in ~/Projects (own repo or a utilities repo), built only if candidate 1's evaluation is positive
Target project
New small code utility
4
Feed the OpenRouter create-agent skill file to a coding agent when building on OpenRouter
The docs expose openrouter.ai/skills/create-agent/SKILL.md and the presenter recommends feeding docs to Claude Code/Codex for feature wiring (e.g. image input).
System value
If Anthony adopts OpenRouter, Claude Code sessions get the vendor's own integration contract instead of reconstructing it from web search.
Proposed form
Reference line in tooling docs after auditing the skill file's instructions (untrusted input until read)
Target project
Personal computer tooling
Take this with you
Save the playbook to read later, or hand the raw notes to your favorite AI.
What's this?
The Markdown file (a .md file) is a plain-text copy of this whole playbook, written in the simple format AI chat tools read best. It keeps the headings, links, timestamps, and captions and drops all the page styling. Think of it as the raw notes behind this page, ready to hand to an assistant.
To use it, download the file and drag it into ChatGPT, Claude, or any AI chat (or just paste the text in), then ask for what you want: “Summarize this into a one-page cheat sheet,” “Turn these steps into a checklist I can follow,” or “Quiz me on the key ideas.” Because the file is already structured, the assistant works from the real content instead of guessing.