OpenRouter in Production Best Practices
Ten practices for reliability, cost control, and observability when OpenRouter backs a production agent.
Use this as a launch rubric and a quarterly review checklist.
How to Use This List
- Walk A for architecture and config, B for resilience and tools, C for operate-and-improve loops.
- Tick items only when true in code, config, or dashboards - not as intentions.
- Pair with Architecting an Agent Around a Model-Agnostic Gateway for design and Case Study: Migrating a Single-Provider Agent to OpenRouter for cutover.
- Re-check after new models, tools, or traffic ramps.
A - Architecture and Configuration
- 1. Route all model calls through one gateway module. No scattered SDKs or base URLs in agent nodes.
- 2. Use logical
model_refvalues mapped by config. Promotions and rollbacks are registry edits, not multi-file refactors. - 3. Pin and document OpenRouter model slugs per environment. Dev, staging, and prod registries are explicit and versioned.
- 4. Set attribution headers consistently. Stable
HTTP-Referer/X-Title(or current equivalents) from the shared client. - 5. Keep secrets in a vault or secret manager. Keys are rotatable; spend caps enabled per key where available (verify at build).
B - Resilience, Tools, and Safety
- 6. Enforce host-side stop conditions. Max turns, wall-clock timeout, and cost budget apply to every agent run.
- 7. Implement backoff with jitter on 429/5xx. Cap attempts; honor sane
Retry-After; do not retry auth or bad-request errors. - 8. Use capability-compatible fallbacks only. Fallback models must support tools and features the step needs.
- 9. Validate tool arguments and isolate side effects. Schema-check JSON; idempotent tools; never re-fire irreversible actions on model retry alone.
- 10. Apply least privilege to tools and data leaving the boundary. Especially when hybrid with Ollama or multi-provider cloud paths.
C - Observability, Cost, and Change Control
- 11. Log run_id, model_ref, resolved model, latency, tokens, retries. Redact PII by default.
- 12. Alert on 429 rate, fallback share, error rate, and cost anomalies. On-call has a short OpenRouter runbook.
- 13. Eval before promoting a model. Offline suite gates registry changes; online guardrails cover canaries.
- 14. Prefer sticky A/B assignment for multi-turn runs. Experiments change one lever at a time.
- 15. Review spend and quality by role weekly. Planner vs triage vs fallback should not share one opaque bill.
Applying These Practices in Order
- Architecture (1-5): cheap early; painful after copy-paste clients spread.
- Resilience and safety (6-10): launch blockers for any tool-using agent.
- Operate (11-15): how you keep OpenRouter honest under real traffic.
FAQs
Why more than ten checkboxes?
Items 1-10 are the core production practices. Items 11-15 extend them into observability and change control after launch.
What is the single highest-leverage practice?
A single gateway with registry-mapped models (practices 1-2). Most other controls hang off that seam.
Do these practices require LangGraph or CrewAI?
No.
They apply to custom loops and frameworks alike.
How often should we re-eval models?
On every registry change, and on a calendar cadence (for example monthly) because quality and pricing shift.
Is OpenRouter fallback enough without client retries?
No.
Combine bounded client retries with capability-safe model fallbacks. See OpenRouter Rate Limits, Retries, and Backoff Strategies.
How do we handle free models in production?
Only on noncritical paths after tool evals and with strict rate/cost caps. Hot agent paths need predictable capacity.
What belongs in the on-call runbook?
Credit exhaustion, 429 storms, fallback disable switch, registry rollback, and where to read latency/cost dashboards.
Can we skip sticky A/B if we only canary by percentage?
Canary ramps help ops, but multi-turn agents still need per-run stickiness when two models are live.
How does Ollama hybrid fit this list?
Treat Ollama as another backend behind the same gateway and apply practices 8-10 carefully for local-only data. See Building a Self-Hosted Fallback Layer: Ollama + OpenRouter.
What evidence shows practice 1 was violated?
More than one module constructing OpenAI/OpenRouter clients or hardcoding base_url outside the gateway package.
Should product managers edit the model registry?
Prefer eng-owned config with product input via experiments. Unreviewed slug changes are production incidents waiting to happen.
Where should teams link this checklist?
Launch PR templates, agent platform README, and quarterly reliability reviews.
Related
- Architecting an Agent Around a Model-Agnostic Gateway - design spine
- Production OpenRouter Basics - first setup
- Tool Calling Through OpenRouter Across Different Providers - tools
- OpenRouter Rate Limits, Retries, and Backoff Strategies - 429 playbook
- A/B Testing Models in Production via OpenRouter - experiments
- Case Study: Migrating a Single-Provider Agent to OpenRouter - migration
Stack versions: Pins from the category manifest (verify at build): OpenRouter (~315+ models, July 2026 pricing/fees); LangGraph 1.0+; CrewAI 1.14+; Microsoft Agent Framework 1.0; Vercel AI SDK 6; Pydantic AI (latest); LlamaIndex (latest); OpenAI Agents SDK (latest + MCP); MCP (Linux Foundation governance); A2A (HTTP+SSE+JSON-RPC 2.0); Solana
@solana/web3.js+@solana/spl-token.