Help center
How to rotate an API key without downtime
Rotate a secret API key safely: create a new restricted key, deploy it, confirm the old one is idle, then revoke it. What to do first if a key has leaked.
Updated 2026-11-23
Create a new key with the same restrictions, deploy it, check in the dashboard that the old key is no longer being used, then revoke the old one. If a key has leaked, reverse the order: revoke first, then replace. A few minutes of failed calls cost less than a balance spent by someone else.
Planned rotation
- Create a new key in the dashboard. Name it after where it runs, such as
signup-service-production. Copy it now: a live key is shown once. - Copy the restrictions. A key can be limited to chosen endpoints among
/phone,/email,/ip,/batch,/bulkand/account. A service that only verifies emails does not need the rest. - Store it in your secret manager or environment variables, never in source code.
- Deploy it to the service that used the old key.
- Check the dashboard. It shows each key's prefix and when it was last used. Wait until the old key shows no recent use.
- Revoke the old key. It stops working within 60 seconds.
If a key has leaked
- Revoke it first. Do not wait for the replacement.
- Create a new key with the same restrictions and deploy it.
- Check your usage and balance in the dashboard for calls you did not make.
- Find the leak. Search your repository history, logs, chat and CI output, and remove the key from them.
- Tighten the new key. Restrict it to the endpoints it needs.
Check which key a service uses
GET /account costs no credits and describes the calling key:
curl https://api.qelka.com/v1/account \
-H "Authorization: Bearer $API_KEY"
{
"key": { "id": "key_01M84BDPNREK4SFJN6ECRF2HYK", "name": "signup-service-production", "mode": "live", "prefix": "sk_live_8Hq2" }
}
| Field | Use |
|---|---|
key.prefix |
Safe to log. Match it with the dashboard. |
key.mode |
live or test. A startup check that reads it makes sure production never runs a test key. |
key.name |
Confirms the right service has the right key. |
The account reference lists every field. After the new key is deployed, a request with the old key returns:
{ "error": { "type": "invalid_api_key" } }
with HTTP status 401. See errors.
Habits that make rotation easy
- One key per service and environment. You can revoke one without breaking the others, and last-used dates show who still relies on it.
- Server side only. Never put a key in a browser bundle or a mobile app.
- Restrict keys. A key limited to
/emailcannot start a bulk job. - Log the prefix, never the key.
- Use test keys in CI and development. They never debit credits. See test mode.
Full details are in authentication.
Common mistakes
- Revoking before deploying. Calls fail until the new key is live.
- Forgetting a second service. Check
last usedbefore you revoke. - Pasting the key in a ticket or chat. Treat it like a password.
- Rotating to a key with wider access. Copy the restrictions.
- Mixing test and live keys. Check
key.mode.
Related
Frequently asked questions
How often should I rotate API keys?
What happens to requests that use a revoked key?
Can I recover a lost live key?
Put this check in your product
Get an API key in under a minute. 100 free credits every month, no card required.
- 100 free credits a month
- No card
- Test keys spend nothing
- Cancel any time