Ask a platform team how many provider API keys their company has, and the honest answer is usually a range. Ask where they are, and the answer becomes a list of places to search: repository secrets, CI variables, a password manager, three .env files, a notebook on someone's laptop, and the personal account a developer used for the first prototype eighteen months ago.
Provider keys multiply because copying one is faster than asking for one. No policy fixes that on its own. What fixes it is an access model where the governed path is also the fastest one. This article describes that model, what each part of it buys you, and how to move to it without a freeze on every AI project in the company.
What the sprawl actually costs
Key sprawl is usually discussed as a security problem. It is one, but it is also a cost problem, an offboarding problem and an audit problem, and each of those has a different owner.
| Symptom | Who feels it | What it looks like in practice |
|---|---|---|
| No inventory | Security, audit | "Which systems can call OpenAI?" takes a week and the answer is still incomplete. |
| Shared keys | Finance | One key, five products, one invoice line. Cost attribution is a negotiation. |
| Leaked key | Security | Revoking it breaks every system that shared it, so it stays active "until we migrate". |
| Offboarding | IT, security | The person who left had a key in a personal project. Nobody knows if it is still used. |
| Provider change | Engineering | Each integration holds its own key and its own client, so switching provider is N migrations. |
The common root is that a provider key is a bearer credential to a paid, data-processing service, distributed with no owner and no scope. Anyone who holds it can spend money and send data, and the provider cannot tell your teams apart.
The model: two kinds of credential, never mixed
The fix is to separate two credentials that today are the same string.
Provider credentials authenticate your company to the model provider. There should be very few of them, ideally one per provider and environment, held in exactly one place and never handed to an application.
Gateway keys authenticate an application to your gateway. There can be many of them, and each one is bound to exactly one project.
Applications never see a provider credential. They call the gateway with a gateway key; the gateway checks that key, applies the project's policies, and forwards the call to the provider with the provider credential it holds. Every credential header the client sent (Authorization, x-api-key, x-goog-api-key, api-key, cookies) is stripped before the request leaves, so a gateway key can never reach a provider and a client cannot smuggle its own provider key through.
That separation is what makes everything below possible.
Provider credentials: held once, shown never
In Axium, provider credentials are encrypted at rest with AES-256-GCM under a master key that lives in the environment, not the database. The API never returns them: after creation, the console shows only the last four characters, which is enough to identify which key is configured without exposing it.
Better still is not to have a provider secret at all. On Azure AI Foundry the gateway can authenticate with the managed identity of the machine it runs on, and on Google Vertex AI it can use the workload's service account through the metadata server. In both cases there is no provider key to leak, rotate or inventory, because access is granted to the gateway's identity in the cloud's own IAM.
The practical consequence: rotating a provider key happens once, in one place, and no application is redeployed. That is the difference between a rotation policy that is followed and one that is written down.
Gateway keys: one owner, one scope
A gateway key in Axium looks like ax_ followed by 40 hexadecimal characters, generated from 20 random bytes. Four properties matter more than the format:
- It is shown once. The plaintext is returned at creation and never again. The server stores only a hash of it and its last four characters, so a database dump does not contain usable keys, and nobody, including administrators, can "look up" a lost key. The only way to replace one is to issue a new one.
- It belongs to exactly one project. A database constraint enforces that each key has a single scope. At runtime, the project in the request URL must match the key's project, or the call is refused with a 403. A key for the claims assistant cannot be used to call through the search project, even by mistake.
- It can only reach what the project is allowed to reach. A project has a list of allowed models. A request for anything else is refused before it reaches a provider, with a
model_not_allowederror. This is where "which systems can use which models" stops being a spreadsheet and becomes an enforced fact. - It can expire, and it can be switched off. An expiry date is optional; deactivation is immediate. Unknown, deactivated and expired keys all receive the same 401, so the response does not tell an attacker which of the three they found.
Note what the scope is not. It is not "one key per project" in the sense of a single shared key per project. A project can have as many keys as it needs: one per environment, one per service, one per CI pipeline. What matters is the direction of the relationship: every key has exactly one project, so every call has exactly one owner. Cost, policy and audit all follow from that.
Making the governed path the fastest path
None of this works if getting a gateway key is slower than copying a provider key. Three design choices keep it fast.
Callers keep their SDK. The gateway exposes the providers' own APIs: the OpenAI Chat Completions and Responses endpoints, the Anthropic Messages API, Gemini's generateContent, Azure OpenAI and Vertex AI. Moving an application to the gateway is a change of base URL and key, not a rewrite. The gateway accepts the key in the header the SDK already sends (Authorization: Bearer for most, x-goog-api-key for Gemini).
# Before: a provider key in the application's environment
client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])
# After: a gateway key scoped to one project
client = OpenAI(
api_key=os.environ["AXIUM_KEY"], # ax_…, valid only for this project
base_url="https://ai-gateway.internal/proxy-apps/<proxy-app-id>/openai/v1",
)
Projects are cheap. Creating a project, choosing its models and issuing a key should take minutes and should not require a ticket to the provider's account owner. If it takes a week, people will find a provider key instead, and they will be right to.
The owner can serve themselves. Revoking a key, issuing a second one for a new environment, or checking when a key was last used are things the project owner should be able to do without the platform team. The gateway records the last-used time of every key, which is the single most useful field for cleaning up an inventory.
Rotation without downtime
Rotating a gateway key does not need a special endpoint; it needs two keys to be valid at the same time for a short window.
- Issue a new key for the same project.
- Deploy it to the application.
- Watch the old key's last-used timestamp stop moving.
- Deactivate the old key. Delete it once you are sure.
Because both keys belong to the same project, budget and policy are unaffected, and the traces of the two overlap cleanly. If step 3 never happens, because the old key is still being used somewhere, you have just found an undocumented consumer, which is the second most useful thing an inventory can tell you.
The inventory that keeps itself
With this model the inventory is not a document someone maintains. It is a query. For every key:
- Project it belongs to, and therefore its owner, budget and policies.
- Created and expires dates.
- Last used, updated on every call.
- Active or not.
- Suffix, the last four characters, to match it against wherever it is deployed.
For every provider credential:
- Which provider and environment it serves, which projects route through it, and whether it is a secret at all or a managed identity.
When an auditor asks "which systems can call a model provider, with which credentials, and who approved it?", that list is the answer. It is complete by construction, because a call that does not use a gateway key does not go through, and a call that does is attributed to a project.
Migrating from the sprawl you already have
You do not need a big-bang migration. The order that works:
- Find the existing keys. Secret scanning on your repositories and CI (GitHub's built-in scanning, gitleaks or similar) will find most of them. The provider console will list the keys that exist on its side.
- Stand up the gateway with one provider credential per provider, and onboard the most active project first. Visible early wins matter.
- Onboard the rest, one project at a time. Each migration is a base URL and a key. Projects that resist are usually the ones with the most interesting undocumented usage.
- Revoke the old provider keys at the provider. This is the step that is always postponed and the only one that actually ends the sprawl. Until it happens, the old path still works.
- Use the invoice as a detector. After revocation, compare the provider invoice with the gateway's cost ledger. Any spend on the invoice that the gateway did not see is traffic using a key you have not found yet. (How to build that ledger.)
When a key leaks anyway
It will. The difference this model makes is in what happens next.
- Blast radius: one project, its allowed models, until its budget is exhausted. Not your whole provider account.
- Revocation: deactivate that key. Every other key, including the other keys of the same project, keeps working.
- Investigation: every call made with the key is in the trace log, with time, client IP, country, model and cost. You can answer "what did the attacker do with it" instead of guessing.
- The provider credential is untouched, because the leaked key was never a provider credential.
Compare that with a leaked provider key shared by five systems: revoke it and break five systems, or leave it active and hope.
Summary
- Separate provider credentials (few, central, never shown) from gateway keys (many, one project each).
- Prefer managed identities to stored provider secrets where the cloud supports them.
- Show keys once, store only a hash, and allow expiry and immediate deactivation.
- Bind each key to one project, and each project to an explicit list of models.
- Make getting a key faster than copying one, or none of the above will be adopted.
- Finish the migration by revoking keys at the provider, and use the invoice to find the ones you missed.
The AI gateway overview puts this access model in the context of the other controls a gateway provides. If you want to walk through it on your own setup, book a demo.