How to Integrate Cloudflare AI Gateway Models in Openclaw
Quick Start
Cloudflare AI Gateway lets you route AI requests through Cloudflare's infrastructure, giving you unified billing, caching, and observability across multiple providers. This guide shows you how to connect Openclaw to Cloudflare AI Gateway in under 5 minutes.
Prerequisites
- A Cloudflare account with AI Gateway enabled
- Your Cloudflare Account ID and Gateway ID
- A provider API key (e.g., Anthropic API key)
Step 1: Interactive Setup (Recommended)
The fastest way to configure Cloudflare AI Gateway is using Openclaw's built-in onboarding wizard:
Openclaw onboard --auth-choice cloudflare-ai-gateway-api-key
Follow the prompts to enter your Account ID, Gateway ID, and provider API key.
Step 2: Non-Interactive Setup (For Scripting)
If you're automating deployment, use the non-interactive flag:
Openclaw onboard --non-interactive --mode local --auth-choice cloudflare-ai-gateway-api-key --cloudflare-ai-gateway-account-id "your-account-id" --cloudflare-ai-gateway-gateway-id "your-gateway-id" --cloudflare-ai-gateway-api-key "$CLOUDFLARE_AI_GATEWAY_API_KEY"
Step 3: Configure Your Primary Model
Edit your ~/.openclaw/openclaw.json to set Cloudflare AI Gateway as your default provider:
{ "agents": { "defaults": { "model": { "primary": "cloudflare-ai-gateway/claude-sonnet-4-5" } } } }
For more AI provider integrations, check out our guide on Anthropic Models Openclaw.
Step 4: Custom Headers (Optional)
If your Cloudflare AI Gateway requires additional authentication, add custom headers:
{ "models": { "providers": { "cloudflare-ai-gateway": { "headers": { "cf-aig-authorization": "Bearer <cloudflare-ai-gateway-token>" } } } } }
Daemon Mode Configuration
If running Openclaw as a background service, ensure your API key is accessible by adding it to ~/.openclaw/.env:
CLOUDFLARE_AI_GATEWAY_API_KEY=your-api-key-here
Looking for alternative deployment options? See our Deploy Flyio Openclaw guide for cloud hosting.
Troubleshooting
- Authentication errors: Verify your Account ID and Gateway ID are correct in the Cloudflare dashboard
- Model not found: Ensure the model ID matches one supported by your Cloudflare AI Gateway configuration
- Connection timeouts: Check that your provider API key has the necessary permissions and quota
Best Practices
- Use environment variables for API keys instead of hardcoding them
- Enable caching in your Cloudflare AI Gateway dashboard to reduce costs
- Monitor your gateway analytics to track request volume and latency