AI Gateway - Call any AI model through AI Gateway's new REST API
Key Points
- Unified REST API for all AI models
- Automatic logging, caching, rate limiting, guardrails
- Use cf-aig-gateway-id to route; unified billing
Summary
AI Gateway now exposes a unified REST API on api.cloudflare.com to call any AI model (OpenAI, Anthropic, Google, or Workers AI) using the same endpoints and authentication across providers. Built-in features (logging, caching, rate limiting, guardrails) apply automatically and third-party usage is billed via Unified Billing.
Key Points
- Endpoints available:
POST /ai/run— universal endpoint for all models and modalitiesPOST /ai/v1/chat/completions— OpenAI SDK compatiblePOST /ai/v1/responses— OpenAI Responses API compatiblePOST /ai/v1/messages— Anthropic SDK compatible
- Authentication and request format are unified; you call models by name (e.g.,
openai/gpt-5.5). - Third-party models are billed through Unified Billing; no separate provider keys required.
- Requests use your account's default gateway created on first use. To force a specific gateway, add the
cf-aig-gateway-idheader. - Workers AI models can be called via the
@cf/model prefix (e.g.,@cf/moonshotai/kimi-k2.6) — the legacy path/ai/run/@cf/{model}continues to work. - All AI Gateway features (logging, caching, rate limits, guardrails) are applied automatically.
Quick example
curl -X POST "https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/v1/chat/completions"
-H "Authorization: Bearer $CLOUDFLARE_API_TOKEN"
-H "Content-Type: application/json"
-d '{"model":"openai/gpt-5.5","messages":[{"role":"user","content":"What is Cloudflare?"}]}'
Where to go next
See the REST API documentation for full request/response schemas, gateway configuration, and examples.