How to Manage API Keys Safely: Scopes, Expiry, and Rotation

By Nimana · Last updated November 20, 2026 · 3 min read

Protect your messaging account with the right API key habits: least-privilege scopes, expiry dates, safe storage, and a rotation routine you can follow.

Why This Matters

If a key leaks, anyone who finds it can send messages as your business. They can spam your customers, use up your quota, and damage your sending reputation. Most leaks are accidents: a key pasted into code that is pushed to a public repository, shared in a chat message, or left in a screenshot.

You cannot make a mistake impossible, but you can make its damage small. That is what scopes, expiry, and rotation are for.

Habit 1: Give Each Key the Smallest Job Possible

The principle is called least privilege. A key should be able to do only what its job needs, and nothing more.

For example, a service that only sends password reset emails does not need to send WhatsApp messages or read your billing information. If that key leaks, the damage is limited to email.

Habit 2: Use Separate Keys for Separate Jobs

Do not use one key everywhere. Create different keys for:

  • Production and testing
  • Different applications or services
  • Different team members or contractors

If one leaks or someone leaves, you only revoke that one key, and everything else keeps running.

Habit 3: Set an Expiry Date Where You Can

Some keys are only needed for a short time, such as a contractor's key for a one-month project. Give them an expiry date, so they stop working by themselves even if you forget.

Habit 4: Store Keys Safely

  • Keep keys in environment variables or a secrets manager, never in source code.
  • Keep them on the server, never in front-end or mobile app code.
  • Do not paste keys into chats, emails, or screenshots.
  • Remember a key is usually shown only once when it is created, so save it somewhere safe straight away.

Habit 5: Know Which Key Is Which

Name every key clearly ("Production", "Checkout service"), and keep a note of what it is used for. When something looks odd, you can tell straight away which key to look at, and whether it was used recently.

Habit 6: Rotate and Revoke

Rotating a key means replacing it with a new one. Do it on a routine, and immediately if you suspect a leak. A safe rotation looks like this:

  1. Create the new key.
  2. Update your servers and apps to use it.
  3. Check that everything works.
  4. Revoke the old key.

If a key is leaked, skip the routine. Revoke it straight away, check your logs for anything you did not send, and create a replacement.

Common Mistakes

  • One key for everything, so one leak affects everything
  • Full-access keys for small jobs
  • No record of which key is used where
  • Never revoking old keys, such as those of former team members

How SendAPI Helps

SendAPI's API Keys feature supports each of these habits:

  • Scoped keys: restrict a key to specific channels with scopes such as whatsapp:read, whatsapp:write, sms:write, email:write, verify:write, and account:read. A key with no scopes has full access, and a key with scopes can only use endpoints in those channels.
  • Automatic expiry: set an expires_at timestamp when you create a key, and it expires on its own. Leave it out for no expiry.
  • Shown only once: the full secret is returned only when the key is created. After that, only the key_prefix (the first 12 characters) is shown, so you can tell keys apart without exposing the secret.
  • Easy revoking: delete a key with DELETE /v1/api-keys/{id}, and any request using it returns 401 Unauthorized.
  • Plan limits: Starter allows 1 key, Growth 3, Business 10, and Enterprise unlimited, so check how many you can have before planning separate keys.

Creating a scoped key looks like this:

curl -X POST https://sendapi.co/v1/api-keys \
  -H "Authorization: Bearer sk_live_YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Password reset service",
    "scopes": ["email:write"]
  }'

All of this comes with WhatsApp, SMS, OTP, and email under one API from $9.99 a month.