
Claude API Tool Use 是什麼?依照 Anthropic 官方文件,Tool Use(也稱 function calling)讓 Claude 可以呼叫你定義的函式,或呼叫 Anthropic 提供的工具。Claude 會依使用者的需求與工具描述,判斷是否該用工具,然後回傳一個結構化的呼叫,由你的程式(客戶端工具)或 Anthropic 的伺服器(伺服器端工具)執行。這篇文章整理工具呼叫的 4 個步驟、兩種工具的差異、官方提醒的限制,以及額外的 token 計費。資料為 2026 年 11 月查閱的官方文件,工具版本與模型支援更新很快,請以官方最新文件為準。基本請求格式可先看Claude API 教學。
tools 參數描述工具(名稱、說明、input_schema);Claude 回傳 stop_reason: "tool_use" 與 tool_use 區塊;你執行後用 tool_result 區塊把結果送回;Claude 再用結果回答。伺服器端工具(如 web_search)則由 Anthropic 代為執行。
本篇文章大綱
工具呼叫的 4 個步驟
官方用 get_weather 範例說明客戶端工具的來回流程:
- 定義工具:在
tools放入工具名稱、描述與 JSON Schema 格式的input_schema。 - Claude 要求呼叫:回應的
stop_reason是tool_use,內容裡有tool_use區塊,含id、name與input。 - 你執行並回傳:執行對應函式,把結果放進
tool_result區塊,並帶上tool_use_id,送進下一個user訊息。 - Claude 回答:再次呼叫 API 後,Claude 利用工具結果產生最終回答。
以下 Python 程式碼改寫自官方範例結構:
tools = [{
"name": "get_weather",
"description": "Get the current weather for a given location.",
"input_schema": {
"type": "object",
"properties": {
"location": {"type": "string", "description": "City and state, e.g. San Francisco, CA"}
},
"required": ["location"],
},
}]
messages = [{"role": "user", "content": "What's the weather in San Francisco?"}]
response = client.messages.create(
model="claude-sonnet-5-5", max_tokens=1024, tools=tools, messages=messages,
)
tool_use = next(b for b in response.content if b.type == "tool_use")
result = "15 degrees Celsius, partly cloudy" # 這裡換成你真正的查詢
messages += [
{"role": "assistant", "content": response.content},
{"role": "user", "content": [
{"type": "tool_result", "tool_use_id": tool_use.id, "content": result}
]},
]
final = client.messages.create(
model="claude-sonnet-5-5", max_tokens=1024, tools=tools, messages=messages,
)
print(next(b for b in final.content if b.type == "text").text)官方也提供 tool runner,由 SDK 自動執行工具並送回結果,省去自己寫迴圈。如果對 Python 的基本寫法還不熟,請先看Claude API Python 教學。

