Behind a shared model gateway, why should no team hold the provider's API key, and what does a per-team gateway key buy?
answer
- who can be cut off alone
- attribution per caller
- one upstream secret, many downstream keys
- revoke a team without touching the provider
- a cap needs a single choke point
basics
~20 sA provider key that teams hold directly cannot be capped, attributed or revoked per team. Giving each team its own gateway key keeps the real key in one place and lets the gateway scope, cap, trace and revoke each caller separately.
solid answer
~50 sIf every team pastes the same provider key into its config, the provider sees one caller: you cannot tell whose code spent the money, you cannot stop one team without stopping all of them, and rotating that key means a coordinated change in every repository that holds it. A shared gateway inverts this. It holds the provider keys itself and issues each team (or service, or environment) its own **gateway key**. Every call then arrives with an identity the gateway owns, so it can attach a spend cap, a model allowlist and logs to that key, revoke one team without touching anyone else, and swap the upstream key without any client noticing. The trade is that the gateway becomes the one holder of the real credential, so it sits in the path of every call and has to stay available.
go deeper
Recall the three things a per-team key gives that a shared provider key cannot: attribution, a per-team cap and revoking one caller alone.
Explain the many-to-few mapping: the gateway authenticates its own key, applies that key's policy, then calls the provider with a key only it holds.
Show you know the scheme holds only if the gateway is the sole path to providers, and that a leaked gateway key is bounded by its cap and allowlist.
Discuss how finely to slice keys (team, service, environment, single run) and what centralising custody costs in availability and secret-handling discipline.
## The problem with a shared provider key A **provider key** is the credential a model provider issues to an account: whoever presents it is billed to that account and can call any model the account can reach. When a company starts using hosted models, the quickest path is for each team to ask for a key, or for one key to be copied into several services' configuration. That works until somebody asks one of these questions: - **Whose code spent this?** The provider's usage view shows spend per key, and perhaps per project if the provider offers projects, but once a key is shared it cannot say which team inside your company made the calls. - **Can we stop just one team?** Revoking a shared key stops every service that holds it. - **Can we rotate it?** Every copy has to change at once, in repositories and deploy configs nobody has a complete list of. - **Can we cap it?** Some providers offer account- or project-level spend limits, but their granularity and enforcement vary, and none of them knows your org chart. ## What a per-team gateway key is A **model gateway** is one internal endpoint that every application calls instead of calling providers directly. It holds the real provider keys and issues its own credentials, **gateway keys**, to callers. A gateway key means nothing to the provider; it is an identity only the gateway recognises. When a request arrives, the gateway: 1. authenticates the gateway key and looks up the team, service or environment it belongs to; 2. applies that key's policy: which models it may use and how much it may still spend; 3. forwards the call to the provider with a provider key only the gateway holds; 4. records the usage against the gateway key. The mapping is many-to-few: dozens or hundreds of gateway keys in front of a handful of provider keys. ## What the indirection buys | Concern | Provider key copied into each team | Per-team gateway key | |---|---|---| | Attribution | One caller as far as the provider knows | Every call tagged with the team's key | | Spend cap | Account- or project-wide at best | Per key, per team, per organisation | | Revoking one caller | Breaks everyone sharing the key | Disable one gateway key | | Leak blast radius | Uncapped spend on the whole account | Bounded by that key's cap and models | | Rotating the upstream credential | Change every holder | Change it once, inside the gateway | | Model access | Anything the account can call | An allowlist per key | Two rows deserve emphasis. A leaked gateway key is **bounded**: it can only spend up to its cap, only on its allowed models, it shows up in the gateway's logs, and it can be disabled without touching anyone else. And because clients never see the provider key, the platform team can replace it (after a leak, an account change or a routine rotation) without a single client deploy. ## How finely to slice keys What a key represents is a design choice; finer slices give finer control at the cost of more keys to issue and track: - **Per team**: the usual starting point, matching each budget to whoever owns the spend. - **Per service or feature**: one runaway service can be stopped while the team's other features keep working. - **Per environment**: a development key's experiments cannot eat production's budget, and dev keys can carry tighter caps. - **Per run or per job**: short-lived keys minted for one batch job or one agent run, each with a small cap, so a single loop cannot drain a whole team's budget. Most organisations end up with a hierarchy: an organisation budget, team budgets beneath it and keys beneath each team, each level with its own limit. ## What it costs Centralising key custody makes the gateway the only path to the provider, so its availability and per-call overhead now matter to every AI feature; that is a question about the gateway in the request path rather than about keys. The scheme also works only if the gateway really is the only path: a team that still holds a provider key directly escapes every cap and every log, so making the gateway the sole holder takes organisational controls (who may create provider keys, whether application networks can reach providers directly) as well as technical ones. Finally, the gateway's own store of provider keys becomes a high-value target, and how those keys are stored and rotated deserves the care given to any production secret.
- If a gateway key leaks, why is that less serious than a leaked provider key?A gateway key works only through the gateway, so it inherits that key's cap, model allowlist and logging: the worst case is its remaining budget on its allowed models, and disabling it affects nobody else. A leaked provider key is billed straight to the account with no internal cap, bypasses your logs, and revoking it breaks every legitimate caller unless the gateway swaps in a replacement first.
- Should a team's development and production traffic share one gateway key?Usually not. Separate keys per environment let a development key carry a small hard cap and a narrower model list, stop experiments from consuming production's budget, and let you revoke a leaked development key without touching production traffic. Attribution improves too: the spend figures say which environment spent the money.
- Teams can share one provider key safely as long as it sits in a secret store.
- One shared provider key is fine because the provider's invoice shows each team's spend.
- A gateway key is just the provider key passed through under another name.
- Rotating the provider key means every team must redeploy with the new value.
- Per-team keys only matter for billing, not for capping or revoking a caller.