LearnThatStack Ace your next interview
AI System Design · question
Question 6 of 54

What is an LLM gateway (or AI proxy), and what belongs in it?

beginner
← All AI System Design questions
Re-explain

An LLM gateway, or AI proxy, is one internal service that every app calls instead of calling model providers directly. It is a reverse proxy for model traffic, so cross-cutting concerns live in one place.

// app code: one endpoint, provider-shaped body, no provider keys
const res = await fetch('https://gateway.internal/v1/messages', {
  method: 'POST',
  headers: { 'x-tenant-id': tenantId, 'x-trace-id': traceId },
  body: JSON.stringify({ model: 'claude-sonnet-4-6', messages, stream: true })
});

The gateway owns:

  • provider keys and caller auth, so no key sits in app code
  • per-tenant rate limits and quotas
  • retries, timeouts and failover
  • trace IDs, token accounting and request logs, so usage is measured once

Prompt templates, retrieval and business logic stay in the app. So do conversation state and response rendering.

Keep it thin. It sits on the hot path of every request, so it must pass streamed chunks through untouched. It is also a single point of failure, so it needs health checks and a bypass path.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

The diagram below the answer is the concept . Jump to it ↓

Tailored explanation · switch back to · ·
What should the new diagram focus on?
Guided practice for AI System Design One question at a time. Answer out loud, get graded, see what you missed.
How well did you know this?
AI:

Saved in this browser - sign in to keep your review list.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Interview lens How interviewers actually use this question

Likely follow-ups

  • How does the gateway count tokens on a streamed response without slowing the stream? Forward each chunk as it arrives and read the usage data the provider sends in the stream. Never hold the response back to count it.
  • Your tenant limits are in tokens, but output length is unknown until the call ends. How do you enforce them? Reserve an estimate up front from input size and max output tokens, then settle with real usage. Keep counters in a shared store, not per instance.
  • A provider fails halfway through a streamed response. Can the gateway retry or fail over? Retry only before the first chunk reaches the client. After that, a retry splices two different outputs, so send an error and let the client restart.
  • The gateway itself goes down. What does the bypass path look like, and what do you lose while on it? Run several replicas first. The bypass is a minimal proxy or direct calls with a scoped key, and on it you lose central quotas, logs and cost tracking.
  • Would you add response caching to the gateway? What could go wrong? It sees all traffic, so it can. Scope cache keys by tenant and model, and keep semantic matching opt-in, since a near match can return the wrong answer.

What you can say

  1. An LLM gateway, or AI proxy, is one internal service that every app calls instead of calling model providers directly. It's a reverse proxy for model traffic.
  2. Apps hit that one endpoint with a tenant ID and a trace ID and never hold a provider key, so cross-cutting concerns live in one place.
  3. It owns caller auth and the provider keys, per-tenant rate limits and quotas, and retries, timeouts and failover.
  4. It also records trace IDs, token counts and request logs, so usage gets measured once instead of in every app.
  5. Prompt templates, retrieval and business logic stay in the app, and so do conversation state and how the response gets rendered.
  6. I'd keep it thin. It sits on the hot path and is a single point of failure, so it passes streamed chunks through untouched and needs health checks plus a bypass path.

Weak answers to avoid

  • Stuffs product logic into the gateway Putting prompt templates, retrieval or chat state in it couples every team to one service. Say it handles keys, limits, retries and logging, and the app keeps the rest.
  • Buffers streams to inspect or count them Holding chunks until the response ends ruins time-to-first-token for every app. Say the gateway forwards chunks as they arrive and reads token counts from usage data.
  • Ignores that it is a single point of failure Every model call now depends on one service. A strong answer names health checks, redundant instances and a bypass path so an outage doesn't take down every app.
  • Treats it as a place to hide API keys Hiding keys is one job. Name the others it centralizes, like per-tenant quotas, retries and failover, and token accounting, so you measure usage once.
Interview lens

Likely follow-ups, what you can say, and the weak answers to avoid.

Sign in free to open it Free account - the lens opens as soon as you're back.

Want a quick review of the fundamentals? See the AI System Design cheatsheet.

← Back to all AI System Design questions
Pro · $10/mo

47 of 54 AI System Design answers are in Pro.

Full answers, code samples, and AI explanations that go simpler or deeper. Cancel anytime.

  • Full answers + code
  • AI explanations, simpler or deeper
  • 1,000 AI credits / month
  • Cancel anytime