ModelSiteAPI

DeepSeek 模型

deepseek-v4.1-flash / deepseek-v4-flash-0731 / deepseek-v4-pro 按场景的调用示例:对话、思考、工具调用、JSON 输出、前缀续写、缓存、图片输入

DeepSeek 系列通过 /v1/chat/completions 与 /v1/messages 两种格式调用。平台对请求体透传:厂商专属参数原样转发,由上游模型决定是否生效。本页按场景组织,场景划分参照 DeepSeek 官方文档(思考模式、工具调用、JSON 输出、对话前缀续写、FIM 补全、上下文缓存、多轮对话),但是否支持以平台实际接入的上游为准,不以官方为准。

每个场景标注证据:

  • 已实测(线上测试账号,2026-10-19):用线上账号真实调用过,响应取自真实输出(id、时间戳已替换为占位符)。
  • 依官方文档(未实测):只对照了官方文档,没有真实请求确认。

支持的模型

平台模型 id说明上下文窗口最大输出能力标签
deepseek-v4.1-flashV4.1 Flash,思考 / 非思考双模式1,000,000384,000对话、流式、工具调用、思考、缓存
deepseek-v4-flash-0731V4 Flash(0731 版本)1,000,000384,000对话、流式、工具调用、思考、缓存
deepseek-v4-proV4 Pro,更强推理1,000,000384,000对话、流式、工具调用、思考、缓存
  • DeepSeek 官方 API 的模型名是 deepseek-flash、deepseek-v4-pro;在 ModelSite 请使用上表的平台模型 id。
  • 能力标签以 GET /v1/models 返回为准。三个模型的能力标签都不含 vision,图片输入见「图片输入」。

平台不会替你开启思考。平台不会默认注入 thinking、reasoning_effort、思考预算或 temperature。你不传,就由上游默认行为决定(官方默认开启思考、reasoning_effort 默认 high)。需要确定的行为,请在每次请求里显式传 thinking。

场景总览

场景官方是否提供我们的情况示例
基础对话与多轮对话是支持基础对话
流式输出是支持流式输出
思考模式(开关、强度、读取思考内容)是支持思考模式
工具调用(非思考)是支持工具调用
思考模式下的工具调用是部分支持:deepseek-v4.1-flash 已实测,另两个模型未实测思考 + 工具调用
JSON 输出是支持JSON 输出
对话前缀续写(Beta)是部分支持:deepseek-v4-pro 已实测,不需要 Beta 入口;另两个模型未实测前缀续写
上下文缓存是支持(自动,无参数)上下文缓存
图片输入官方定价页标注 Flash 支持部分支持:deepseek-v4.1-flash 实测能识图,但平台未列为视觉能力,不承诺图片输入
Anthropic 格式调用是(官方 Anthropic 兼容页)支持Anthropic 格式
FIM 补全(Beta,/completions)是未接入:平台没有 /v1/completions 入口无
严格模式工具调用(strict,Beta)是未接入:官方依赖 Beta 入口,平台没有对应入口,未验证 strict 是否被上游识别无

基础对话

证据:已实测(线上测试账号,2026-10-19),deepseek-v4-flash-0731。

何时用:一问一答,或者把历史消息带上做多轮对话。接口是无状态的,多轮对话要把每轮的 assistant 回复追加到 messages 再发下一轮。

请求

from openai import OpenAI

client = OpenAI(base_url="https://api.modelsite.ai/v1", api_key="sk-ms-xxxxxxxx")

messages = [{"role": "user", "content": "Which is the highest mountain in the world? Answer in one short sentence."}]
resp = client.chat.completions.create(
    model="deepseek-v4-flash-0731",
    messages=messages,
    max_tokens=200,
    extra_body={"thinking": {"type": "disabled"}},
)
print(resp.choices[0].message.content)

# 多轮:把回复追加进历史,再问下一句
messages.append({"role": "assistant", "content": resp.choices[0].message.content})
messages.append({"role": "user", "content": "And the second highest?"})
resp = client.chat.completions.create(
    model="deepseek-v4-flash-0731",
    messages=messages,
    max_tokens=200,
    extra_body={"thinking": {"type": "disabled"}},
)

响应

