An API key for an AI model is a line of text. Whoever holds it can use the model as you, at your expense, from anywhere, until someone deletes it. There is no username, no second factor and usually no expiry date.
Companies are creating these keys faster than they can keep track of them, and the keys are leaking at the same pace. This article is for the people who approve budgets and policy, not the people who write the code. It makes one recommendation: stop issuing long-lived AI keys to software, and give each piece of software an identity of its own. The technical names are service accounts and workload identity federation. Every major AI provider now supports them.
How often it happens
GitGuardian scans public commits on GitHub for credentials. Its report on 2025 counted 28.65 million new ones, 34% more than the year before. Credentials for AI services grew much faster: 1,275,105 of them, up 81%.
Three more findings explain why this is not a training problem.
Expertise does not prevent it. In November 2025, Wiz examined 50 leading AI companies and found that 65% had leaked verified, working secrets on GitHub.
Leaked keys stay alive. GitGuardian retested credentials it had confirmed as valid in 2022. In January 2026, more than 64% of them still worked.
Code is not the only route. About 28% of the incidents GitGuardian tracked began entirely outside source code, in tools such as Slack, Jira and Confluence.
AI coding assistants add to the total. GitGuardian measured public commits made with one widely used assistant, Claude Code, and found a leak rate of 3.2%, against 1.5% across all public commits.
What one key costs
US$82,314 in 48 hours. In February 2026 a three-person startup in Mexico found that charge on its Google Cloud account, run up on Gemini models over two days. Its normal spend was about US$180 a month. The developer did not know how the key got out. According to The Register, a Google representative cited the shared responsibility model, and the developer wrote that paying even a third of the amount would bankrupt the company.
About US$600,000 over three weeks. METR, an AI evaluation organisation, disclosed that in March 2026 a key for its model account was sitting inside an app on a researcher’s personal server. A flaw left the app open to the internet. The attacker asked the AI agent running there to reveal its key, and it did. The credits had been granted to METR free of charge, so the figure is their retail value. METR’s own review noted that the key had no spending ceiling.
Keys you gave to someone else. In May 2026 the AI firm Braintrust told customers to replace the AI provider keys they had stored with it, after one of its AWS accounts was breached. One customer was confirmed affected. Three more reported unusual spikes in AI usage.
Keys nobody thought were secret. Truffle Security found 2,863 working Google API keys on public web pages that could reach Gemini. Keys of this kind are routinely placed in web pages for services such as maps. When Gemini was switched on in the same project, the old keys gained access to it.
We have seen the same pattern from the cloud side. A client’s leaked AWS key was used at 11 at night to run AI models on their account.
Why “be careful” is not a control
The cause is not carelessness. A key is designed to be copied. To be used, it has to sit somewhere: a developer’s laptop, a configuration file, a build system, a supplier’s dashboard, a message to a colleague who needed it quickly. Each copy is a place to leak from, and nobody has the full list.
Three properties make every leak expensive.
- It does not expire. A key leaked two years ago is as useful as one leaked this morning.
- It does not say who is using it. The provider sees the key, not the person or program behind it. Five systems sharing one key look like one customer.
- Replacing it is manual. Rotation means finding every copy first, so it gets postponed.
Staff training, secret scanners and rotation schedules all help. All of them also accept that the key exists. And there is a newer route they do not cover, shown in the METR case: an AI agent that can read its own configuration can be talked into reading it out.
The alternative: an identity, not a secret
Two ideas do the work.
A service account is a named, non-human identity for one piece of software, for example “invoice-reader-production”. It has its own permissions and its own line in the usage report. It does not belong to an employee, so nothing breaks when someone leaves, and it is not shared between systems.
Workload identity federation is how that software proves it is the service account without holding a password. Software already has an identity in the place where it runs. AWS, Google Cloud, Azure, a Kubernetes cluster and GitHub’s build service each know exactly which workload they are running, and each can issue that workload a signed statement saying so, valid for a few minutes. You tell the AI provider which statements to trust: “this repository, on this branch”, or “this role in our production account”. The provider checks the signature and returns an access token that expires, typically within the hour. When it runs out, the software repeats the exchange on its own.
Think of a master key against a staff pass. Copies of the master key work for anyone, for ever. The pass is issued to one named holder, checked at the door, and stops working at the end of the shift.
| Long-lived API key | Federated service account | |
|---|---|---|
| What there is to steal | A string that works from anywhere, indefinitely | A token that expires in minutes to an hour |
| Where it is stored | Laptops, files, build settings, suppliers | Nowhere. It is issued when the software runs |
| What the usage report shows | A key | A named system |
| Replacement | Manual, usually overdue | Automatic, all the time |
| When an engineer leaves | Every key they saw is suspect | Nothing they saw is still valid |
One caution about the term “service account”
A service account is only an improvement when nothing permanent is attached to it. Google Cloud will let you download a service account’s key as a file. The model providers will issue an ordinary API key to a service account if asked. Either one is the original problem under a tidier name.
So the instruction to your team has two parts: service accounts, and no stored keys.
It is available today
The cloud platforms have worked this way for years. The model providers’ own APIs now do as well.
| Where you call the model | The keyless route | Worth knowing |
|---|---|---|
| Anthropic (Claude API) | Workload identity federation to a service account | Token lifetime is set per rule, from one minute to one day. The setup wizard defaults to ten minutes |
| OpenAI API | Workload identity federation to a project service account | Setup guides cover AWS, Azure, Google Cloud, Kubernetes and GitHub Actions |
| Amazon Bedrock | An IAM role attached to the workload | AWS also offers Bedrock API keys. Its own documentation says: “Long-term keys are for exploration only” |
| Google Gemini on Vertex AI | An attached service account, or federation from outside Google Cloud | Google’s guidance: “We recommend using an API key for testing and using application default credentials for production” |
| Microsoft Foundry on Azure | Managed identities through Microsoft Entra ID | Key access can be switched off altogether and enforced by policy |
It is not exotic. This website is deployed that way. On each deployment, GitHub proves its identity to AWS and receives credentials for that one job. There is no AWS key stored in GitHub to steal.
What it does not solve
People still need access. Federation is for software. Engineers who are experimenting should work in a separate sandbox project, apart from production, with a low spending limit and keys that expire.
Some software cannot do it. A packaged tool or an outside service may only accept a pasted key. Treat each one as a written exception: the narrowest key the provider allows, a spending limit, a named owner and a review date. The Braintrust case is the reason.
Trust moves. It does not vanish. Anthropic’s documentation is direct about this: “Federated authentication is only as strong as the upstream identity provider.” The rules also have to be narrow. Trust one repository and one branch, not everything in your GitHub organisation.
A running system can still overspend. If the application itself is compromised, or has a bug that loops, it spends with a perfectly valid token. Spending limits and alerts still matter.
A leftover key undoes the work. Anthropic warns that an old key left in a system’s settings silently takes precedence over federation. A migration is finished when the old key is deleted, not when the new method works.
What to ask for
Five instructions, none of which requires you to read a line of code.
- An inventory, this month. Every AI API key: who created it, what uses it, where it is stored and what it is able to spend. Expect surprises. They are the point.
- A rule for new work. No long-lived AI key in any production system. New services authenticate with a service account and federation from the first day.
- A date for existing systems. Each key in the inventory is either migrated and deleted, or recorded as an exception with an owner and a review date.
- One service account per system, per environment. Then the usage report can answer the question “what spent this?”
- A spending limit wherever the provider offers one, and an alert everywhere. Sent to a person who would see it at the weekend.
Then ask one question each quarter: how many long-lived AI keys do we have? The number should fall until the only ones left are on the exceptions list.
For the wider picture, read why stolen credentials now end up running AI models, five questions directors should ask about cyber risk, and the AWS baseline we run on every account.
Sources
- The State of Secrets Sprawl 2026 (GitGuardian)
- Exposure report: 65% of leading AI companies found with verified secret leaks (Wiz)
- Dev stunned by $82K Gemini bill after unknown API key thief goes to town (The Register)
- Security update, 31 August 2026 (METR)
- AI firm Braintrust prompts API key rotation after data breach (SecurityWeek)
- Google API keys weren’t secrets. But then Gemini changed the rules (Truffle Security)
- Workload Identity Federation (Claude Platform documentation)
- Workload identity federation (OpenAI API documentation)
- API keys (Amazon Bedrock User Guide)
- Configure application default credentials (Google Cloud, Vertex AI)
- Disable local authentication in Foundry Tools (Microsoft Learn)