Cost & Performance Intermediate·9 min read· ← Back to Guides

AI Gateways & Model Routing: Optimise for Cost per Successful Task

The cheapest model on the price list is often the most expensive one in production. What you actually pay for is a successful task — and that includes retries, escalations, human clean-up and the failures nobody caught. An AI gateway is where you control that number.

Most teams start by calling one model directly from application code. It works — until there are five features, three providers, a finance team asking where the money went and an outage at a provider on a Friday night. At that point the model call needs the same treatment every other critical dependency gets: a single, governed entry point. That's an AI gateway.

The number that matters: cost per successful task

Per-token price tells you what one attempt costs. Users care about one result. The honest formula is:

cost per successful task = (model spend + retries + escalations + review effort) ÷ tasks that actually succeeded

A worked example with illustrative numbers: a small model costs $0.002 per attempt and solves 70% of a task on its own; a large model costs $0.02 and solves 95%. Sending everything to the large model costs $0.02 per attempt and leaves 5% of tasks failing. A cascade — try the small model, verify, escalate the 30% that fail — costs about $0.002 + 0.3 × $0.02 ≈ $0.008, with roughly the large model's success rate. Send everything to the small model without verification and the "cheap" option quietly ships 30% wrong answers, which someone pays for later.

What an AI gateway does

Routing strategies, from simple to smart

  1. Static by task. Classification and extraction go to a small model; long-form reasoning goes to a large one. Easy, and often half the savings.
  2. Complexity-based. A cheap classifier (or simple heuristics: input length, number of documents, user tier) predicts how hard a request is and picks a tier.
  3. Cascades. Try the small model first, run a cheap check, escalate only when the check fails. This is where the biggest wins usually are.
  4. Quality-aware. Route using eval scores per model and task type, refreshed as models change — not on vibes or last quarter's benchmark.
  5. SLA- and budget-aware. Prefer the fastest healthy option for interactive paths; prefer the cheapest acceptable option for batch jobs; tighten when a budget is nearly spent.
# routing policy (illustrative)
routes:
  - match: { task: classify }          # cheap, high-volume
    model: small-fast
  - match: { task: answer, tier: free }
    cascade:
      - model: small-fast
        verify: schema_valid && grounded_score >= 0.8
      - model: large-reasoning         # only the ~20–30% that fail verification
  - match: { task: answer, tier: enterprise }
    model: large-reasoning
    fallback: [large-reasoning@provider-b]
limits:
  per_tenant_monthly_usd: 2000
  timeout_ms: 20000
cache:
  exact: true
  semantic: { threshold: 0.95, ttl: 1h }

Cascades only work if you can verify cheaply

Escalation needs a signal that the first answer is not good enough. Good signals are cheap and specific: the output parses against the expected schema, cited passages actually contain the claim, two samples agree, a small judge model scores it above a threshold, or a tool call succeeds. Without a check, a cascade is just "use the small model and hope".

Guardrails and routing are the same layerThe gateway already sees every prompt and response, so it's the natural place to enforce PII redaction, tenant isolation and output validation — and to record an audit trail of which model answered what. Bolting those checks into each application separately is how they drift apart.

Measure before and after every change

Pitfalls to avoid

Key takeaways

  • Optimise cost per successful task, not price per token.
  • An AI gateway centralises routing, caching, guardrails, resilience and cost visibility.
  • Cascades (small model → verify → escalate) usually deliver the biggest savings — but need a cheap verification signal.
  • Treat routing changes like releases: evals, shadow traffic, canaries and an easy rollback.
← Optimizing LLM Tokens See the Vertex Studio AI Runtime →

Related