Skip to main content

DeepSeek logoDeepSeek

通过 Mastra 的模型路由访问 2 个 DeepSeek 模型。身份验证会自动使用 DEEPSEEK_API_KEY 环境变量处理。

🌐 Access 2 DeepSeek models through Mastra's model router. Authentication is handled automatically using the DEEPSEEK_API_KEY environment variable.

DeepSeek文档中了解更多。

🌐 Learn more in the DeepSeek documentation.

.env
DEEPSEEK_API_KEY=your-api-key
src/mastra/agents/my-agent.ts
import { Agent } from "@mastra/core/agent";

const agent = new Agent({
id: "my-agent",
name: "My Agent",
instructions: "You are a helpful assistant",
model: "deepseek/deepseek-chat"
});

// Generate a response
const response = await agent.generate("Hello!");

// Stream a response
const stream = await agent.stream("Tell me a story");
for await (const chunk of stream) {
console.log(chunk);
}

模型
Direct link to 模型

🌐 Models

ModelContextToolsReasoningImageAudioVideoInput $/1MOutput $/1M
deepseek/deepseek-chat128K$0.28$0.42
deepseek/deepseek-reasoner128K$0.28$0.42
2 available models

高级配置
Direct link to 高级配置

🌐 Advanced Configuration

自定义头
Direct link to 自定义头

🌐 Custom Headers

src/mastra/agents/my-agent.ts
const agent = new Agent({
id: "custom-agent",
name: "custom-agent",
model: {
url: "https://api.deepseek.com",
id: "deepseek/deepseek-chat",
apiKey: process.env.DEEPSEEK_API_KEY,
headers: {
"X-Custom-Header": "value"
}
}
});

动态模型选择
Direct link to 动态模型选择

🌐 Dynamic Model Selection

src/mastra/agents/my-agent.ts
const agent = new Agent({
id: "dynamic-agent",
name: "Dynamic Agent",
model: ({ requestContext }) => {
const useAdvanced = requestContext.task === "complex";
return useAdvanced
? "deepseek/deepseek-reasoner"
: "deepseek/deepseek-chat";
}
});

提供商选项
Direct link to 提供商选项

🌐 Provider Options

DeepSeek 通过 providerOptions 参数支持以下特定于提供商的选项:

🌐 DeepSeek supports the following provider-specific options via the providerOptions parameter:

const response = await agent.generate("Hello!", {
providerOptions: {
deepseek: {
// See available options in the table below
}
}
});

可用选项
Direct link to 可用选项

🌐 Available Options

thinking?:

{ type?: "enabled" | "disabled" | undefined; } | undefined