DeepSeek ↗ 帮助你使用 DeepSeek 的先进 AI 模型快速构建。
https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/deepseek向 DeepSeek 发送请求时,请确保具备以下条件:
- 你的 AI Gateway Account ID。
- 你的 AI Gateway gateway 名称。
- 有效的 DeepSeek AI API 令牌。
- 要使用的 DeepSeek AI 模型名称。
你的新基础 URL 将使用上述数据,结构如下:
https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/deepseek/。
然后可以追加要访问的端点,例如:chat/completions。
因此最终 URL 为:
https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/deepseek/chat/completions。
curl https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/deepseek/chat/completions \
--header 'content-type: application/json' \
--header 'Authorization: Bearer DEEPSEEK_TOKEN' \
--data '{
"model": "deepseek-chat",
"messages": [
{
"role": "user",
"content": "What is Cloudflare?"
}
]
}'如果你使用 OpenAI SDK,可以这样设置端点:
import OpenAI from "openai";
const openai = new OpenAI({
apiKey: env.DEEPSEEK_TOKEN,
baseURL:
"https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/deepseek",
});
try {
const chatCompletion = await openai.chat.completions.create({
model: "deepseek-chat",
messages: [{ role: "user", content: "What is Cloudflare?" }],
});
const response = chatCompletion.choices[0].message;
return new Response(JSON.stringify(response));
} catch (e) {
return new Response(e);
}你也可以通过 REST API 使用 OpenAI API schema 访问 DeepSeek 模型。将请求发送至:
https://api.cloudflare.com/client/v4/accounts/{account_id}/ai/v1/chat/completions指定:
{
"model": "deepseek/{model}"
}