客戶端與伺服器端工具
官方依「程式碼在哪裡執行」區分工具:
| 類型 | 誰執行 | 官方列出的例子 |
|---|---|---|
| 你自己定義的工具 | 你的應用程式 | 任何你寫的函式,例如查天氣、查訂單 |
| Anthropic 定義 schema 的客戶端工具 | 你的應用程式 | memory、bash、text editor、computer use、browser use |
| 伺服器端工具 | Anthropic 的基礎設施 | web search、web fetch、code execution、tool search、MCP connector 等 |
伺服器端工具不需要你寫處理程式,結果直接隨回應回來。官方的最小範例是在 tools 放入 {"type": "web_search_20260209", "name": "web_search"},Claude 會在 Anthropic 端完成搜尋並附上引用來源。若要連接 MCP 伺服器,可看Claude API 與 MCP。
免費領取《從零到百萬:新手快速提升行銷收入指南》
學會如何建立一套能 24 小時自動培養名單、自動化成交系統
控制工具使用與官方提醒的限制
預設行為:tool_choice 預設為 {"type": "auto"},每一輪由 Claude 判斷要不要用工具。官方建議用系統提示來調整,例如「先使用工具調查再回答」會增加使用工具的傾向。
嚴格模式:在自訂工具定義加上 strict: true,可確保 Claude 的工具呼叫一定符合你的 schema。
強制呼叫的限制:官方錯誤文件指出,Claude Opus 5.5、Sonnet 5.5、Fable 5.1 不支援強制工具使用;送出 tool_choice: {"type": "any"} 或 {"type": "tool", ...} 會收到 400 錯誤,只接受 auto 與 none。要保持輸入符合 schema,官方建議搭配 strict 模式,需要固定 JSON 格式則用結構化輸出。
缺少參數:官方提醒,若使用者沒提供必填參數,Opus 較可能主動詢問,Sonnet 可能詢問也可能自行推測合理的值,這種行為不保證,所以重要參數應在你的程式端驗證。
平行呼叫:Claude 可能一次回傳多個工具呼叫;官方範例用 disable_parallel_tool_use: True 限制每輪最多一次。
額外的計費
官方說明 Tool Use 依一般 token 計費,額外的 token 來自三處:tools 參數(名稱、描述、schema)、tool_use 區塊,以及 tool_result 區塊。啟用工具時 API 還會自動加入專用的系統提示,Opus 5.5、Sonnet 5.5 與 Haiku 5.5 為 286 個 token(tool_choice 為 auto 或 none 時)。伺服器端工具可能另有按次收費,例如網路搜尋每 1,000 次 10 美元(2026 年 11 月查閱)。完整算法見Claude API 價格怎麼算。

官方沒有說明的部分
- 工具描述怎麼寫才最能提升呼叫準確率,本次查閱的概覽頁只說明要寫清楚,沒有量化數據。
- 同時提供多少個工具後效果會下降,概覽頁沒有給具體數字(官方另有 tool search 工具處理大量工具的情況)。
- 工具執行失敗時的最佳重試策略,概覽頁指向另一頁「handle tool calls」,本文沒有展開。
- 各模型呼叫工具的正確率比較,官方沒有在概覽頁提供。
結論:把 Tool Use 想成「Claude 提需求、你來執行」
Tool Use 的核心是一個來回迴圈:Claude 提出要用哪個工具與參數,你負責執行並回傳結果。先從一個簡單的工具練習,確認 tool_use_id 對應正確,再加上 strict 模式與參數驗證。API 的整體概念可回看Claude API 是什麼。
常見問題 FAQ
Tool Use 與 function calling 一樣嗎?
官方文件說明 Tool Use 也稱為 function calling,指讓 Claude 呼叫你定義或 Anthropic 提供的函式。
Claude 會自己執行我的函式嗎?
不會。客戶端工具由你的程式執行,Claude 只回傳結構化的呼叫。伺服器端工具則由 Anthropic 執行。
可以強制 Claude 一定要用某個工具嗎?
在 Opus 5.5、Sonnet 5.5 與 Fable 5.1,官方說明不支援強制工具使用,送出會得到 400 錯誤。
用工具會多收費嗎?
工具定義與結果會增加 token,並多一段專用系統提示;伺服器端工具可能另有按次費用。
參考資料
- Claude 開發者文件:Tool use with Claude
- Claude 開發者文件:API errors
- Claude 開發者文件:Pricing
- 圖片來源:Christina Morillo、Yan Krukau(Pexels)
想建立 24/7 自動成交的課程獲利系統嗎?
如果你想建立的不只是電子報,而是一套真正能自動幫你成交的內容變現系統,那你可以進一步了解:
《百萬課程獲利藍圖:打造 24/7 幫你自動賣課的印鈔系統》
這套系統會完整分享:
- 如何建立高轉換Email名單
- 如何設計Lead Magnet
- 如何打造Email自動化流程
- 如何透過內容建立穩定現金流
- 如何讓線上課程24小時自動成交
即使沒有大量粉絲,也能透過內容、Email與自動化漏斗,慢慢建立穩定的獲利模式。

