Authentication

AI Gateway uses API keys to authenticate requests. Choose the authentication method based on which API format you're using.

OpenAI Format — Bearer Token

When using the OpenAI-compatible endpoint (/v1/chat/completions), authenticate using the Authorization header with a Bearer token.

Authorization: Bearer YOUR_API_KEY

This format is automatically used by OpenAI SDKs when you set the api_key parameter.

Anthropic Format — x-api-key Header

When using the Anthropic-compatible endpoint (/v1/messages), authenticate using the x-api-key header.

x-api-key: YOUR_API_KEY
anthropic-version: 2023-06-01

The anthropic-version header is required for Anthropic API compatibility.

Generating API Keys

1

Navigate to API Keys

Go to Dashboard → API Keys

2

Create a new key

Click Create keyand give it a descriptive name (e.g., "production", "my-app").

3

Copy your key

Copy the key immediately after creation. It will not be shown again for security reasons.

Key Management

Multiple keys per account

Create up to 3 keys (Free), 5 (Lite), 10 (Pro), or 50 (Enterprise) for different environments.

Enable/disable without deleting

Toggle keys on or off without revoking them. Useful for temporary access control.

Immediate revocation

Revoke compromised keys instantly. All requests using that key will fail immediately.

Security Best Practices

Treat API keys like passwords

Anyone with access to your API key can make requests and consume your credits.

Never expose keys in client-side code

API keys should only be used in server-side code or environment variables. Never commit keys to source control.

Use environment variables

Store keys in environment variables or a secrets manager. Never hardcode keys in your application code.

Rotate keys regularly

Create new keys periodically and revoke old ones. Use different keys for development and production.

Monitor key usage

Check your usage dashboard regularly for unexpected activity. Revoke keys immediately if you notice suspicious behavior.