AI Gateways: Routing, Fallback, Caching & Metering

One API in front of many model providers: fallback chains that switch only before the first token, circuit breakers, stream watchdogs, exact and semantic caching, token budgets, per-tenant metering, BYOK isolation and TTFT dashboards.

Overview

Why this topic

Once a product calls more than one model, every team writes the same code: retries, timeouts, a second provider when the first is down, a cache, a usage counter. An AI gateway puts that code in one place, between your services and the providers, behind one API (usually the OpenAI chat completions shape).

The difference shows up in four places.

  • Keys: without a gateway, each service holds provider keys. With one, the keys live in the gateway and services hold only a gateway token.
  • Outages: without a gateway, a provider outage breaks every feature. With one, the gateway moves traffic to the next model in the chain.
  • Usage: without a gateway, usage is reconstructed from provider invoices. With one, every request is metered per tenant, feature and model.
  • Latency: without a gateway, latency is unknown until users complain. With one, time to first token (TTFT) and the error rate per provider sit on one dashboard.

Open-source and hosted examples include LiteLLM Proxy, Portkey, Kong AI Gateway, Envoy AI Gateway and Cloudflare AI Gateway. Many teams build a thin one in-house.

Interview questions

  • Design the fallback logic for a streaming chat endpoint that can use three providers. What exactly triggers a fallback?
  • Why do you need a stream watchdog when the SDK already has a timeout? How do you implement it?
  • How would you add caching to the gateway? When is a semantic cache safe?
  • How do you meter usage and enforce budgets per tenant without letting parallel requests overspend?
  • Some tenants bring their own provider keys. How do you keep their traffic isolated from the platform keys?
  • What would you put on the gateway dashboard, and which alerts would page someone?

Sign up free to read the full topic

More Agentic AI topics

Start free on Cariara · Coding problems · System design studio