{
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Mount Everest, at 8,848.86 meters (29,031.7 feet) above sea level, is the highest mountain in the world.",
        "refusal": null
      },
      "finish_reason": "stop"
    }
  ],
  "created": 1760000000,
  "id": "chatcmpl-xxxx",
  "model": "deepseek-v4-flash-0731",
  "object": "chat.completion",
  "system_fingerprint": "fp_xxxx",
  "usage": {
    "prompt_tokens": 19,
    "completion_tokens": 32,
    "total_tokens": 51,
    "prompt_tokens_details": {
      "cached_tokens": 0
    },
    "completion_tokens_details": {
      "reasoning_tokens": 0,
      "audio_tokens": 0,
      "accepted_prediction_tokens": 0,
      "rejected_prediction_tokens": 0
    }
  }
}

注意事项

  • 不传 max_tokens 时的默认值与计数口径由上游决定,且因模型而异:deepseek-v4.1-flash 上游默认 128K、计入思考、超出后截断不报错;另两个模型未验证。官方 API 的默认是非思考 8K、思考 64K、超出报错。建议每次请求显式传 max_tokens,思考模型要给思考留足空间。
  • 多轮对话请求的历史越长,输入 token 越多;重复的前缀会自动命中缓存,见上下文缓存。

流式输出

证据:已实测(线上测试账号,2026-10-19),deepseek-v4-pro。

何时用:边生成边显示。传 stream: true,按 SSE 逐块读取;思考内容在 delta.reasoning_content,回答在 delta.content,两者分别累加。

请求

from openai import OpenAI

client = OpenAI(base_url="https://api.modelsite.ai/v1", api_key="sk-ms-xxxxxxxx")

stream = client.chat.completions.create(
    model="deepseek-v4-pro",
    messages=[{"role": "user", "content": "数到五,用逗号分隔。"}],
    max_tokens=100,
    stream=True,
    extra_body={"thinking": {"type": "disabled"}},
)
reasoning, content = "", ""
for chunk in stream:
    if not chunk.choices:
        continue
    d = chunk.choices[0].delta
    if getattr(d, "reasoning_content", None):
        reasoning += d.reasoning_content
    elif d.content:
        content += d.content
print(content)

响应(中间的数据块用 ... 省略)

data: {"choices":[{"index":0,"delta":{"role":"assistant","content":"1"}}],"created":1760000000,"id":"chatcmpl-xxxx","model":"deepseek-v4-pro","object":"chat.completion.chunk","service_tier":"default"}

data: {"choices":[{"index":0,"delta":{"role":"assistant","content":","}}],"created":1760000000,"id":"chatcmpl-xxxx","model":"deepseek-v4-pro","object":"chat.completion.chunk","service_tier":"default"}

...

data: {"choices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":"stop"}],"created":1760000000,"id":"chatcmpl-xxxx","model":"deepseek-v4-pro","object":"chat.completion.chunk","service_tier":"default","usage":{"prompt_tokens":13,"completion_tokens":13,"total_tokens":26,"prompt_tokens_details":{"cached_tokens":0},"completion_tokens_details":{"reasoning_tokens":0,"audio_tokens":0,"accepted_prediction_tokens":0,"rejected_prediction_tokens":0}}}

data: {"choices":[],"created":1760000000,"id":"chatcmpl-xxxx","model":"deepseek-v4-pro","object":"chat.completion.chunk","service_tier":"default","usage":{"prompt_tokens":13,"completion_tokens":13,"total_tokens":26,"prompt_tokens_details":{"cached_tokens":0},"completion_tokens_details":{"reasoning_tokens":0,"audio_tokens":0,"accepted_prediction_tokens":0,"rejected_prediction_tokens":0}}}

data: [DONE]

注意事项

  • 流式请求没传 stream_options 时,网关自动加 include_usage,用量出现在流的最后;最后一个带 choices 的块和随后 choices 为空的块都带 usage,读取时先判断 choices 是否为空。
  • 流式里思考内容和回答是分开的字段,不要把 reasoning_content 拼进回答。

思考模式

证据:已实测(线上测试账号,2026-10-19),deepseek-v4.1-flash(OpenAI 格式)。

