Somewhere around the third AI feature, a platform team notices the same thing. The support bot calls one provider, the search team calls another, and somebody’s agent prototype calls both, each with its own API key in its own environment file. Nobody can say what last month cost per team. When a provider has a bad afternoon, three products find out separately.
That’s the moment the words model gateway show up in a design doc. A week later comes the question that matters more than the architecture: do we build it or buy it?
Here’s how I think about that call: what a gateway actually has to do, the shapes the market sells it in, and the signals that tell you which side of the line you’re on.
What a model gateway actually does
A model gateway is a reverse proxy between your applications and every model they call. Apps talk to one endpoint with one credential. The gateway decides which model serves the request, holds the real provider keys, and writes down what happened. Strip away the marketing and the job description is short. The must-haves:
- One API across providers. Apps code against a single request shape (in practice, usually the OpenAI-style chat format) and the gateway translates.
- Keys in one place. Teams get gateway keys, often called virtual keys, scoped to a budget and a set of models. The real provider keys never leave the gateway.
- Routing and fallback. Send a request to the cheap model by default, to the strong model when asked, and to a second provider when the first one times out.
- Limits measured in tokens. Requests per minute is the wrong unit for LLM traffic, because one request can cost a thousand times another. Quotas need to count tokens in and out.
- Cost you can attribute. Every request is tagged with team, app and feature, so the bill splits itself.
- Logs and traces. Model, version, latency, time to first token, tokens, cost and outcome, under a trace ID your apps already use.
Then the nice-to-haves, which is where vendors compete:
- Caching: exact-match for repeated prompts, semantic for “close enough” ones. More on why that second one is dangerous later.
- Guardrails: PII redaction on the way in, moderation on the way out.
- Shadow and canary traffic: mirror a slice of real requests to a candidate model before you switch.
The list is short. The hard part is that every item sits on the hot path of every AI feature you have, which is why the build-or-buy decision deserves more than a hunch.
The shapes it comes in
Gateways don’t differ much in what they do. They differ in where they run, who operates them, and which world they grew out of. Five shapes cover nearly everything:
- An open-source proxy you host. A service like LiteLLM or Envoy AI Gateway that you deploy next to your apps. You get a wide provider list and a familiar OpenAI-shaped API on day one, and prompts never leave your network. You also get a new critical service to run.
- A managed gateway. A hosted control plane such as Portkey or Cloudflare AI Gateway, or an aggregator like OpenRouter that also resells the models under one bill. Fastest to start and strongest on dashboards. The trade is that your prompts take an extra hop through someone else’s infrastructure.
- AI features on the API gateway you already run. Kong, Azure API Management and Apigee add LLM-aware policies, such as token limits, semantic caching and prompt guards, to a gateway your platform team already operates. Compelling if that gateway is already your front door; heavy if it isn’t.
- Your cloud’s multi-model API. Amazon Bedrock and Google’s Vertex AI put many model families behind one API, one permission model and one bill. That’s a gateway in all but name, as long as every model you want is in that catalogue.
- A thin layer you build. A small service, or even a shared client library, that owns keys, routing, limits and logging for exactly the providers you use.
None of these is wrong. Each is built for a different set of constraints, which is easiest to see side by side.
Side by side
| Open-source proxy | Managed gateway | API-gateway add-on | Cloud multi-model API | Build your own | |
|---|---|---|---|---|---|
| Time to first request | A day | An hour | Days, if you already run it | Hours | Weeks |
| Provider coverage | Very wide | Wide | The main providers | That cloud’s catalogue | What you write |
| Provider-specific features | Usually, with a lag | Usually, with a lag | Varies by plugin | Good, for its models | Whatever you expose |
| Where prompts go | Your network | Their network | Your network, if self-hosted | Your cloud account | Your network |
| Who runs the new failure point | You | They do | Your existing gateway team | The cloud provider | You |
| Ops burden | Medium | Low | Low to medium | Low | High, and permanent |
| Cost model | Infra plus your time | Usage or seats | Your gateway licence | Model usage only | Your team’s time |
| Lock-in | Low | Medium | Medium to high | High | Low, but you own it all |
A few cells deserve a footnote.
“Provider-specific features” is the row that bites. A gateway earns its keep by flattening providers into one API, and flattening loses detail. Prompt caching, reasoning controls, structured-output modes, new tool types: each provider ships these on its own schedule, and the gateway has to learn each one before your apps can use it. Check how a candidate handles the features you rely on today, then check how long it took to support the last one a provider shipped.
“Where prompts go” is a compliance question, not a performance one. If prompts carry customer data, a managed gateway is one more processor on your data map, with its own retention and logging defaults. Sometimes that’s fine. Find out before procurement does.
Every option adds a failure point. The only question is who is on call for it. More on that below.
When building wins
Building has a bad reputation because people build the wrong thing: a full-featured gateway that re-implements what every product above already does. Building makes sense when what you need isn’t for sale:
- Routing on business signals. Choosing a model from the customer’s plan, the ticket’s severity or a per-tenant contract is product logic. No vendor knows your tenants.
- A tenancy or auth model of your own. If identity, budgets and audit already live in your platform, a gateway that wants its own users and keys becomes a second source of truth.
- One or two providers, and a strict data path. With a short provider list, translation is a small problem, and owning the whole path keeps the compliance story simple.
To be honest about the cost: the first version is cheap and the next ten are not. The bill arrives as maintenance:
- Provider APIs change, and every change is yours to absorb.
- Streaming is where the edge cases live: partial chunks, errors halfway through a response, clients that disconnect, usage numbers that only arrive in the last event.
- Token counts for limits and cost have to match the provider’s count, model by model.
- Every new provider feature is a ticket on your backlog before any app can use it.
If you build, build it thin: keys, routing, limits, logs. For anything past that, check whether an open-source proxy already does it before you write it.
When buying wins
Buying wins on the opposite signals:
- Many providers or many apps. Translation and coverage are exactly the work vendors spread across all their customers.
- A small platform team. If two engineers own all of internal infrastructure, a hosted control plane or your cloud’s multi-model API buys back their time.
- You need cost visibility this quarter. Dashboards, budgets and alerts come standard in the products above and take weeks to build in yours.
- You’re still finding out what you need. Three months on a real gateway is the cheapest requirements document you’ll get, and it makes a later decision to build far better informed.
The hybrid most teams land on: rent the plumbing, own the seam
In practice the answer is rarely pure. The pattern I keep recommending is to buy or adopt the gateway and put a thin client library of your own in front of it.
The client library is small on purpose. It gives apps your names for models, like fast, strong or batch, instead of vendor model IDs. It attaches the team and feature tags that make cost attribution work. It sets your timeout and retry defaults in one place. And it’s the only code that knows the gateway’s address.
// apps never see a provider name or a vendor model ID
const reply = await llm.chat({
model: 'strong', // your alias; the gateway maps it to a real model
feature: 'ticket-summary', // cost attribution and traces
messages,
});
That seam turns the gateway choice from a one-way door into a two-way door. If the vendor’s pricing changes, or you outgrow it, or you finally do need to build, you change one library and one config file, not every app. (I’ve written more about telling those two kinds of decision apart in Designing for change.)
The escape hatch matters too. When a provider ships a feature your gateway doesn’t support yet, the client library can call that provider directly for that one feature, on purpose and where everyone can see it. That beats every team inventing its own workaround.
Pitfalls, whichever way you go
- The lowest-common-denominator trap. A unified API is only as good as what it can express. If teams quietly start going around the gateway to reach a feature, it has stopped being your gateway.
- The gateway is now critical infrastructure. Every AI feature depends on it, so run it like your auth service: several instances, health checks, and a decision made in advance about what happens when it’s down. Either fail closed, or fall back to direct calls with tighter limits.
- Retries stacked on retries. If the client retries three times and the gateway retries three times, one bad minute at a provider becomes nine attempts per request. Retry in exactly one layer. (The rest of the retry envelope is in Designing agentic systems that don’t fall over in production.)
- Semantic caching that answers the wrong question. “Cancel my order” and “don’t cancel my order” sit close together in embedding space. Semantic caching is only safe where a near-miss answer is harmless. Everywhere else, cache exact matches or nothing.
- Logs are a data store. A gateway that logs every prompt has quietly become the biggest store of customer text in your company. Decide on redaction and retention before you turn logging on, not after.
- Switching models is a release, not a config change. The gateway makes swapping a model a one-line change, which is exactly why that change needs a gate. Replay your eval set and shadow real traffic first. (More on that in Evaluating LLM features without fooling yourself.)
A decision you can make in an afternoon
Before you sign a contract or start building, check:
- You’ve listed the providers and models you’ll realistically use over the next year, not just today.
- You know which provider-specific features your apps depend on, and whether each candidate supports them.
- You know where prompts are allowed to go, and who’s allowed to log them.
- Retries happen in exactly one place, and you’ve written down what happens when the gateway is down.
- Apps talk to your client library, not to the gateway directly.
A gateway is plumbing, and good plumbing is the kind nobody thinks about. Pick the one that lets you forget it, and keep the seam that lets you change your mind.