跳转到主要内容

chat-completion


title: Unified API (OpenAI compat) description: Send requests to multiple AI providers through a single OpenAI-compatible endpoint on AI Gateway. pcx_content_type: reference tags:

  • AI sidebar: order: 3 badge: Deprecated products:
  • ai-gateway

import { Details, Tabs, TabItem } from "/components"; import CodeSnippets from "/components/ai-gateway/code-examples.astro";

:::caution[Deprecated for single-model calls] For standard single-model chat completions, this endpoint is deprecated. Use the REST API instead, which provides OpenAI-compatible endpoints at api.cloudflare.com/client/v4/accounts/{ACCOUNT_ID}/ai/v1/chat/completions. The /compat/chat/completions endpoint will continue to work for existing integrations. :::

:::note[Dynamic routing] Dynamic routes (dynamic/{route}) can be invoked through this /compat/chat/completions endpoint, and existing integrations continue to work. For new integrations, use the REST API at /ai/v1/chat/completions or the AI binding instead. See Using a dynamic route for examples. :::

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}/default/compat/chat/completions

Replace {account_id} with your Cloudflare account ID. The default gateway is created automatically on your first request — no setup needed. You can also replace default with a specific gateway ID if you have already created one.

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

Supported Providers

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