跳至主要內容

v1/messages → /responses 參數對照

當您向 /v1/messages 傳送針對 OpenAI 或 Azure 模型的請求時,LiteLLM 會在內部透過 OpenAI Responses API 路由。此頁面 دقیق說明每個參數在雙向之間如何轉換。

轉換邏輯位於 litellm/llms/anthropic/experimental_pass_through/responses_adapters/transformation.py

請求:Anthropic → Responses API

頂層參數

Anthropic (/v1/messages)Responses API備註
modelmodel原樣傳遞
messagesinput結構上已轉換 — 請見下方 messages 區段
system (string)instructions作為純字串傳遞
system (list of content blocks)instructions文字區塊會以 \n 串接;非文字區塊會被忽略
max_tokensmax_output_tokens已重新命名
temperaturetemperature原樣傳遞
top_ptop_p原樣傳遞
toolstools格式已轉換 — 請見下方 tools 區段
tool_choicetool_choice型別已重新對應 — 請見下方 tool_choice 區段
thinkingreasoning預算 tokens 對應為 effort 等級 — 請見下方 thinking 區段
output_format or output_config.formattext包裝為 {"format": {"type": "json_schema", "name": "structured_output", "schema": ..., "strict": true}}
context_managementcontext_management從 Anthropic dict 轉換為 OpenAI array 格式 — 請見下方 context_management 區段
metadata.user_iduser從 metadata 物件中擷取並截斷為 64 個字元
stop_sequences❌ 未對應靜默捨棄
top_k❌ 未對應靜默捨棄
speed❌ 未對應僅用於在原生路徑上設定 Anthropic beta 標頭

messages 如何轉換

每個 Anthropic message 都會展開為一個或多個 Responses API input item。關鍵差異在於 tool_resulttool_use 區塊會成為 input 陣列中的頂層項目,而不是巢狀在 message 內。

Anthropic messageResponses API input item
user role, string content{"type": "message", "role": "user", "content": [{"type": "input_text", "text": "..."}]}
user role, {"type": "text"} block位於 user message 內的 {"type": "input_text", "text": "..."}
user role, {"type": "image", "source": {"type": "base64"}}位於 user message 內的 {"type": "input_image", "image_url": "data:<media_type>;base64,<data>"}
user role, {"type": "image", "source": {"type": "url"}}位於 user message 內的 {"type": "input_image", "image_url": "<url>"}
user role, {"type": "tool_result"} block頂層 {"type": "function_call_output", "call_id": "...", "output": "..."} — 完全從 message 中取出
assistant role, string content{"type": "message", "role": "assistant", "content": [{"type": "output_text", "text": "..."}]}
assistant role, {"type": "text"} block位於 assistant message 內的 {"type": "output_text", "text": "..."}
assistant role, {"type": "tool_use"} block頂層 {"type": "function_call", "call_id": "<id>", "name": "...", "arguments": "<JSON string>"} — 完全從 message 中取出
assistant role, {"type": "thinking"} block位於 assistant message 內的 {"type": "output_text", "text": "<thinking text>"}

tools

Anthropic toolResponses API tool
任何 type"web_search"name == "web_search" 開頭的 tool{"type": "web_search_preview"}
其他所有 tools{"type": "function", "name": "...", "description": "...", "parameters": <input_schema>}

tool_choice

Anthropic tool_choice.typeResponses API tool_choice
"auto"{"type": "auto"}
"any"{"type": "required"}
"tool"{"type": "function", "name": "<tool name>"}

thinking → reasoning

budget_tokens 值會對應到字串 effort 等級。summary 一律設為 "detailed"

thinking.budget_tokensreasoning.effort
>= 10000"high"
>= 5000"medium"
>= 2000"low"
< 2000"minimal"

如果 thinking.type 不是 "enabled" 以外的任何值,則完全不會傳送 reasoning 欄位。

context_management

Anthropic 使用帶有 edits 陣列的巢狀 dict。OpenAI 使用扁平的 compaction objects 陣列。

Anthropic input:
{
"edits": [
{
"type": "compact_20260112",
"trigger": {"type": "input_tokens", "value": 150000}
}
]
}

Responses API output:
[
{"type": "compaction", "compact_threshold": 150000}
]

回應:Responses API → Anthropic

當 Responses API 回覆返回時,LiteLLM 會將其轉換為 Anthropic AnthropicMessagesResponse

Responses API 欄位Anthropic 回應欄位備註
response.idid
response.modelmodel若缺少則回退至 "unknown-model"
ResponseReasoningItemsummary[*].textcontent 區塊 {"type": "thinking", "thinking": "..."}每個非空的 summary text 都會成為 thinking 區塊
ResponseOutputMessagecontent[*] where type == "output_text"content 區塊 {"type": "text", "text": "..."}
ResponseFunctionToolCall{call_id, name, arguments}content 區塊 {"type": "tool_use", "id": "...", "name": "...", "input": {...}}arguments 會重新以 JSON 解析回 dict
輸出中存在的任何 function_callstop_reason: "tool_use"
response.status == "incomplete"stop_reason: "max_tokens"優先於預設值
其他全部stop_reason: "end_turn"預設值
response.usage.input_tokensusage.input_tokens
response.usage.output_tokensusage.output_tokens
(hardcoded)type: "message"一律設定
(hardcoded)role: "assistant"一律設定
(hardcoded)stop_sequence: null在此路徑上一律為 null
🚅
LiteLLM Enterprise
為正式環境打造的 SSO/SAML、稽核記錄、支出追蹤、多團隊管理與防護欄。
深入瞭解 →