Skip to Content
KingsPay Docs
API Keys

Securing API Keys

Best practices to keep your API keys safe and prevent unauthorized access.

Anyone with your API key can make requests to the KingsPay API on your behalf — including creating charges, initiating payouts, and accessing sensitive account data. Treat your API keys with the same care as passwords.

Never Expose Your API Key Publicly

  • Do not commit API keys to source control. Store them in environment variables (e.g. a .env file) and add .env to your .gitignore.
  • Do not include API keys in client-side code. Any key bundled into a browser app, mobile app, or publicly accessible JavaScript file can be extracted by anyone.
  • Do not share API keys in chat, email, or support tickets. Use the Dashboard to regenerate a key if you need to hand off access.

Use Environment Variables

Always load your API key from the environment at runtime:

# .env (never commit this file)
PAYMENTS_API_KEY=your_api_key_here

Then reference it in your code:

const apiKey = process.env.PAYMENTS_API_KEY;

Apply the Principle of Least Privilege

When creating an API key, only grant the permissions it actually needs. A key used only to create charges should not have payout permissions. This limits the blast radius if the key is ever compromised.

For a full list of available permissions, see the API Key Permissions page.

Restrict Access by IP Address

If your integration runs from a server with a known static IP, enable IP restrictions on your API key. When enabled, requests from any IP not on the allowlist are rejected outright — even if someone obtains the key itself.

Go to Integrations → API Keys, open the menu on your key, and select Manage IP Restrictions. For full details, see the IP Restrictions page.

Rotate Keys Regularly

Even if you have no reason to suspect a leak, rotating API keys periodically is good hygiene. To rotate a key:

  1. Create a new API key in Integrations → API Keys.
  2. Update your application to use the new key.
  3. Delete the old key from the Dashboard.

Revoke a Compromised Key Immediately

If you suspect a key has been leaked or misused:

  1. Go to Integrations → API Keys in the Dashboard.
  2. Delete the compromised key immediately.
  3. Review your transaction history for any unauthorized activity.
  4. Generate a new key and update your application.

KingsPay support staff will never ask you for your API key. If you receive such a request, treat it as a phishing attempt.

On this page