API Key Authentication
All API requests require a valid API key sent via theAuthorization header using the Bearer scheme:
Full Example
Using the SDK
When using an OpenAI-compatible SDK, pass your API key during client initialization:Using Environment Variables
We recommend storing your API key in an environment variable rather than hardcoding it:Managing API Keys
You can create, view, and revoke API keys from the Console.- Create multiple keys for different environments (development, staging, production)
- Set spending limits per key to control costs
- Revoke keys instantly if they are compromised
Error Responses
If authentication fails, the API returns a401 Unauthorized error:
- Missing or malformed
Authorizationheader - Expired or revoked API key
- API key does not have sufficient permissions
Security Best Practices
Never expose your API key in frontend code
Always call the API from your backend server. Never include API keys in client-side JavaScript, mobile apps, or public repositories.
Use environment variables
Store API keys in environment variables or a secrets manager (e.g., AWS Secrets Manager, HashiCorp Vault). Never commit keys to version control.
Rotate keys regularly
Generate new API keys periodically and revoke old ones. This limits the impact if a key is accidentally exposed.
Use separate keys per environment
Create different API keys for development, staging, and production. This way, revoking a dev key won’t affect production.
Monitor usage
Review your API usage regularly in the Console to detect any unusual activity.