Unified API (OpenAI compat)·续
const ai = createAI({ accountId: "{CLOUDFLARE_ACCOUNT_ID}", apiToken: "{CF_API_TOKEN}", gateway: "{GATEWAY_NAME}", });
const google = createGoogleGenerativeAI({ apiKey: "{API_KEY}" });
const { text } = await generateText({ model: ai(google("gemini-4-argon"), { vendorKey: "request" }), prompt: "What is Cloudflare?", });
```javascript
import { createAI } from "agents/models/ai-sdk";
import { createXai } from "@ai-sdk/xai";
import { generateText } from "ai";
const ai = createAI({
accountId: "{CLOUDFLARE_ACCOUNT_ID}",
apiToken: "{CF_API_TOKEN}",
gateway: "{GATEWAY_NAME}",
});
const xai = createXai({ apiKey: "{API_KEY}" });
const { text } = await generateText({
model: ai(xai("grok-4.7"), { vendorKey: "request" }),
prompt: "What is Cloudflare?",
});
import { createAI } from "agents/models/ai-sdk";
import { createXai } from "@ai-sdk/xai";
import { generateText } from "ai";
const ai = createAI({
accountId: "{CLOUDFLARE_ACCOUNT_ID}",
apiToken: "{CF_API_TOKEN}",
gateway: "{GATEWAY_NAME}",
});
const xai = createXai({ apiKey: "{API_KEY}" });
const { text } = await generateText({
model: ai(xai("grok-4.7"), { vendorKey: "request" }),
prompt: "What is Cloudflare?",
});
import { createAI } from "agents/models/ai-sdk";
import { createOpenAI } from "@ai-sdk/openai";
import { generateText } from "ai";
const ai = createAI({
accountId: "{CLOUDFLARE_ACCOUNT_ID}",
apiToken: "{CF_API_TOKEN}",
gateway: "{GATEWAY_NAME}",
});
const openai = createOpenAI({ apiKey: "cloudflare" });
const { text } = await generateText({
model: ai(openai("gpt-6-luna")),
prompt: "What is Cloudflare?",
});
import { createAI } from "agents/models/ai-sdk";
import { createAnthropic } from "@ai-sdk/anthropic";
import { generateText } from "ai";
const ai = createAI({
accountId: "{CLOUDFLARE_ACCOUNT_ID}",
apiToken: "{CF_API_TOKEN}",
gateway: "{GATEWAY_NAME}",
});
const anthropic = createAnthropic({ apiKey: "cloudflare" });
const { text } = await generateText({
model: ai(anthropic("claude-opus-5-5")),
prompt: "What is Cloudflare?",
});
import { createAI } from "agents/models/ai-sdk";
import { createGoogleGenerativeAI } from "@ai-sdk/google";
import { generateText } from "ai";
const ai = createAI({
accountId: "{CLOUDFLARE_ACCOUNT_ID}",
apiToken: "{CF_API_TOKEN}",
gateway: "{GATEWAY_NAME}",
});
const google = createGoogleGenerativeAI({ apiKey: "cloudflare" });
const { text } = await generateText({
model: ai(google("gemini-4-argon")),
prompt: "What is Cloudflare?",
});
import { createAI } from "agents/models/ai-sdk";
import { createXai } from "@ai-sdk/xai";
import { generateText } from "ai";
const ai = createAI({
accountId: "{CLOUDFLARE_ACCOUNT_ID}",
apiToken: "{CF_API_TOKEN}",
gateway: "{GATEWAY_NAME}",
});
const xai = createXai({ apiKey: "cloudflare" });
const { text } = await generateText({
model: ai(xai("grok-4.7")),
prompt: "What is Cloudflare?",
});
curl -X POST https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/compat/chat/completions \
--header 'cf-aig-authorization: Bearer {CF_AIG_TOKEN}' \
--header 'Content-Type: application/json' \
--data '{
"model": "openai/gpt-6-luna",
"messages": [
{
"role": "user",
"content": "What is Cloudflare?"
}
]
}'
curl -X POST https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/compat/chat/completions \
--header 'cf-aig-authorization: Bearer {CF_AIG_TOKEN}' \
--header 'Content-Type: application/json' \
--data '{
"model": "anthropic/claude-opus-5-5",
"messages": [
{
"role": "user",
"content": "What is Cloudflare?"
}
]
}'
curl -X POST https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/compat/chat/completions \
--header 'cf-aig-authorization: Bearer {CF_AIG_TOKEN}' \
--header 'Content-Type: application/json' \
--data '{
"model": "google/gemini-4-argon",
"messages": [
{
"role": "user",
"content": "What is Cloudflare?"
}
]
}'
curl -X POST https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/compat/chat/completions \
--header 'cf-aig-authorization: Bearer {CF_AIG_TOKEN}' \
--header 'Content-Type: application/json' \
--data '{
"model": "grok/grok-4.7",
"messages": [
{
"role": "user",
"content": "What is Cloudflare?"
}
]
}'
curl -X POST https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/compat/chat/completions \
--header 'cf-aig-authorization: Bearer {CF_AIG_TOKEN}' \
--header 'Content-Type: application/json' \
--data '{
"model": "dynamic/customer-support",
"messages": [
{
"role": "user",
"content": "What is Cloudflare?"
}
]
}'
curl -X POST https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/compat/chat/completions \
--header 'cf-aig-authorization: Bearer {CF_AIG_TOKEN}' \
--header 'Content-Type: application/json' \
--data '{
"model": "workers-ai/@cf/meta/llama-3.3-70b-instruct-fp8-fast",
"messages": [
{
"role": "user",
"content": "What is Cloudflare?"
}
]
}'
curl -X POST https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/compat/chat/completions \
--header 'cf-aig-authorization: Bearer {CF_AIG_TOKEN}' \
--header 'Authorization: Bearer {openai_api_token}' \
--header 'Content-Type: application/json' \
--data '{
"model": "openai/gpt-6-luna",
"messages": [
{
"role": "user",
"content": "What is Cloudflare?"
}
]
}'
curl -X POST https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/compat/chat/completions \
--header 'cf-aig-authorization: Bearer {CF_AIG_TOKEN}' \
--header 'Authorization: Bearer {anthropic_api_token}' \
--header 'Content-Type: application/json' \
--data '{
"model": "anthropic/claude-opus-5-5",
"messages": [
{
"role": "user",
"content": "What is Cloudflare?"
}
]
}'
curl -X POST https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/compat/chat/completions \
--header 'cf-aig-authorization: Bearer {CF_AIG_TOKEN}' \
--header 'Authorization: Bearer {google_api_token}' \
--header 'Content-Type: application/json' \
--data '{
"model": "google/gemini-4-argon",
"messages": [
{
"role": "user",
"content": "What is Cloudflare?"
}
]
}'
curl -X POST https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/compat/chat/completions \
--header 'cf-aig-authorization: Bearer {CF_AIG_TOKEN}' \
--header 'Authorization: Bearer {grok_api_token}' \
--header 'Content-Type: application/json' \
--data '{
"model": "grok/grok-4.7",
"messages": [
{
"role": "user",
"content": "What is Cloudflare?"
}
]
}'
curl -X POST https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/compat/chat/completions \
--header 'cf-aig-authorization: Bearer {CF_AIG_TOKEN}' \
--header 'Authorization: Bearer {dynamic_api_token}' \
--header 'Content-Type: application/json' \
--data '{
"model": "dynamic/customer-support",
"messages": [
{
"role": "user",
"content": "What is Cloudflare?"
}
]
}'
curl -X POST https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/compat/chat/completions \
--header 'cf-aig-authorization: Bearer {CF_AIG_TOKEN}' \
--header 'Authorization: Bearer {workers-ai_api_token}' \
--header 'Content-Type: application/json' \
--data '{
"model": "workers-ai/@cf/meta/llama-3.3-70b-instruct-fp8-fast",
"messages": [
{
"role": "user",
"content": "What is Cloudflare?"
}
]
}'
Supported Providers
The OpenAI-compatible endpoint supports models from the following providers:
- Anthropic
- OpenAI
- Groq
- Mistral
- Cohere
- Perplexity
- Workers AI
- Google-AI-Studio
- Google Vertex AI
- xAI
- DeepSeek
- Cerebras
- Baseten
- Parallel
Was this helpful?
YesNo
On this page
{"@context":"https://schema.org","@type":"TechArticle","@id":"https://developers.cloudflare.com/ai-gateway/usage/chat-completion/#page","headline":"Unified API (OpenAI compat)","description":"Send requests to multiple AI providers through a single OpenAI-compatible endpoint on AI Gateway.","url":"https://developers.cloudflare.com/ai-gateway/usage/chat-completion/","inLanguage":"en","image":"https://developers.cloudflare.com/ai-gateway/usage/chat-completion/og.png?v=2235868629d7554b","dateModified":"2026-10-02","publisher":{"@type":"Organization","name":"Cloudflare","description":"One platform for your apps, agents, and workforce. Build, secure, and scale without managing infrastructure","url":"https://www.cloudflare.com/","sameAs":["https://github.com/cloudflare","https://www.linkedin.com/company/cloudflare","https://x.com/cloudflare"],"logo":{"@type":"ImageObject","url":"https://developers.cloudflare.com/logo.svg"},"address":{"@type":"PostalAddress","streetAddress":"101 Townsend St","addressLocality":"San Francisco","addressRegion":"CA","postalCode":"94107","addressCountry":"US"},"contactPoint":[{"@type":"ContactPoint","contactType":"Customer Support","url":"https://support.cloudflare.com/","availableLanguage":["English"]},{"@type":"ContactPoint","contactType":"Sales","url":"https://www.cloudflare.com/contact/","availableLanguage":["English"]}]},"isPartOf":{"@type":"WebSite","@id":"https://developers.cloudflare.com/#website","name":"Cloudflare Docs","url":"https://developers.cloudflare.com/"},"keywords":["AI"]}
description: Route Anthropic API requests through AI Gateway for observability and control. title: Anthropic image: https://developers.cloudflare.com/ai-gateway/usage/providers/anthropic/og.png?v=23074fb36ef32eac
Documentation Index
Fetch the complete documentation index at: https://developers.cloudflare.com/ai-gateway/llms.txt
Use this file to discover all available pages before exploring further.
Docs