APITube Help Center

API key security best practices

Keep keys private, limit access and replace exposed secrets

Erick Horn

Written by Erick Horn

June 28, 2026

Updated October 16, 2026

Open this example in the API Playground ↗

API key security best practices

Treat your API key as a password. Keep it on your server, send it in a header and give it only the access its app needs. If a key is exposed, replace or revoke it from API Keys in the dashboard.

Send your key in a header, not in the URL

Use X-API-Key or Authorization: Bearer for production requests. The supported api_key query parameter puts the secret in a URL, where it can appear in browser history or access logs.

curl -H "X-API-Key: YOUR_API_KEY" \
  "https://api.apitube.io/v1/news/everything?per_page=10"

See how to authenticate requests.

Never expose a live key in client-side code

Visitors can copy a key included in browser JavaScript or a mobile app. Make news requests from your own server and keep the key there.

Test keys do not spend quota and return preview article text, but they are still credentials. Keep them private too. Live keys can spend account quota or balance, subject to their restrictions.

Lock each key down with IP, scope and expiry limits

Use the key’s dashboard settings to limit access:

  • Allowed IPs: list your server’s public outbound addresses or ranges, such as 203.0.113.0/24. Disallowed callers get 403 ER0601. See IP restrictions.
  • Endpoint scopes: select which endpoints the app can use. Other endpoints return 403 ER0603. See key permissions.
  • Expiry: set an end date for temporary access. An expired key returns 401 ER0230. See key expiry.

Errors include a code and message in the errors array, so your app can identify which restriction blocked it.

The API Key Restrictions card on the key detail page where allowed IPs and referrers are configured

Use a separate key per app or environment

Give apps and environments named keys so you can track usage and replace one without changing all of them. You can have up to 20 active keys per mode.

Keys share account quota and the live rate limit. Separate keys do not increase either allowance. See how to create, rename and revoke keys.

Rotate or revoke a key the moment it leaks

Open API Keys and regenerate the exposed key or revoke it. Regeneration replaces the secret while keeping the key’s name and restrictions. The old value stops working immediately, so update every app that used it.

Revocation permanently stops that key value. Revoke keys that are no longer needed as well.

Common Questions

Is it safe to put my API key in the URL?

It works, but URLs are often recorded. Prefer a header and keep keys out of shared links and logs.

What happens to requests made with a key after I regenerate it?

Requests using the old value return 401. Copy the new value into your app’s secret settings so requests can resume.

Can my whole team share one API key?

Yes, but separate named keys make usage and access easier to manage. You can replace or revoke one person’s or app’s key independently. All keys still share the account’s quotas and rate limits.

Are test keys safer to expose than live keys?

They cannot spend quota and return preview article text, but should still stay private. Use them for development, with appropriate permissions and restrictions.


Related Articles