跳转到内容
搜索文档

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

使用 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}"
}

这篇文档对您有帮助吗?