從 Claude Sonnet 3.7 開始,Claude 能夠以代幣高效的方式呼叫工具。請求平均節省 14% 的輸出代幣,最高可達 70%,這也降低了延遲。確切的代幣減少量和延遲改進取決於整體回應形狀和大小。
代幣高效工具使用是一項測試版功能,僅適用於 Claude 3.7 Sonnet。要使用此測試版功能,請在工具使用請求中新增測試版標頭 token-efficient-tools-2025-02-19。此標頭對其他 Claude 模型沒有影響。所有 Claude 4 模型 預設支援代幣高效工具使用。不需要測試版標頭。
代幣高效工具使用目前不適用於 disable_parallel_tool_use
以下是如何在 Claude Sonnet 3.7 中使用 API 的代幣高效工具的範例:
curl https://api.anthropic.com/v1/messages \
  -H "content-type: application/json" \
  -H "x-api-key: $ANTHROPIC_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "anthropic-beta: token-efficient-tools-2025-02-19" \
  -d '{
    "model": "claude-3-7-sonnet-20250219",
    "max_tokens": 1024,
    "tools": [
      {
        "name": "get_weather",
        "description": "Get the current weather in a given location",
        "input_schema": {
          "type": "object",
          "properties": {
            "location": {
              "type": "string",
              "description": "The city and state, e.g. San Francisco, CA"
            }
          },
          "required": [
            "location"
          ]
        }
      }
    ],
    "messages": [
      {
        "role": "user",
        "content": "Tell me the weather in San Francisco."
      }
    ]
  }' | jq '.usage'
上述請求平均應該使用比正常請求更少的輸入和輸出代幣。要確認這一點,請嘗試發出相同的請求,但從測試版標頭列表中移除 token-efficient-tools-2025-02-19
為了保持提示快取的優勢,請對您想要快取的請求一致地使用測試版標頭。如果您選擇性地使用它,提示快取將失敗。