何时用:数学、推理、复杂编码等需要多步推理的任务;简单问答、翻译、工具循环建议关闭思考,更快更便宜。

三个模型都有思考 / 非思考两种模式,用 thinking 控制,用 reasoning_effort 调强度。thinking 不是 OpenAI 标准字段,Python SDK 放进 extra_body;reasoning_effort 是标准字段,直接传。

请求

from openai import OpenAI

client = OpenAI(base_url="https://api.modelsite.ai/v1", api_key="sk-ms-xxxxxxxx")

# 显式开启思考并指定强度
resp = client.chat.completions.create(
    model="deepseek-v4.1-flash",
    messages=[{"role": "user", "content": "9.11 和 9.9 哪个大?一句话回答。"}],
    max_tokens=1500,
    reasoning_effort="low",
    extra_body={"thinking": {"type": "enabled"}},
)
msg = resp.choices[0].message
print(getattr(msg, "reasoning_content", None))  # 思考过程
print(msg.content)                              # 最终回答

# 关闭思考
resp = client.chat.completions.create(
    model="deepseek-v4.1-flash",
    messages=[{"role": "user", "content": "用一句话解释量子纠缠"}],
    extra_body={"thinking": {"type": "disabled"}},
)

响应:思考过程在 message.reasoning_content,最终回答在 message.content,思考 token 数在 usage.completion_tokens_details.reasoning_tokens,且计入 completion_tokens。

{
  "id": "xxxxxxxx",
  "object": "chat.completion",
  "created": 1760000000,
  "model": "deepseek-v4.1-flash",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "按数值比较,9.9 比 9.11 大。",
        "refusal": null,
        "reasoning_content": "我们需要回答中文问题:“9.11 和 9.9 哪个大?一句话回答。” 需要注意可能是版本号? 一般数字比较:9.11 < 9.9? 因为 9.11 = 9.11,9.9=9.90,所以 9.9 大。但如果像软件版本号,9.11 > 9.9 因为 minor 11 > 9。问题没指定。通常数学数字比较:9.9 大。一句话回答。需要简洁。问“9.11 和 9.9 哪个大?” 应该回答“按数值比较,9.9 比 9.11 大。” 一句话。注意如果版本号则 9.11 更大,但通常直接问哪个大,按十进制。可以加“按数值”。一句话。最终。"
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 46,
    "completion_tokens": 200,
    "total_tokens": 246,
    "prompt_tokens_details": {
      "cached_tokens": 0
    },
    "completion_tokens_details": {
      "reasoning_tokens": 183,
      "audio_tokens": 0,
      "accepted_prediction_tokens": 0,
      "rejected_prediction_tokens": 0
    }
  },
  "service_tier": "default"
}

注意事项

  • reasoning_effort 只用 low、high、max,默认 high。其他取值(none、minimal、medium、xhigh、ultra)在不同模型上的映射不一致,不要依赖:deepseek-v4.1-flash 的上游文档写 none 关闭思考、minimal 映射 low、medium 与 xhigh 映射 high、ultra 映射 max;deepseek-v4-pro 写 none 与 minimal 关闭思考、medium 映射 low、xhigh 映射 high;deepseek-v4-flash-0731 未验证。关闭思考请用 thinking: {"type": "disabled"}。
  • 采样参数:temperature 在思考模式下不生效(不报错);top_p 在 deepseek-v4.1-flash 思考模式下小于 0.95 会被提升到 0.95、非思考固定 1.0;frequency_penalty、presence_penalty 不要传。top_k 上游忽略。平台不做范围校验,超范围的值原样交给上游。
  • thinking 只认 enabled / disabled;adaptive(Claude 专用取值)不会被转发。
  • 历史消息里的 reasoning_content:不带 tools 的多轮对话里它会被上游忽略;带 tools 的情况见「思考 + 工具调用」。

工具调用

证据:已实测(线上测试账号,2026-10-19),deepseek-v4-pro,关闭思考。

何时用:让模型决定调用你定义的函数。模型本身不执行函数:它返回 tool_calls,由你的代码执行后,把结果以 role: "tool" 消息(带对应的 tool_call_id)放回历史,再请求一次得到最终回答。

第一轮请求

from openai import OpenAI

