在本指南中,您将学习如何创建您的第一个 AI 网关。您可以创建多个网关来控制不同的应用。
在开始之前,您需要一个 Cloudflare 账户。
注册
然后,创建一个新的 AI 网关。
To set up an AI Gateway in the dashboard:
- Log into the Cloudflare dashboard ↗ and select your account.
- Go to AI > AI Gateway.
- Select Create Gateway.
- Enter your Gateway name. Note: Gateway name has a 64 character limit.
- Select Create.
To set up an AI Gateway using the API:
-
Create an API token with the following permissions:
AI Gateway - Read
AI Gateway - Edit
-
Get your Account ID.
-
Using that API token and Account ID, send a
POST
request to the Cloudflare API.
设置新网关时,您可以在已验证和未验证的网关之间进行选择。启用已验证的网关需要每个请求都包含有效的授权令牌,这增加了一层额外的安全性。我们建议在存储日志时使用已验证的网关,以防止未经授权的访问,并防范可能增加日志存储使用量并使您难以找到所需数据的无效请求。了解更多关于设置已验证网关的信息。
接下来,将您的 AI 提供商连接到您的网关。
AI 网关为您创建的每个网关提供多个端点 - 每个提供商一个端点,以及一个通用端点。要使用 AI 网关,您需要为每个提供商创建自己的账户并提供您的 API 密钥。AI 网关充当这些请求的代理,实现可观察性、缓存等功能。
此外,AI 网关还有一个 WebSockets API,它提供单一持久连接,实现持续通信。此 API 支持连接到 AI 网关的所有 AI 提供商,包括那些本身不支持 WebSockets 的提供商。
以下是我们支持的模型提供商列表:
- Amazon Bedrock
- Anthropic
- Azure OpenAI
- Cartesia
- Cerebras
- Cohere
- DeepSeek
- ElevenLabs
- Google AI Studio
- Google Vertex AI
- Grok
- Groq
- HuggingFace
- Mistral AI
- OpenAI
- OpenRouter
- Perplexity
- Replicate
- Workers AI
如果您没有提供商偏好,请从我们的专门教程之一开始:
现在您的提供商已连接到 AI 网关,您可以查看通过网关的请求分析。
Your AI Gateway dashboard shows metrics on requests, tokens, caching, errors, and cost. You can filter these metrics by time and provider-type.
To view analytics in the dashboard:
- Log into the Cloudflare dashboard ↗ and select your account.
- Go to AI > AI Gateway.
- Make sure you have your gateway selected.
- 了解更多关于缓存以实现更快的请求和成本节省,以及速率限制来控制应用的扩展方式。
- 探索如何为弹性指定模型或提供商回退。
- 了解如何在 Workers AI 上使用低成本的开源模型 - 我们的 AI 推理服务。
- @2025 Cloudflare Ubitools
- Cf Repo