Back to Automation

What Are API Keys and How Do You Keep Them Safe?

What Are API Keys and How Do You Keep Them Safe?
AI Tutorials Team 29 January 2026

An API key identifies your account and authorises charges against it. Anybody who has it can use your account, which makes it a password with a bill attached.

How do keys get exposed?

  • Committed to a repository. The most common route.
  • Embedded in client-side code. Visible to anybody.
  • Pasted into a chat. To ask why something failed.
  • Left in a screenshot. Or a shared document.
  • In a public log. Or an error message.

Why is client-side the worst?

Because a key in a web page or a mobile application is extractable by anybody who wants it, regardless of obfuscation. Calls from a browser must go through your own server, which holds the key.

Where should a key live?

In an environment variable or a secrets manager, never in code. That separation is standard practice and it is what prevents the accidental commit that exposes most keys.

What about repositories?

Add the file holding your secrets to the ignore list before your first commit rather than afterwards. A key committed and then removed is still in the history and must be treated as compromised.

What happens when one leaks?

Automated scanners find exposed keys within minutes and they get used. The bill arrives quickly, and the first sign is usually unexpected usage rather than any warning.

What about keys in a team?

Worth arranging properly rather than informally. A key passed around in messages ends up in several places, cannot be attributed to anybody, and has to be rotated whenever somebody leaves.

Separate keys per person and per environment make usage traceable and departures straightforward. Most providers support organisational accounts with per-member keys, which is the arrangement to use rather than sharing one.

What should you do immediately?

Revoke the key rather than deleting the file. The exposed value is what matters, and anything short of revoking leaves it working.

What about keys in client applications?

Worth restating because it keeps happening. A key in a mobile application or a browser is extractable, and obfuscation delays rather than prevents it.

The only correct arrangement is a server of your own between the client and the provider. That server holds the key, applies your limits and can refuse requests, which is also where per-user controls belong.

What limits should you set?

A spending cap and usage alerts, which every major provider offers. Those are the difference between an unpleasant surprise and an expensive one.

Why use separate keys?

Because you can revoke one without breaking everything else. A key per project, or per environment, means an exposure is contained rather than requiring you to rotate everything at once.

What about keys that have leaked already?

Assume any key that has been in a repository, a screenshot or a message is compromised, regardless of whether anything suspicious has appeared. Scanners find these quickly and usage can start at any point.

Revoking is immediate and costs only the work of updating wherever the key was used. That is a small inconvenience against an unbounded bill, and hesitating because nothing has happened yet is how people end up with an expensive month.

What about keys in automation platforms?

A case people forget. Pasting a key into a no-code platform stores it there, which is reasonable and means the platform's security is now part of yours.

Using a separate key for each platform is the sensible arrangement. If that service is compromised or you stop using it, revoking one key deals with it, where a shared key means rotating something several systems depend on.

What about sharing with colleagues?

Issue them their own rather than passing yours around. Shared keys make usage untraceable and mean a departure requires rotating something several systems depend on.

What is the minimum discipline?

Environment variables, a spending cap, separate keys per project, and revoking rather than hiding anything exposed. Four habits, and they prevent nearly every expensive mistake in this area.