跳转到内容
搜索文档

统一 API(OpenAI 兼容)

最后更新 查看 MarkdownAgent 设置

Cloudflare 的 AI Gateway 提供与 OpenAI 兼容的 /chat/completions 端点,使你能够使用单个 URL 与多个 AI 提供商集成。此功能简化了集成流程,允许在不同模型之间无缝切换,而无需大幅修改代码。

端点 URL

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

{account_id} 替换为你的 Cloudflare 账户 ID。default gateway 会在你的首次请求时自动创建 — 无需额外设置。如果你已创建 gateway,也可以将 default 替换为特定的 gateway ID。

参数

通过更改 modelapiKey 参数来切换提供商。

使用 {provider}/{model} 格式指定模型。例如:

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

示例

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!" }],
});

受支持的提供商

OpenAI 兼容端点支持以下提供商的模型:

这篇文档对您有帮助吗?