APIMaster.ai

DeepSeek V4.1 Flash INTL API 串接教學

透過 Chat Completions、Responses 和 Messages 完成文字對話、文件分析、結構化擷取與工具呼叫。

串接準備

使用 APIMaster API 金鑰,模型 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 API 會因此回傳 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 否 使用者識別碼宜使用不含個資的代碼。

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 否 選用的中繼資料物件。使用者識別碼宜使用不含個資的代碼。

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 否 使用者識別碼宜使用不含個資的代碼。

每個請求只傳一種思考控制。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":"..."},帶上呼叫識別碼,再請求下一步回應。

出現 400 時檢查欄位和取樣、思考限制,401 時查核金鑰,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。即時價格見模型卡片。