Route agent model traffic through a governed gateway
Choosing
Section titled “Choosing”-
SHOULD use a central gateway when more than one person, agent or application calls models, or when you need per-key budgets, spend tracking, logs in one place or guardrails.
-
SHOULD choose the gateway by scope:
Need Gateway type Example Team or organisation: shared keys, budgets, routing, guardrails, MCP access Central gateway (self-hosted or managed) LiteLLM proxy One developer: send a coding agent’s requests to other providers or models per task type Local router on the developer’s machine Claude Code Router
Keys and access
Section titled “Keys and access”- MUST keep real provider keys only in the gateway, and give each agent, team or app its own gateway-issued key (virtual key) with allowed models, rate limits and a hard budget, so a runaway job or leaked key stops at its cap.
- MUST protect the gateway’s admin interface and master key (SSO, network restriction, no default keys), and store its credentials in a secret manager (BP-0033).
- MUST treat the gateway as a high-value component: it sees every prompt and response. Run it on trusted infrastructure, pin its version, review its configuration and plugins, and patch it promptly (BP-0044).
Routing
Section titled “Routing”- MUST route data only to providers and regions approved for it. Classify which agents and data may use which providers, and enforce it in the gateway’s model allow-lists, not by convention.
- MUST evaluate a model before routing real work to it, especially when substituting a different provider behind an agent built for another model; check tool-calling, long-context and output quality on your tasks (BP-0006).
- SHOULD configure fallbacks and retries in the gateway for provider outages, with fallbacks to models that passed the same evaluation.
- SHOULD respect provider and tool terms when routing (for example whether a client may be used with other providers).
Observability
Section titled “Observability”- SHOULD log usage per key (tokens, cost, latency, errors) at the gateway and send traces to your tracing system with the agent’s run ID (BP-0039).
- MUST NOT log full prompts and responses by default; redact secrets and personal data where content logging is needed.
- MUST keep the gateway’s price table current: record source and date for each model price, refresh it on a schedule, and reconcile computed spend against provider invoices monthly (BP-0047 rules 12–17).
When to apply
Section titled “When to apply”Teams running several agents or applications against models; developers routing a coding agent to multiple providers.
Examples
Section titled “Examples”Central: agents call https://llm-gw.internal/v1 with their own virtual key; the gateway holds provider keys, enforces worker-* keys to small models with a monthly budget, falls back from a primary to a secondary provider on errors, and masks personal data before it leaves.
Local: Claude Code runs with ANTHROPIC_BASE_URL pointing at a local Claude Code Router, which sends background tasks to a cheaper model and long-context tasks to a long-context model, using keys read from the developer’s environment.
Anti-patterns
Section titled “Anti-patterns”- Provider master keys copied into every agent’s environment.
- A gateway on the default master key, open on the network.
- Silently swapping an agent to an unevaluated model “because it is cheaper”.
- Routing confidential data to a provider not approved for it.
Checklist
Section titled “Checklist”- Gateway type fits scope (central vs local)
- Provider keys only in the gateway; virtual keys per agent with budgets
- Admin access protected; gateway pinned, reviewed, patched
- Data-to-provider rules enforced; substitute models evaluated
- Fallbacks evaluated; usage and traces logged; content redacted