APIrove

Home / Blog / API key security

API SECURITY · CHECKLIST

AI API Key Security: A Practical Checklist to Prevent Credential Leaks

An API key is a credential that can make requests. Keeping it in the right place and limiting its permissions is easier than tracing charges after a leak.

By APIrove · Updated September 29, 2026

Do not put the key in client code

Web pages, browser extensions, mobile apps, and desktop programs all run on devices that users can inspect. Even if a key is minified or obfuscated, it can still be extracted. Have the client call your own backend, and let the backend call the AI API securely.

Choose a secure storage location

  • Keep production keys in server environment variables, a cloud key manager, or an encrypted secret store.
  • Put local development keys in an ignored file so they are not committed to version control.
  • Create separate keys for different applications and environments, and give each one only the quota and model access it needs.
  • Redact Authorization headers and environment variables in logs and error tracking.

Set up a key rotation process

A two-key switchover reduces disruption during rotation: create the new key first, verify it on non-production requests, then update service configuration step by step. Once the new key is confirmed to work, revoke the old key and check whether any component is still using it.

What to do first after a leak

  1. Revoke the leaked API key in the console immediately.
  2. Review usage and billing records to identify unusual requests since the leak began.
  3. Replace the credential on servers, in CI/CD, and in development environments.
  4. Delete the key text from public repositories, logs, or tickets, and check the version history.
  5. Issue a new dedicated key for each affected application and re-verify its access scope.
Do not paste keys into public chats, screenshots, or issue tickets, and do not hand them to a third party to test for you. See the APIrove API key security guide.