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
- Revoke the leaked API key in the console immediately.
- Review usage and billing records to identify unusual requests since the leak began.
- Replace the credential on servers, in CI/CD, and in development environments.
- Delete the key text from public repositories, logs, or tickets, and check the version history.
- Issue a new dedicated key for each affected application and re-verify its access scope.