client = OpenAI(base_url="https://api.modelsite.ai/v1", api_key="sk-ms-xxxxxxxx")

tools = [{
    "type": "function",
    "function": {
        "name": "get_weather",
        "description": "Get weather of a location, the user should supply a location first.",
        "parameters": {
            "type": "object",
            "properties": {"location": {"type": "string", "description": "The city and state, e.g. San Francisco, CA"}},
            "required": ["location"],
        },
    },
}]
messages = [{"role": "user", "content": "How is the weather in Hangzhou?"}]
resp = client.chat.completions.create(
    model="deepseek-v4-pro", messages=messages, tools=tools, max_tokens=300,
    extra_body={"thinking": {"type": "disabled"}},
)
msg = resp.choices[0].message
messages.append(msg)  # 把带 tool_calls 的 assistant 消息放回历史

第一轮响应:finish_reason 为 tool_calls,function.arguments 是 JSON 字符串,需要自己解析。

{
  "id": "xxxxxxxx",
  "object": "chat.completion",
  "created": 1760000000,
  "model": "deepseek-v4-pro",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "I'll check the current weather in Hangzhou for you.\n\n",
        "refusal": null,
        "tool_calls": [
          {
            "id": "call_xxxx",
            "type": "function",
            "function": {
              "name": "get_weather",
              "arguments": "{\"location\": \"Hangzhou, China\"}"
            }
          }
        ]
      },
      "finish_reason": "tool_calls"
    }
  ],
  "usage": {
    "prompt_tokens": 306,
    "completion_tokens": 59,
    "total_tokens": 365,
    "prompt_tokens_details": {
      "cached_tokens": 0
    },
    "completion_tokens_details": {
      "reasoning_tokens": 0,
      "audio_tokens": 0,
      "accepted_prediction_tokens": 0,
      "rejected_prediction_tokens": 0
    }
  },
  "service_tier": "default"
}

第二轮:执行函数,把结果放回历史再请求(tools 建议继续带上)。

for call in msg.tool_calls:
    result = "24℃, cloudy"  # 你的函数实际执行结果
    messages.append({"role": "tool", "tool_call_id": call.id, "content": result})

resp = client.chat.completions.create(
    model="deepseek-v4-pro", messages=messages, tools=tools, max_tokens=300,
    extra_body={"thinking": {"type": "disabled"}},
)
print(resp.choices[0].message.content)

第二轮响应

{
  "id": "xxxxxxxx",
  "object": "chat.completion",
  "created": 1760000000,
  "model": "deepseek-v4-pro",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "The weather in Hangzhou is currently **24℃ and cloudy**.",
        "refusal": null
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 381,
    "completion_tokens": 13,
    "total_tokens": 394,
    "prompt_tokens_details": {
      "cached_tokens": 0
    },
    "completion_tokens_details": {
      "reasoning_tokens": 0,
      "audio_tokens": 0,
      "accepted_prediction_tokens": 0,
      "rejected_prediction_tokens": 0
    }
  },
  "service_tier": "default"
}

注意事项

  • tool_choice 取值 none、auto、required 或指定函数。思考模式下能否强制调用因模型而异(见下一节);需要强制调用某个工具时最稳妥的做法是关闭思考。
  • tools 只支持 function 类型。
  • Chat Completions 格式不支持在对话中途插入工具调用消息(官方说明,要用 Anthropic 格式)。
  • Anthropic 格式的 tool_choice:auto 对应 auto,any 对应 required,tool 对应指定函数;none 对应 none;disable_parallel_tool_use: true 对应 parallel_tool_calls: false。

思考 + 工具调用

证据:已实测(线上测试账号,2026-10-19),仅 deepseek-v4.1-flash;deepseek-v4-pro 与 deepseek-v4-flash-0731 依官方文档(未实测)。

何时用:需要先推理再决定调用哪个函数的 Agent 场景。开启思考并传 tools,循环到响应不再带 tool_calls 为止。

请求(第一轮)

resp = client.chat.completions.create(
    model="deepseek-v4.1-flash",
    messages=messages,            # 同上,用户问杭州天气
    tools=tools,
    max_tokens=1500,
    reasoning_effort="low",
    extra_body={"thinking": {"type": "enabled"}},
)
msg = resp.choices[0].message     # 含 reasoning_content 与 tool_calls
messages.append(msg)              # 整条 assistant 消息(含 reasoning_content)放回历史

