Skip to main content
API keys provide simple, long-lived authentication for CLI tools, webhooks, and legacy integrations. All API keys are exchanged for JWTs and stored securely in Keycloak. See ADR-0034 for architectural details.

Overview

API keys are:
  • Stored in Keycloak (user attributes with bcrypt hashing)
  • Exchanged for JWTs (standardized authentication)
  • User-attributed (linked to user or service principal identity)
  • Rotatable (without changing client code)
  • Expirable (default 365 days)
  • Rate-limited (5 keys per user)

Creating API Keys

Via API

Response:
  • ⚠️ Save the api_key value immediately - it cannot be retrieved later.

Via CLI

Using API Keys

Direct API Calls

Python Client

JavaScript Client

How API Keys Work

Exchange Flow

Storage Format

API keys are stored in Keycloak user attributes as bcrypt hashes:

Managing API Keys

List Keys

Response:

Rotate Key

Response:

Revoke Key

Security Best Practices

Storage

  • DO: Store in secrets manager (Vault, AWS Secrets Manager, GCP Secret Manager)
  • DO: Use environment variables in production
  • DON’T: Commit to version control
  • DON’T: Log API keys
  • DON’T: Include in error messages

Rotation

  • DO: Rotate keys every 90-180 days
  • DO: Rotate immediately if compromised
  • DO: Test new key before revoking old key
  • DON’T: Share keys across multiple systems
  • DON’T: Reuse revoked keys

Usage

  • DO: Use HTTPS only
  • DO: Monitor key usage (last_used timestamp)
  • DO: Set appropriate expiration dates
  • DO: Use different keys for dev/staging/production
  • DON’T: Use in client-side code (browsers)
  • DON’T: Share keys in public repositories

Rate Limiting

API keys are subject to rate limits based on user tier: Rate limit headers:

Monitoring

Key Usage

Check last_used timestamps to identify unused keys:

Prometheus Metrics

Troubleshooting

Invalid API Key

Symptom: 401 Unauthorized - Invalid or expired API key Solutions:
  • Verify key is copied correctly (no whitespace)
  • Check expiration date: GET /api/v1/api-keys
  • Ensure user account is enabled
  • Verify key hasn’t been revoked

Kong Validation Timeout

Symptom: 504 Gateway Timeout Solutions:
  • Check MCP server health
  • Verify Kong→MCP connectivity
  • Increase timeout in Kong plugin config
  • Check Keycloak availability

Cache Issues

Symptom: Old key still works after revocation Solutions:
  • Wait for cache TTL (5 minutes by default)
  • Clear Kong cache: kong cache:purge apikey:*
  • Reduce cache TTL if faster revocation needed

Migration from Kong-Stored Keys

Step 1: Export Existing Keys

Step 2: Recreate in Keycloak

Step 3: Update Clients

Provide new API keys to clients (gradual rollout).

Step 4: Sunset Old Keys

After migration period, remove Kong key-auth plugin.

Examples

CLI Tool Authentication

Webhook Integration

References

Architecture & API Docs