Model and Provider Rules: Routing, Fallback, and Cost Discipline
These rules keep model identity, provider routing, fallback, and spend as runtime policy instead of scattered constants and tribal knowledge.
Search across all documentation pages
These rules keep model identity, provider routing, fallback, and spend as runtime policy instead of scattered constants and tribal knowledge.
Multi-turn tool use multiplies tokens quickly.
Without provider-agnostic design, predeclared fallbacks, and cost budgets, the first real traffic week becomes either an outage or an invoice incident.
fast, balanced, strong, or a named route (triage, planner, coder).| Situation | Default action |
|---|---|
| New agent call site | Request a policy name, never embed a model id |
| Quality not meeting bar | Escalate tier with eval evidence on a fixed suite |
| Cost too high | De-escalate cheap steps first; re-eval; cut turns and tools next |
| Provider outage | Follow predeclared fallback; alert; do not invent chains live |
| Sensitive data | Restrict providers by data policy before optimizing price |
| Experiment | Time-boxed override + promote via config if it wins |
from dataclasses import dataclass
@dataclass(frozen=True)
class ModelRef:
provider: str
model_id: str
POLICY = {
"fast": ModelRef("openrouter", "meta-llama/llama-3.3-70b-instruct"),
"balanced": ModelRef("openrouter", "anthropic/claude-sonnet-4.5"),
"strong": ModelRef("openrouter", "openai/gpt-5"),
}
FALLBACK = {"strong": "balanced", "balanced": "fast"} # acyclic
def resolve(policy: str) -> ModelRef:
return POLICY[policy]Model ids are illustrative; verify current provider and OpenRouter names at build time.
No.
It is one convenient multi-model gateway.
The rules are logical policies, budgets, and fallbacks in your system; transport can be direct APIs or a gateway.
Two or three (fast / balanced / strong) cover most designs.
Add named routes when a step has a special quality or compliance bar.
Often yes.
Validate with evals; do not assume a stronger planner always wins.
Model ids, fallbacks, budgets, and default policies belong in config.
Agent goal logic and tool handlers belong in code that requests policies by name.
Run the same golden tasks and production samples; compare task success and safety metrics, not vibe.
Define a degraded mode: reduce autonomy, queue work, or fail closed with a clear operator alert rather than silently serving bad answers.
Both when possible.
App per-run budgets catch loop waste; provider or key caps catch total runaway spend.
On any material quality or cost incident, when providers change pricing or retention policy, and on a fixed quarterly (or similar) review.
No.
Even one multi-turn agent benefits from a policy name, a budget, and a fallback.
Fundamentals introduce policy-based selection for early agents.
This page adds production cost discipline, provider routing, and fallback operations for tech leads.
Treat latency as a first-class axis: some routes optimize for p95 response time, others for cost or quality.
Document which axis each policy optimizes.
Yes as an explicit, reviewed exception with owner and rationale - not as an unlogged special case in one handler.
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.
Reviewed by Chris St. John·Last updated Jul 16, 2026