第一轮响应:同时有 reasoning_content 和 tool_calls。

{
  "id": "xxxxxxxx",
  "object": "chat.completion",
  "created": 1760000000,
  "model": "deepseek-v4.1-flash",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "",
        "refusal": null,
        "tool_calls": [
          {
            "id": "call_xxxx",
            "type": "function",
            "function": {
              "name": "get_weather",
              "arguments": "{\"location\": \"Hangzhou\"}"
            }
          }
        ],
        "reasoning_content": "The user wants to know the weather in Hangzhou. Let me call the get_weather function."
      },
      "finish_reason": "tool_calls"
    }
  ],
  "usage": {
    "prompt_tokens": 321,
    "completion_tokens": 61,
    "total_tokens": 382,
    "prompt_tokens_details": {
      "cached_tokens": 0
    },
    "completion_tokens_details": {
      "reasoning_tokens": 20,
      "audio_tokens": 0,
      "accepted_prediction_tokens": 0,
      "rejected_prediction_tokens": 0
    }
  },
  "service_tier": "default"
}

第二轮响应:把上面整条 assistant 消息(含 reasoning_content)和 role: "tool" 的结果放回历史再请求。

{
  "id": "xxxxxxxx",
  "object": "chat.completion",
  "created": 1760000000,
  "model": "deepseek-v4.1-flash",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "The weather in Hangzhou is currently **24℃ and cloudy** — mild and comfortable, with no precipitation expected. It's a good day to be outside, though you might want a light layer if it gets breezy.",
        "refusal": null,
        "reasoning_content": "The tool returned 24℃, cloudy. Let me report that."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 378,
    "completion_tokens": 60,
    "total_tokens": 438,
    "prompt_tokens_details": {
      "cached_tokens": 256
    },
    "completion_tokens_details": {
      "reasoning_tokens": 14,
      "audio_tokens": 0,
      "accepted_prediction_tokens": 0,
      "rejected_prediction_tokens": 0
    }
  },
  "service_tier": "default"
}

注意事项

  • 回传 reasoning_content:DeepSeek 官方要求带 tools 时,历史 assistant 消息里的 reasoning_content 必须完整回传,漏传返回 400。我们接入的 deepseek-v4.1-flash 上游实测漏传不报错(第二轮去掉 reasoning_content 照常返回),但这是上游的宽松行为,不是承诺;建议始终回传,平台会把历史里的 reasoning_content 原样转发。Anthropic 格式下历史里的 thinking 内容块也会被转成 reasoning_content。
  • 强制工具调用:官方 API 在思考模式下对 tool_choice: "required" 与指定函数返回 400;deepseek-v4.1-flash 的上游文档写思考模式下支持 required;另两个模型未验证。
  • 这一场景的 usage.prompt_tokens_details.cached_tokens 在第二轮出现了 256,说明前缀命中了自动缓存。

JSON 输出

证据:已实测(线上测试账号,2026-10-19),deepseek-v4.1-flash,关闭思考。

何时用:需要稳定、可直接解析的 JSON,例如信息抽取。设置 response_format: {"type": "json_object"},提示词里必须出现 “json” 一词并给出期望格式的样例。

请求

import json
from openai import OpenAI

client = OpenAI(base_url="https://api.modelsite.ai/v1", api_key="sk-ms-xxxxxxxx")

system_prompt = """Parse the question and answer from the exam text and output them as JSON.
Example input: "Which is the highest mountain? Mount Everest."
Example JSON: {"question": "Which is the highest mountain?", "answer": "Mount Everest"}"""

resp = client.chat.completions.create(
    model="deepseek-v4.1-flash",
    messages=[
        {"role": "system", "content": system_prompt},
        {"role": "user", "content": "Which is the longest river in the world? The Nile River."},
    ],
    response_format={"type": "json_object"},
    max_tokens=512,
    extra_body={"thinking": {"type": "disabled"}},
)
print(json.loads(resp.choices[0].message.content))

响应

