BYOK (Store Keys)
Bring your own keys (BYOK) is a feature in Cloudflare AI Gateway that allows you to securely store your AI provider API keys directly in the Cloudflare dashboard. Instead of including API keys in every request to your AI models, you can configure them once in the dashboard, and reference them in your gateway configuration.
The keys are stored securely with Secret Store and allows for:
- Secure storage and limit exposure
- Easier key rotation
- Rate limit, budget limit and other restrictions with Dynamic Routes
- Ensure your gateway is authenticated.
- Ensure you have appropriate permissions to create and deploy secrets on Secret Store.
- Log into the Cloudflare dashboard ↗ and select your account.
- Go to AI > AI Gateway.
- Select your gateway or create a new one.
- Go to the Provider Keys section.
- Click Add API Key.
- Select your AI provider from the dropdown.
- Enter your API key and optionally provide a description.
- Click Save.
Once you've configured your API keys in the dashboard:
- Remove API keys from your code: Delete any hardcoded API keys or environment variables.
- Update request headers: Remove provider authorization headers from your requests. Note that you still need to pass
cf-aig-authorization
. - Test your integration: Verify that requests work without including API keys.
With BYOK enabled, your workflow changes from:
-
Traditional approach: Include API key in every request header
Terminal window curl https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/openai/chat/completions \-H 'cf-aig-authorization: Bearer {CF_AIG_TOKEN}' \-H "Authorization: Bearer YOUR_OPENAI_API_KEY" \-H "Content-Type: application/json" \-d '{"model": "gpt-4", "messages": [...]}' -
BYOK approach: Configure key once in dashboard, make requests without exposing keys
Terminal window curl https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/openai/chat/completions \-H 'cf-aig-authorization: Bearer {CF_AIG_TOKEN}' \-H "Content-Type: application/json" \-d '{"model": "gpt-4", "messages": [...]}'
In the AI Gateway dashboard, you can:
- View all configured API keys by provider
- See when each key was last used
- Check the status of each key (active, expired, invalid)
To rotate an API key:
- Generate a new API key from your AI provider
- In the Cloudflare dashboard, edit the existing key entry
- Replace the old key with the new one
- Save the changes
Your applications will immediately start using the new key without any code changes or downtime.
To remove an API key:
- In the AI Gateway dashboard, find the key you want to remove
- Click the Delete button
- Confirm the deletion
Was this helpful?
- Resources
- API
- New to Cloudflare?
- Directory
- Sponsorships
- Open Source
- Support
- Help Center
- System Status
- Compliance
- GDPR
- Company
- cloudflare.com
- Our team
- Careers
- © 2025 Cloudflare, Inc.
- Privacy Policy
- Terms of Use
- Report Security Issues
- Trademark