跳转到内容
本站为社区维护的非官方中文翻译,与 Cloudflare, Inc. 无关联。本站不提供账户登录,请勿在任何非官方站点输入您的 Cloudflare 账户信息。官方文档:developers.cloudflare.com

DeepSeek

最后更新 查看 MarkdownAgent 设置

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 结构

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

Example fetch requestbash
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?"
        }
    ]
}'

使用已存储密钥(BYOK)的 cURL

通过自带密钥(BYOK)存储 DeepSeek 密钥。然后省略 Authorization 标头,AI Gateway 就能替换为已存储的密钥:

Example BYOK requestbash
curl https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/deepseek/chat/completions \
 --header 'content-type: application/json' \
 --header 'cf-aig-authorization: Bearer {CF_AIG_TOKEN}' \
 --data '{
    "model": "deepseek-chat",
    "messages": [
        {
            "role": "user",
            "content": "What is Cloudflare?"
        }
    ]
}'

使用 DeepSeek 与 JavaScript

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

JavaScriptjs
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 兼容端点

你也可以通过 REST API 使用 OpenAI API schema 访问 DeepSeek 模型。将请求发送至:

https://api.cloudflare.com/client/v4/accounts/{account_id}/ai/v1/chat/completions

指定:


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

这篇文档对您有帮助吗?