{
  "id": "xxxxxxxx",
  "object": "chat.completion",
  "created": 1760000000,
  "model": "deepseek-v4.1-flash",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "{\"question\": \"Which is the longest river in the world?\", \"answer\": \"The Nile River\"}",
        "refusal": null
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 89,
    "completion_tokens": 21,
    "total_tokens": 110,
    "prompt_tokens_details": {
      "cached_tokens": 0
    },
    "completion_tokens_details": {
      "reasoning_tokens": 0,
      "audio_tokens": 0,
      "accepted_prediction_tokens": 0,
      "rejected_prediction_tokens": 0
    }
  },
  "service_tier": "default"
}

注意事项

  • max_tokens 要设得足够大,否则 JSON 可能被截断;官方提示偶尔会返回空内容,代码里要处理空结果。
  • 只用 json_object。json_schema 在上游文档里标为 Beta,各模型支持情况未验证。

前缀续写

证据:已实测(线上测试账号,2026-10-19),仅 deepseek-v4-pro;deepseek-v4.1-flash 与 deepseek-v4-flash-0731 依官方文档(未实测)。

何时用:让模型接着你给的开头往下写,例如强制以代码块开头输出代码。官方把它做成 Beta 功能,要换 https://api.deepseek.com/beta 入口;在 ModelSite 不需要换入口,用同一个 /v1/chat/completions:最后一条消息 role 为 assistant,加 "prefix": true,content 是要续写的开头。

请求

from openai import OpenAI

client = OpenAI(base_url="https://api.modelsite.ai/v1", api_key="sk-ms-xxxxxxxx")

resp = client.chat.completions.create(
    model="deepseek-v4-pro",
    messages=[
        {"role": "user", "content": "Please write quick sort code"},
        {"role": "assistant", "content": "```python\n", "prefix": True},
    ],
    stop=["```"],
    max_tokens=400,
    extra_body={"thinking": {"type": "disabled"}},
)
print(resp.choices[0].message.content)

响应(正文已截断;这次 max_tokens 用完所以 finish_reason 是 length)

{
  "id": "xxxxxxxx",
  "object": "chat.completion",
  "created": 1760000000,
  "model": "deepseek-v4-pro",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "def quick_sort(arr):\n    \"\"\"\n    Quick sort implementation using Lomuto partition scheme.\n    \n    Args:\n        arr: List of comparable elements\n    \n    Retur…",
        "refusal": null
      },
      "finish_reason": "length"
    }
  ],
  "usage": {
    "prompt_tokens": 12,
    "completion_tokens": 400,
    "total_tokens": 412,
    "prompt_tokens_details": {
      "cached_tokens": 0
    },
    "completion_tokens_details": {
      "reasoning_tokens": 0,
      "audio_tokens": 0,
      "accepted_prediction_tokens": 0,
      "rejected_prediction_tokens": 0
    }
  },
  "service_tier": "default"
}

注意事项

  • 判断前缀被采用的依据:不带前缀问同样的问题,模型以「Here's a clean implementation…」这样的说明文字开头;带前缀时直接从代码开始,且输入 token 多出了前缀的部分。响应里只有续写的部分,不含你传的前缀本身。
  • 最后一条消息必须是带 prefix: true 的 assistant 消息。stop 可选,用来在分隔符处截断。
  • 这是 DeepSeek 的 Beta 能力,行为可能变化;只在 deepseek-v4-pro 上实测过。

上下文缓存

证据:已实测(线上测试账号,2026-10-19),deepseek-v4.1-flash。

何时用:多轮对话、同一份长文档反复提问。缓存自动开启,没有请求参数,命中是尽力而为,不保证 100%;只缓存输入前缀。把不变的内容(系统提示、文档)放在前面,变化的内容放在后面,才能命中。

怎么看是否命中:响应 usage.prompt_tokens_details.cached_tokens。例如上面「思考 + 工具调用」第二轮响应里 prompt_tokens 为 378,其中 cached_tokens 为 256。

注意事项

  • deepseek-v4.1-flash 的上游文档写隐式缓存最少 256 token,缓存构建需要数秒。
  • DeepSeek 官方另给 prompt_cache_hit_tokens / prompt_cache_miss_tokens;实测响应里没有这两个字段,以 cached_tokens 为准。
  • 请求里内容块上的 cache_control 标记对 DeepSeek 无效,平台会在转发前去掉,不要使用。

