Skip to content
Cloudflare Docs

Unified API (OpenAI compat)

Cloudflare's AI Gateway offers an OpenAI-compatible /chat/completions endpoint, enabling integration with multiple AI providers using a single URL. This feature simplifies the integration process, allowing for seamless switching between different models without significant code modifications.

Endpoint URL

https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/compat/chat/completions

Replace {account_id} and {gateway_id} with your Cloudflare account and gateway IDs.

Parameters

Switch providers by changing the model and apiKey parameters.

Specify the model using {provider}/{model} format. For example:

  • openai/gpt-5-mini
  • google-ai-studio/gemini-2.5-flash
  • anthropic/claude-sonnet-4-5

Examples

Make a request to
OpenAI
using
OpenAI JS SDK
with
Stored Key (BYOK)
import OpenAI from "openai";
const client = new OpenAI({
apiKey: "{cf_api_token}",
baseURL:
"https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/compat",
});
const response = await client.chat.completions.create({
model: "openai/gpt-5.2",
messages: [{ role: "user", content: "Hello, world!" }],
});

Supported Providers

The OpenAI-compatible endpoint supports models from the following providers: