An API key is a secret string of characters that identifies an application when it calls an API, so the service knows who is asking, what they're allowed to do and which account to bill. It works like a password for software, except that it's long, random, never meant to be typed by a person, and usually pasted into a settings file once and left there.

Whoever holds the key can use it. If it leaks, someone else can spend your allowance and act as you, within whatever the key is allowed to do.

What happens if an API key leaks?

The first risk is money. A leaked key for an AI model provider can run up a large bill within hours. A common route is a key accidentally committed to a public code repository, where automated scanners look for exactly that; GitHub runs secret scanning partly for this reason.

The second is data. A key that can read a system can read it for anyone who holds the key, so the scope of the key sets the scope of the damage.

An example

A developer runs a hobby agent on a VPS and pastes her model provider's key into a configuration file. Three months later she posts that file to a forum while asking for help with an error, key included. Within hours, usage on her account spikes.

Revoking the key and issuing a new one stops the spending, but the charges already made stay on the account. A monthly spend limit set in the provider's dashboard would have capped the loss at a figure she'd chosen in advance.

Should you ever give your key to another service?

Sometimes, yes. Plenty of legitimate products are built on a bring-your-own-key model: you paste in a key from your model provider, and usage is billed straight to your own account, where you can see it. That's reasonable when:

  • the service is designed for it and explains how it stores keys (encrypted, and never displayed again once saved),
  • you create a separate key just for that service, so you can revoke it without breaking anything else,
  • the key has the narrowest permissions the provider allows,
  • you've set a spend limit or budget alert with the provider.

Be wary of anyone who asks for a key casually by chat or email, or who wants your main key rather than one made for them.

How is an API key different from a password?

A password identifies a person, who remembers it and resets it when needed, whereas a key identifies a program and is copied, rotated and revoked. Give each program or service its own key and replace keys periodically, so a single leak doesn't expose everything.

Common questions

Does a hosted agent service need my API key?

It depends on how the service is billed. Some include model usage in their price and use their own keys, while others are bring-your-own-key, so you pay the model provider directly. Both are legitimate, and it's worth knowing which kind you're signing up for.

How do I know if a key has leaked?

Often not until the bill arrives. Turn on usage alerts and spend limits where your provider offers them, and glance at the usage page now and then for activity at hours when you weren't working.

Can I limit what a key can do?

Often, through scopes, project budgets, IP address restrictions or a list of allowed models, depending on the provider. These sit alongside other guardrails: a leaked key that can only call one model up to a fixed monthly budget is a small, contained problem.