Skip to content

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

  1. 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.
  2. Copy the restrictions. A key can be limited to chosen endpoints among /phone, /email, /ip, /batch, /bulk and /account. A service that only verifies emails does not need the rest.
  3. Store it in your secret manager or environment variables, never in source code.
  4. Deploy it to the service that used the old key.
  5. Check the dashboard. It shows each key's prefix and when it was last used. Wait until the old key shows no recent use.
  6. Revoke the old key. It stops working within 60 seconds.

If a key has leaked

  1. Revoke it first. Do not wait for the replacement.
  2. Create a new key with the same restrictions and deploy it.
  3. Check your usage and balance in the dashboard for calls you did not make.
  4. Find the leak. Search your repository history, logs, chat and CI output, and remove the key from them.
  5. 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:

bash
curl https://api.qelka.com/v1/account \
  -H "Authorization: Bearer $API_KEY"
json
{
  "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:

json
{ "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 /email cannot 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 used before 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.

Frequently asked questions

How often should I rotate API keys?
On a schedule you can keep, such as every few months, and immediately when someone with access leaves or a key may have leaked. A regular rotation also proves that your deployment can change a key without an outage. Use one key per service and environment so that rotating one does not break the others.
What happens to requests that use a revoked key?
A revoked key stops working within 60 seconds. After that, every request made with it gets a 401 response with the error type invalid_api_key, and nothing is billed. Retrying does not help: deploy the new key instead. Test and live keys are separate, so check which one a service uses.
Can I recover a lost live key?
No. A live key is shown once, when you create it, and only a SHA-256 hash is stored. If you lose it, create a new key and revoke the old one. Test keys are the exception: they are also kept encrypted so the dashboard can show them again, and they cannot spend credits.

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