skip to content

A provider API key behind your model gateway turns up in a public repository: how do you replace it without client changes, and stop it recurring?

level: seniorimportance: should knowfreq 45%

answer

  1. new key in before old key out
  2. clients hold gateway keys only
  3. a leaked upstream key is uncapped
  4. provider usage versus gateway records
  5. who may create provider keys

basics

~20 s

Mint a new provider key, load it into every gateway replica, confirm traffic succeeds on it, then revoke the leaked one; clients hold only gateway keys, so none changes. Then close the bypass that let a copy exist outside the gateway.

solid answer

~50 s

Every client authenticates with a gateway key, so the provider key is an upstream secret only the gateway uses, and replacing it is a gateway-side change: create a new key at the provider, roll it into every gateway replica, check that calls succeed on it, then revoke the leaked one. For a leak the window with both keys valid is minutes, not the longer overlap a routine rotation might allow. Next, compare the provider's usage for the leaked key with the gateway's own records: anything the gateway did not send is someone else's spend, and it was never under any team cap. Finally, ask how a copy reached a repository at all. Someone held the key outside the gateway, so restrict who may create provider keys, stop application networks calling providers directly, and reconcile provider invoices against gateway-metered spend to catch the next bypass.

go deeper

for a junior

Recall that clients present gateway keys, so replacing the provider key behind the gateway needs no client change.

for a middle

Explain the order: mint the new key, load it into every replica, verify traffic on it, then revoke the leaked one.

for a senior

Show that you compare the leaked key's provider-side usage with the gateway's records, because that outside spend was never under any cap.

for a principal

Treat the leak as evidence of bypass and argue for the controls (key-creation rights, egress rules, invoice reconciliation) that make the gateway the only holder.

## Why the swap needs no client change A **provider key** is the credential a model provider bills against. Behind a shared **model gateway** only the gateway should hold it; teams get their own **gateway keys** instead. Clients authenticate to the gateway with those, and the gateway authenticates to the provider with the provider key. The two are independent, so replacing the provider key is a change inside the gateway's upstream configuration, and no client redeploys. The scenario here: a provider key turns up pasted in a public repository. That one fact says two things: the key must be replaced quickly, and somebody held a copy outside the gateway. ## The swap, step by step 1. **Mint a replacement** at the provider, in the same account or project and with the same permissions. Check its quota too: on many providers throughput limits attach to the account, project or tier, and a key created elsewhere may not carry the old key's limits. 2. **Load it into the gateway's upstream credentials** and roll it to every gateway replica. A replica still holding the old value starts failing the moment the old key dies. 3. **Verify** that calls succeed on the new key, from per-key success rates or a canary request through each replica. 4. **Revoke the leaked key** at the provider. 5. **Watch authentication errors** for a few minutes; a burst means some path (a replica, a forgotten job) still held the old value. For a leak, the period with both keys valid is minutes: one rollout. A routine rotation may keep a longer overlap while many consumers move; sizing that window, and where the secret itself is stored, are covered with credential rotation. If the gateway spreads load over several provider keys, only the leaked one is swapped and the others carry traffic meanwhile. ## What did the leaked key spend? Spend made with a provider key outside the gateway never passed admission, so it counted against **no team cap** and appears in **no gateway log**. To size it: - pull the provider's usage for that key, or its project, over the exposure period; - subtract what the gateway itself sent through that key; - treat the difference as outside spend, someone else's calls on your account, and raise it with the provider if it looks fraudulent. ## The leak is a symptom: close the bypass A provider key in a repository means a person or service held it directly, so some traffic may be escaping every cap and every log. Making the gateway the **only holder** takes several controls, because each covers a different gap: | Control | What it stops | Its limit | |---|---|---| | Only the platform team may create provider keys | Teams minting their own direct keys | Depends on the provider's role model | | A provider account or project reserved for the gateway | The gateway's upstream keys being reused elsewhere | Needs discipline as new providers arrive | | Egress rules letting only the gateway reach provider endpoints | Services calling providers directly | Laptops and outside build machines escape it | | Reconciling provider invoices against gateway-metered spend | Bypass going unnoticed | Finds it after the money is spent | | Secret scanning on repositories | Keys pasted into code | Detection only, after the fact | No single row is enough. Egress rules stop services inside the network but not a developer's laptop; reconciliation catches what slipped past, but only later. Together they make bypass both hard and visible. ## Clean-up that is easy to skip - **Deleting the key from the latest commit does not end the exposure**: it remains in history and in every clone and fork, so revocation is the real fix. - **Find who held the copy and why.** Often a team needed something the gateway did not offer, such as a new model or a feature the shared request shape lacks, and went around it. Meeting that need prevents the next copy. ## Contrast: a leaked gateway key Had the leaked value been a team's **gateway key**, the stakes would be lower. It works only through the gateway, so it is bounded by its own cap and model allowlist and shows up in the gateway's logs. Disable it and issue the team a new one; that team does change its configuration, and nobody else is touched. That asymmetry is the main argument for never handing provider keys to teams in the first place.

  • Why revoke the leaked key within minutes instead of keeping the usual rotation overlap?
    A routine rotation keeps both values valid while many consumers move across. Here the only legitimate consumer is the gateway, and it can move in one rollout. Every extra minute the leaked key stays valid is uncapped spend for whoever copied it, so the overlap only needs to last until every replica has loaded the new key and calls on it are succeeding.
  • How would you spot traffic bypassing the gateway before a key ever leaks?
    Reconcile the provider's per-key or per-project usage against what the gateway sent over the same period; spend the gateway never saw came from somewhere else. Pair that with egress rules that let only the gateway reach provider endpoints, and flag any provider key the platform team did not create.

  • Every client must update its configuration once the provider key changes.
  • Spend run up on a leaked provider key still counts against some team's cap.
  • Keep both keys valid for a week, as for any routine rotation.
  • Deleting the key from the repository's latest commit ends the exposure.
  • If the gateway holds the provider keys, no copy can exist anywhere else.