图片输入

证据:已实测(线上测试账号,2026-10-19),仅 deepseek-v4.1-flash;其余两个模型未实测。

三个模型在平台上的能力标签都不含 vision,平台没有把 DeepSeek 作为视觉模型开通,所以这一场景只能算「部分支持」:

  • deepseek-v4.1-flash:用一张纯红色 64x64 PNG 实测,模型能正确回答颜色,响应正常、没有报错。但这是上游的行为,平台没有承诺,图片输入的计费口径也没有单独核对,不建议用于生产。
  • deepseek-v4-pro:官方不支持图片,未实测。
  • deepseek-v4-flash-0731:模型库标注不支持视觉,未实测。

需要稳定的图片理解,请选能力标签含 vision 的模型(见 Qwen 页)。

Anthropic 格式

证据:已实测(线上测试账号,2026-10-19),deepseek-v4-pro。

何时用:你的客户端是 Anthropic SDK 或 Claude Code 之类,只能说 /v1/messages。调用方式与鉴权见 Messages 页(SDK 用 auth_token,不是 api_key)。

请求

from anthropic import Anthropic

client = Anthropic(base_url="https://api.modelsite.ai", auth_token="sk-ms-xxxxxxxx")

resp = client.messages.create(
    model="deepseek-v4-pro",
    max_tokens=1500,
    thinking={"type": "enabled", "budget_tokens": 1024},
    messages=[{"role": "user", "content": "9.11 和 9.9 哪个大?一句话回答。"}],
)
for block in resp.content:
    if block.type == "thinking":
        print("思考:", block.thinking)
    elif block.type == "text":
        print("回答:", block.text)

响应

{
  "id": "msg_xxxx",
  "type": "message",
  "role": "assistant",
  "content": [
    {
      "type": "thinking",
      "thinking": "我们需要回答用户中文问题“9.11 和 9.9 哪个大?一句话回答。”需要一句话。注意陷阱?9.11和9.9作为数字比较,9.9大。但要注意可能是日期?但通常数字。用户要求一句话回答。我们可以说“9.9更大。”需要一句话。确保不要解释太多。用中文。"
    },
    {
      "type": "text",
      "text": "9.9 更大。"
    }
  ],
  "model": "deepseek-v4-pro",
  "stop_reason": "end_turn",
  "stop_sequence": null,
  "usage": {
    "input_tokens": 20,
    "output_tokens": 84,
    "reasoning_tokens": 77
  }
}

注意事项

  • budget_tokens 不是硬预算:官方 Anthropic 兼容文档写明它被忽略。要控制强度,在请求体里直接加顶层字段 reasoning_effort(Python SDK 用 extra_body),平台原样转发。关闭思考用 thinking: {"type": "disabled"}。
  • 返回里的思考过程以 thinking 内容块给出;usage.reasoning_tokens 是思考 token 数。
  • top_k 会被转发,上游忽略;stop_sequences 对应 stop;metadata.user_id 对应 user。

参数速查

参数说明
thinkingenabled / disabled;auto 原样转发但 DeepSeek 只认前两者;adaptive 不转发
reasoning_effort只用 low / high / max
max_tokens / max_completion_tokens平台不改写、不注入默认值;两个都传时只转发 max_completion_tokens
temperature、top_p思考模式下基本不生效,见思考模式
frequency_penalty、presence_penalty不要传(deepseek-v4.1-flash 上游写明不支持)
stop最多 16 个字符串(deepseek-v4.1-flash 上游文档;其余按官方,未验证)
logprobs、top_logprobs上游文档写支持,top_logprobs 最大 20;未实测
stream_options.include_usage流式没传时网关自动加
response_formattext / json_object;json_schema 未验证
n(大于 1)、service_tier、store、metadata、user_id 等原样转发,上游是否识别未验证
未知顶层字段、extra_body 里的键原样平铺转发
developer 角色转为 system

其他:reasoning 对象(OpenRouter 风格,reasoning.effort、reasoning.exclude 等)由平台自己处理;reasoning.exclude: true 或 include_reasoning: false 会在响应里去掉思考内容,思考 token 仍计费。

官方文档

本页内容