Getting started
In this guide, you will learn how to set up and use your first AI Gateway.
Before making requests, you need two things:
- Your Account ID — find it in the Cloudflare dashboard.
- A Cloudflare API token — create an API token with
AI Gateway - ReadandAI Gateway - Editpermissions. The example below also uses Workers AI, so addWorkers AI - Readas well.
Run the following command to make your first request through AI Gateway:
curl -X POST "https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/v1/chat/completions" \ --header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \ --header "Content-Type: application/json" \ --data '{ "model": "moonshotai/kimi-k2.6", "provider": "cloudflare", "messages": [ { "role": "user", "content": "What is Cloudflare?" } ] }'Create a gateway manually
You can also create gateways manually with a custom name and configuration through the dashboard or API.
- Log into the Cloudflare dashboard ↗ and select your account.
- Go to AI > AI Gateway.
- Select Create Gateway.
- Enter your Gateway name. Note: Gateway name has a 64 character limit.
- Select Create.
To set up an AI Gateway using the API:
-
Create an API token with the following permissions:
AI Gateway - ReadAI Gateway - Edit
-
Get your Account ID.
-
Using that API token and Account ID, send a
POSTrequest to the Cloudflare API.
Authenticate with your upstream AI provider using one of the following options:
- Unified Billing: Use the AI Gateway billing to pay for and authenticate your inference requests. Refer to Unified Billing.
- BYOK (Store Keys): Store your own provider API Keys with Cloudflare, and AI Gateway will include them at runtime. Refer to BYOK.
- Request headers: Include your provider API Key in the request headers as you normally would (for example,
Authorization: Bearer <OPENAI_API_KEY>).
Call any model — whether hosted on Cloudflare or by a third-party provider — through the same Cloudflare API. No provider SDKs or API keys needed — authentication and billing are handled through your Cloudflare account. Three endpoints are available: /ai/run for all modalities, /ai/v1/chat/completions for OpenAI SDK compatibility, and /ai/v1/responses for agentic workflows.
curl -X POST "https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/v1/chat/completions" \ --header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \ --header "Content-Type: application/json" \ --data '{ "model": "openai/gpt-4.1-mini", "messages": [{"role": "user", "content": "What is Cloudflare?"}] }'Refer to REST API for details and examples.
For direct integration with specific AI providers, use dedicated endpoints that maintain the original provider's API schema while adding AI Gateway features.
https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/{provider}Available providers:
- OpenAI - GPT models and embeddings
- Anthropic - Claude models
- Google AI Studio - Gemini models
- Workers AI - Cloudflare's inference platform
- AWS Bedrock - Amazon's managed AI service
- Azure OpenAI - Microsoft's OpenAI service
- and more...
- Learn more about caching for faster requests and cost savings and rate limiting to control how your application scales.
- Explore how to specify model or provider fallbacks, ratelimits, A/B tests for resiliency.
- Learn how to use low-cost, open source models on Workers AI - our AI inference service.