跳到主要内容

使用 Anthropic API

为了满足大家对 Anthropic API 生态的使用需求,我们的 API 新增了对 Anthropic API 格式的支持,其 base_urlhttps://api.deepseek.com/anthropic

通过简单的配置,即可将 DeepSeek 的能力,接入到 Anthropic API 生态中。


将 DeepSeek 模型接入 Claude Code

请参考接入 Claude Code

通过 Anthropic API 调用 DeepSeek 模型

  1. 安装 Anthropic SDK
pip install anthropic
  1. 配置环境变量
export ANTHROPIC_BASE_URL=https://api.deepseek.com/anthropic
export ANTHROPIC_API_KEY=${YOUR_API_KEY}
  1. 调用 API
import anthropic

client = anthropic.Anthropic()

message = client.messages.create(
model="deepseek-flash",
max_tokens=1000,
system="You are a helpful assistant.",
messages=[
{
"role": "user",
"content": [
{
"type": "text",
"text": "Hi, how are you?"
}
]
}
]
)
print(message.content)

注意:当您给 DeepSeek 的 Anthropic API 传入不支持的模型名时,API 后端会自动将其映射到 deepseek-flash 模型。


Anthropic 模型映射

您在使用 Anthropic API 时,我们会对您传入的 claude 模型名进行映射:

  • claude-opus 开头的模型,会映射到 deepseek-v4-pro
  • claude-haiku、claude-sonnet 开头的模型,会映射到 deepseek-flash

claude-opus 映射到的 deepseek-v4-pro 按 V4 Pro 价格计费。

通过这样的映射,您在使用新版 Claude Desktop APP 的 developer 模式时,可以绕过 APP 对模型名的限制,只需改动 base_url 和 api_key,即可在其中接入 DeepSeek 模型。


Anthropic API 兼容性细节

本小节罗列了 DeepSeek API 对 Anthropic API 的兼容性细节。Anthropic API 完整格式定义,请参考 Anthropic 官方 API 手册

HTTP Header

字段支持情况
anthropic-beta/messages 忽略;Files API 端点必须携带(files-api-2025-04-14)——见 Files API
anthropic-version忽略
x-api-key完全支持

简单字段

字段支持情况
model改为使用 DeepSeek 模型
max_tokens完全支持
container忽略
mcp_servers忽略
metadata支持 user_id,其它字段忽略
关于 user_id 参数的更多信息,请参考 限速与隔离
service_tier忽略
stop_sequences完全支持
stream完全支持
system完全支持
temperature完全支持(范围 [0.0 ~ 2.0])
thinking支持(budget_tokens 被忽略)
output_config仅支持 effort
top_k忽略
top_p仅思考模式下生效(下限为 0.95);非思考模式下恒为 1.0

Tool 字段

tools

字段支持情况
name完全支持
input_schema完全支持
description完全支持
cache_control忽略

tool_choice

取值支持情况
none完全支持
auto支持(disable_parallel_tool_use 被忽略)
any支持(disable_parallel_tool_use 被忽略)
tool支持(disable_parallel_tool_use 被忽略)

Message 字段

字段变体子字段支持情况
content string 完全支持
array, type="text" text 完全支持
cache_control 忽略
citations 忽略
array, type="image" source 支持。source.type 可为 base64(媒体类型:jpeg、png、gif、webp)、url 或 file(file 形式需带请求头 anthropic-beta: files-api-2025-04-14
array, type = "document" 不支持
array, type = "search_result" 不支持
array, type = "thinking" 支持
array, type="redacted_thinking" 不支持
array, type = "tool_use" id 完全支持
input 完全支持
name 完全支持
cache_control 忽略
array, type = "tool_result" tool_use_id 完全支持
content 完全支持
cache_control 忽略
is_error 忽略
array, type = "server_tool_use" 支持
array, type = "web_search_tool_result" 支持
array, type = "code_execution_tool_result" 不支持
array, type = "mcp_tool_use" 不支持
array, type = "mcp_tool_result" 不支持
array, type = "container_upload" 不支持