Blog

API key authentication: best practices and security guidance

·4 min read

API keys are only as strong as how you manage them

An API key is a shared secret. The security of a system using API keys depends almost entirely on how those keys are generated, stored, distributed, and retired — not on the key itself. This post covers the practical patterns that separate secure API key management from the kind that ends up in a breach post-mortem.

Generation: entropy matters

A key that can be brute-forced or guessed is no key at all. Use a cryptographically secure random generator and enough entropy to make offline attacks impractical:

  • Minimum 128 bits of entropy (a 32-character hex string, or a 22-character base64url string).
  • Prefix your keys to make them identifiable in code scanners (e.g. rr_live_ or sk_), or use standard UUID format. Secret Scanning and similar tools can alert on known prefixes / patterns.

Storage: never in source code

The most common API key leak vector is source code committed to a repository. The rule is simple: keys never live in code. Options in order of preference:

  1. A secrets manager (AWS Secrets Manager, HashiCorp Vault) — retrieve at runtime, not at build time.
  2. Environment variables injected at deploy time by your CI/CD pipeline.
  3. A gateway layer where the credential is stored and injected centrally — this is the RequestRocket model.

The gateway approach is the strongest because your application code never receives the actual vendor credential at all. It holds only a proxy key (scoped to specific proxies), while the upstream secret lives encrypted in the gateway.

Scoping: one key, one job

Broad-scope keys that can call any endpoint are the biggest operational risk. When a key leaks, you want its potential damage to be as small as possible.

Create one proxy credential per service or agent identity in RequestRocket:

POST /clients/{clientId}/credentials
{
  "credentialType": "proxy",
  "credentialAuthType": "key",
  "credentialName": "inventory-service",
  "credentialRegion": "us-east-1",
  "credentialSecret": {
    "key": "rr_live_xxxxxxxxxxxxxx"
  }
}

Then add rules that constrain what paths and methods this credential can access:

POST /clients/{clientId}/credentials/{credentialId}/rules
{
  "effect": "allow",
  "methods": ["GET"],
  "path": {
    "path": { "pattern": "^/v2/inventory/.*" },
    "presence": "must_exist"
  },
  "priority": 10,
  "notes": "Inventory service: read-only access to /v2/inventory/*"
}

Set proxyDefaultRuleEffect: "deny" on every proxy, so anything not explicitly permitted is rejected:

POST /clients/{clientId}/proxies
{
  "proxyName": "shopify-inventory",
  "proxyRegion": "us-east-1",
  "proxyProxyCredentialId": "<inventory-service-credential-id>",
  "proxyTargetId": "<shopify-target-id>",
  "proxyTargetCredentialId": "<shopify-api-key-credential-id>",
  "proxyDefaultRuleEffect": "deny"
}

Rotation: frequent and zero-downtime

Keys should be rotated on a schedule and immediately after any suspected compromise. Zero-downtime rotation requires a two-credential overlap window:

  1. Create the new target credential with the refreshed vendor key.
  2. Update the proxy’s proxyTargetCredentialId to the new credential ID.
  3. Confirm live traffic is routing through the new credential via the request log.
  4. Delete the old credential.

User tokens are what you use to authenticate calls to RequestRocket’s Core API — creating proxies, managing credentials, querying logs. They are entirely separate from proxy credentials and are never used to make requests through a proxy. User tokens are rotated via the token endpoint:

POST /users/tokens/{tokenId}

This returns a newToken value. Update your secret with the new value and delete the old token. The old token stops working immediately.

Proxy keys (the credentials your consumers present when calling a RequestRocket proxy) are rotated by creating a new proxy credential, updating the proxy’s proxyProxyCredentialId to reference it, confirming traffic flows correctly, then deleting the old credential.

Revocation: instantaneous and audited

A key that cannot be revoked instantly is a liability. In RequestRocket, deleting a credential immediately blocks all proxies that use it:

DELETE /clients/{clientId}/credentials/{credentialId}

Every request made with a credential before revocation is retained in the request log, giving you a full audit trail of what was called and when.

Auditing: know what your keys are doing

Don’t wait for a vendor alert to find out a key has been misused. Pull request history for any proxy to inspect traffic patterns:

GET /clients/{clientId}/proxies/{proxyId}/requests
  ?processedAfter=2026-04-01T00:00:00Z
  &processedBefore=2026-04-23T00:00:00Z

Aggregate telemetry is available at the client or proxy level:

GET /clients/{clientId}/telemetry?interval=day&limit=30

Anomalies — a sudden spike in requests, requests to unexpected paths, a surge of 4xx responses — are visible without waiting for vendor invoices.

What not to do

  • Don’t share keys between teams or services. One key, one identity.
  • Don’t log raw keys. If your access log captures the Authorization header, mask the value.
  • Don’t rely on IP allowlisting as a substitute for scoped rules. IPs change; rules are explicit.
  • Don’t let keys outlive their purpose. Delete credentials for decommissioned services immediately.

Next steps

Most API key security failures are preventable with process — not by switching to a different auth mechanism. A gateway that centralises credential storage, enforces scope via rules, and provides a full audit trail closes the gaps that raw key management leaves open. Explore the RequestRocket documentation or start for free.

Enhance ISO 27001
Enhance SOC 2
Enhance GDPR
Enhance HIPAA

Add outbound API security
without changing code

Start on your own or talk to our team about improving the security of every API call you make.