Skip to content
Cloudflare Docs
非官方翻译 - 此文档为非官方中文翻译版本,仅供参考。如有疑问请以 英文官方文档 为准。

DeepSeek

DeepSeek 帮助您使用 DeepSeek 的先进 AI 模型快速构建。

端点

https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/deepseek

前提条件

在向 DeepSeek 发出请求时,确保您具有以下内容:

  • 您的 AI 网关账户 ID。
  • 您的 AI 网关网关名称。
  • 一个有效的 DeepSeek AI API 令牌。
  • 您要使用的 DeepSeek AI 模型的名称。

URL 结构

您的新基础 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

示例获取请求
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?"
}
]
}'

在 JavaScript 中使用 DeepSeek

如果您使用 OpenAI SDK,您可以这样设置您的端点:

JavaScript
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);
}

OpenAI-Compatible Endpoint

You can also use the OpenAI-compatible endpoint (/ai-gateway/chat-completion/) to access DeepSeek models using the OpenAI API schema. To do so, send your requests to:

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

Specify:

{
"model": "deepseek/{model}"
}