Security practice · About 3 min read
Store keys only on the server
- Put keys in server-side environment variables or a key management service. Do not write them into web page JavaScript, mobile apps, or desktop clients.
- Do not commit real keys to Git or put them in public issues, build artifacts, or screenshots.
- For local development, use an environment file that version control ignores, and restrict the file's read permissions.
- In CI/CD, use the project's secret management feature and avoid printing keys to logs in plain text.
Use least privilege
Create a separate key for each application, and set allowed models, quota, and expiry (if the console supports it). Do not reuse production keys in test environments, and regularly review keys that are no longer in use.
How to rotate an API key
- Create a new key and add it only to trusted server-side configuration.
- Verify the new key with a small amount of traffic before switching production traffic.
- Once the new key works correctly, revoke the old key immediately.
- Check usage records and application logs to confirm there are no unusual calls.
If you suspect a key has leaked
First disable or delete the leaked key in the console, then review recent requests and charges. Update the configuration in CI/CD, on servers, and in local development environments; check commit history and copies of logs so the same key does not appear again. If you cannot sign in or you see unusual usage, contact support at help@apirove.com.