DeepSeek V4.1 Flash INTL API 接入教程
通过 Chat Completions、Responses 和 Messages 完成文本对话、文档分析、结构化提取与工具调用。
接入准备
使用 APIMaster API Key,模型 ID 填 deepseek-v4.1-flash-intl,请求体为 JSON,输入为文本。三个接口都支持同步调用和 SSE 流式输出。
| 协议 | 路径 | 成功结束标记 |
|---|---|---|
| Chat Completions | POST /v1/chat/completions |
[DONE] |
| Responses | POST /v1/responses |
response.completed |
| Messages | POST /v1/messages |
message_stop |
在 Claude Code 中使用
Claude Code 可能会发送 thinking.type: adaptive,而此模型的 Messages 接口会因此返回 400 invalid_parameter。打开 ~/.claude/settings.json,把下面的设置合并到现有的 env 对象中。如果还没有 env,请新增它。
{
"env": {
"CLAUDE_CODE_DISABLE_THINKING": "1"
}
}
这项设置让 Claude Code 在请求中省略 thinking,模型会按服务默认行为运行。保存后重新启动 Claude Code,并使用你的 APIMaster 连接配置运行以下命令。
claude --model deepseek-v4.1-flash-intl
使用场景
- 聊天与客服。用 Chat Completions 传递多轮对话,把系统指令放在第一条消息。
- 信息提取与分类。用 Chat 的 JSON 模式或 Responses 的 JSON Schema,返回应用可校验的字段。
- 文档分析与代码辅助。用 Responses 分别提交待处理文本和指令。需要多步推导时可开启思考。
- 调用业务工具。按所选协议声明函数。应用先校验参数,再执行函数,并带上对应调用 ID 回传结果。
请求参数
Chat Completions
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
model |
string |
是 | 每个请求都填 deepseek-v4.1-flash-intl。 |
messages |
array |
是 | 至少一条文本消息。Chat 把系统消息放在第一条,Messages 把系统指令放在顶层 system 字段。 |
messages[].role |
string |
是 | system / user / assistant / tool |
messages[].content |
string / array / null |
否 | text / null + tool_calls |
messages[].tool_call_id |
string |
否 | role: tool → tool_calls[].id |
max_tokens |
integer |
否 | 正整数输出上限。Messages 必填,开启思考时须大于思考预算。 |
stream |
boolean |
否 | true 开启 SSE,false 返回 JSON。切换模式时建议显式传值。 |
temperature |
number |
否 | 采样温度。Chat 和 Responses 接受 0 ≤ temperature < 2,Messages 接受 0 ≤ temperature ≤ 2。 |
top_p |
number |
否 | 核采样范围为 0 < top_p ≤ 1。省略采样参数时使用服务默认值。 |
top_k |
integer |
否 | Chat 和 Messages 的候选数量。填正整数,省略时使用默认值。 |
frequency_penalty, presence_penalty |
number |
否 | Chat 的频率惩罚和存在惩罚各自取值范围为 -2 至 2。 |
stop |
string / string[] |
否 | Chat 接受单个停止字符串或字符串数组。Messages 使用 stop_sequences 字符串数组。 |
reasoning_effort |
string |
否 | Chat 用 reasoning_effort,Responses 用 reasoning.effort。none 关闭思考,启用时可先用 medium。 none, minimal, low, medium, high, xhigh, max. |
tools |
array |
否 | 声明函数。Chat 把定义放在 function 内,Responses 把 name、description、parameters 放在函数项顶层,Messages 使用 input_schema。 |
tool_choice |
string / object |
否 | 自动选工具,或按当前协议的结构指定工具名。 auto / {"type":"function","function":{"name":"lookup"}} |
response_format |
object |
否 | 选择 JSON 对象或 JSON Schema 模式。使用 JSON 对象模式时,在提示词中明确要求 JSON 输出。 type: json_object / type: json_schema → json_schema.name, json_schema.schema |
stream_options.include_usage |
boolean |
否 | true → usage |
seed |
integer |
否 | seed: 42 |
n |
integer |
否 | n: 1 |
logprobs |
boolean |
否 | true → choices[].logprobs |
user |
string |
否 | 传递用户标识时使用不含个人身份信息的 ID。 |
Chat 只允许一个候选(n: 1),随机种子尽力复现。通过 logprobs 请求 token 对数概率,请省略 top_logprobs。流式调用可在 stream_options 中设置 include_usage: true,并在 [DONE] 前读取用量帧。
Responses
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
model |
string |
是 | 每个请求都填 deepseek-v4.1-flash-intl。 |
input |
string / array |
是 | 用户文本或标准 Responses 输入项数组。系统指令放在 instructions。 |
instructions |
string |
否 | instructions → input |
max_output_tokens |
integer |
否 | 为 Responses 显式设置输出上限时填不小于 16 的整数。 |
stream |
boolean |
否 | true 开启 SSE,false 返回 JSON。切换模式时建议显式传值。 |
temperature |
number |
否 | 采样温度。Chat 和 Responses 接受 0 ≤ temperature < 2,Messages 接受 0 ≤ temperature ≤ 2。 |
top_p |
number |
否 | 核采样范围为 0 < top_p ≤ 1。省略采样参数时使用服务默认值。 |
reasoning.effort |
string |
否 | Chat 用 reasoning_effort,Responses 用 reasoning.effort。none 关闭思考,启用时可先用 medium。 none, minimal, low, medium, high, xhigh, max. |
tools |
array |
否 | 声明函数。Chat 把定义放在 function 内,Responses 把 name、description、parameters 放在函数项顶层,Messages 使用 input_schema。 |
tool_choice |
string / object |
否 | 自动选工具,或按当前协议的结构指定工具名。 auto / {"type":"function","name":"lookup"} |
text.format |
object |
否 | 选择 JSON 对象或 JSON Schema 模式。使用 JSON 对象模式时,在提示词中明确要求 JSON 输出。 type: json_object / type: json_schema → name, schema |
metadata |
object |
否 | 可选元数据对象。传递用户标识时使用不含个人身份信息的 ID。 |
Responses 提供创建和流式生成。请由应用维护上下文,使用本页列出的 Responses 字段,并省略 stop、stop_sequences、top_k、frequency_penalty 和 presence_penalty。
Messages
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
model |
string |
是 | 每个请求都填 deepseek-v4.1-flash-intl。 |
messages |
array |
是 | 至少一条文本消息。Chat 把系统消息放在第一条,Messages 把系统指令放在顶层 system 字段。 |
messages[].role |
string |
是 | user / assistant |
messages[].content |
string / array |
是 | text / tool_use / tool_result |
max_tokens |
integer |
是 | 正整数输出上限。Messages 必填,开启思考时须大于思考预算。 |
system |
string / array |
否 | system → messages. |
thinking |
object |
否 | Messages 用 {"type":"enabled","budget_tokens":1024} 并提供整数 budget_tokens,至少为 1024 且小于 max_tokens,关闭时用 {"type":"disabled"}。省略时使用服务默认值。 |
stream |
boolean |
否 | true 开启 SSE,false 返回 JSON。切换模式时建议显式传值。 |
temperature |
number |
否 | 采样温度。Chat 和 Responses 接受 0 ≤ temperature < 2,Messages 接受 0 ≤ temperature ≤ 2。 |
top_p |
number |
否 | 核采样范围为 0 < top_p ≤ 1。省略采样参数时使用服务默认值。 |
top_k |
integer |
否 | Chat 和 Messages 的候选数量。填正整数,省略时使用默认值。 |
stop_sequences |
string[] |
否 | Chat 接受单个停止字符串或字符串数组。Messages 使用 stop_sequences 字符串数组。 |
tools |
array |
否 | 声明函数。Chat 把定义放在 function 内,Responses 把 name、description、parameters 放在函数项顶层,Messages 使用 input_schema。 |
tool_choice |
object |
否 | 自动选工具,或按当前协议的结构指定工具名。 {"type":"auto"} / {"type":"tool","name":"lookup"} |
metadata.user_id |
string |
否 | 传递用户标识时使用不含个人身份信息的 ID。 |
每个请求只传一种思考控制。Messages 使用上面的开关形式,请省略 adaptive 和 output_config.effort。
可复制的请求示例
三种调用均使用 Authorization: Bearer $APIMASTER_API_KEY。Messages 另加 anthropic-version: 2023-06-01 请求头。先在终端设置环境变量,再运行示例。
export APIMASTER_API_KEY="YOUR_APIMASTER_API_KEY"
Chat Completions
curl --fail-with-body 'https://apimaster.ai/v1/chat/completions' \
-H "Authorization: Bearer $APIMASTER_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"model": "deepseek-v4.1-flash-intl",
"messages": [
{
"role": "system",
"content": "Return a JSON object with category and priority."
},
{
"role": "user",
"content": "Ticket: My invoice link expired. Please send a new one."
}
],
"max_tokens": 256,
"reasoning_effort": "none",
"response_format": {
"type": "json_object"
},
"stream": false
}'
Responses
curl --fail-with-body --no-buffer 'https://apimaster.ai/v1/responses' \
-H "Authorization: Bearer $APIMASTER_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"model": "deepseek-v4.1-flash-intl",
"instructions": "Summarize in two bullets. Preserve dates and owners.",
"input": "On May 12, Leila will publish the migration checklist. On May 19, Arun will review rollback tests.",
"max_output_tokens": 256,
"reasoning": {
"effort": "none"
},
"stream": true
}'
Messages
curl --fail-with-body 'https://apimaster.ai/v1/messages' \
-H "Authorization: Bearer $APIMASTER_API_KEY" \
-H 'Content-Type: application/json' \
-H 'anthropic-version: 2023-06-01' \
-d '{
"model": "deepseek-v4.1-flash-intl",
"system": "Write a concise, friendly support reply.",
"messages": [
{
"role": "user",
"content": "Explain how to download my invoice again."
}
],
"max_tokens": 256,
"thinking": {
"type": "disabled"
},
"stream": false
}'
读取响应
三种协议分别从 choices[].message.content、output[].content[] 中 type 为 output_text 的项,以及 content[].text 读取文本。
| 协议 | 说明 | 成功结束标记 |
|---|---|---|
| Chat Completions | choices[].delta.content |
[DONE] |
| Responses | response.output_text.delta → delta |
response.completed |
| Messages | content_block_delta → delta.text |
message_stop |
流式调用应拼接文本增量并等待对应的终止事件。Responses 的 response.incomplete 需要单独处理,并查看 incomplete_details,错误事件或结束前断流视为未完成。心跳注释可以忽略。Messages 的累计用量以最新一条为准。
工具执行后,按协议回传 Chat 的 {"role":"tool","tool_call_id":"...","content":"..."}、Responses 的 {"type":"function_call_output","call_id":"...","output":"..."} 或 Messages 的 {"type":"tool_result","tool_use_id":"...","content":"..."},关联原调用 ID,再请求下一步回答。
遇到 400 时检查协议字段和采样或思考限制,401 时检查 APIMaster Key,429 时降低并发并退避。
用量与计费
未命中缓存的输入、缓存读取和输出分别计费。Chat 的 usage.prompt_tokens 和 Responses 的 usage.input_tokens 已含缓存输入,计算未命中输入时先减去缓存读取量。Messages 的 usage.input_tokens 已排除 cache_read_input_tokens。Chat 即使最后一帧的 choices 为空,也要读取用量。
每天按 UTC 计价,高峰 00:00–14:00,低峰 14:00–24:00。实时价格以模型卡片为准。
