How AI is applied across API Evangelist and APIs.io. Read my AI disclosure →
API Evangelist API Evangelist
Discovery
Learnings
Guidance
Toolbox
Alignment
API Evangelist LLC

How do I stop leaking API keys and tokens?

lock Security & Authentication Updated August 12, 2026

Short answer

Assume they will leak. Scope them narrowly, expire them by default, make rotation and revocation trivial, scan your repositories continuously, and monitor for anomalous use.

Credentials leak. They get committed to public repositories, pasted into support tickets, embedded in mobile apps, logged by middleware, and left in a .env file on a laptop that gets sold. This is not a hypothetical — cloud providers have had to build entire notification programs because customer keys turn up publicly so often. Design for the leak rather than against it.

As a provider, that means: scope every credential to the minimum it needs, expire tokens by default, make rotation a one-click operation that does not require downtime, make revocation instant and obvious, show users when each credential was last used and from where, and alert on anomalous usage patterns. Never display a full secret again after issuance. Prefix your keys with a recognizable identifier so scanners — including GitHub’s — can detect them in the wild.

As a consumer: never commit secrets, use a secrets manager rather than environment files, scan your own repositories and history, rotate on any suspicion, and give each integration its own credential so you can revoke one without breaking everything.

The framing that keeps this honest is that a key is an accounting mechanism, not a lock. Its job is to tell you who is calling. The moment it stops telling the truth, everything downstream — your rate limits, your billing, your audit trail — is lying to you too.

Go deeper in the guidance

This answer is distilled from the API Evangelist guidance catalog — the long-form treatment of each topic, with its own citations back into sixteen years of writing.

Read the original writing

The posts on apievangelist.com this answer is built on.