Getting Your API Key
- Sign in to your Dashboard
- Navigate to API Keys in the sidebar
- Click Create New Key
- Give your key a descriptive name (e.g., “Production”, “Development”)
- Copy the key immediately - you won’t be able to see it again
Using Your API Key
With the SDK
Pass your API key when initializing the Layer client:With Environment Variables
Store your API key in environment variables for security:.env
With Direct API Calls
Include your API key in theAuthorization header:
Key Management Best Practices
Rotate keys regularly
Rotate keys regularly
Create new keys and delete old ones periodically to maintain security. Layer AI allows multiple active keys per account.
Use different keys for different environments
Use different keys for different environments
Create separate keys for development, staging, and production environments. This makes it easier to rotate keys and track usage.
Delete compromised keys immediately
Delete compromised keys immediately
If you suspect a key has been exposed, delete it from your Dashboard immediately and create a new one.
Monitor key usage
Monitor key usage
Check your Dashboard regularly to review which keys are being used and their associated costs.
Key Permissions
All Layer AI API keys have full access to your account:- Make inference requests through your gates
- Read and modify gates and configuration
- Manage API keys
- Access usage logs and analytics
Since all keys have full permissions, treat them with the same level of security you would treat a password.
Troubleshooting
Invalid API Key Error
If you receive an authentication error:- Verify your API key is correctly copied (no extra spaces)
- Check that the key hasn’t been deleted in your Dashboard
- Ensure you’re using the correct format:
Bearer your-api-key
Rate Limits
API keys are subject to rate limits based on your plan. If you’re hitting rate limits:- Implement exponential backoff in your code
- Consider upgrading your plan for higher limits
- Contact support for custom rate limits
Next Steps
Create Your First Gate
Set up a gate to start making requests
Make Your First Request
Follow the quickstart guide to make your first API call