Loading...
    • 开发者指南
    • API 参考
    • MCP
    • 资源
    • 发布说明
    Search...
    ⌘K
    快速开始
    Claude 简介快速入门
    模型与定价
    模型概览选择模型Claude 4.5 新功能迁移到 Claude 4.5模型弃用定价
    使用 Claude 构建
    功能概览使用 Messages API上下文窗口提示词最佳实践
    能力
    提示词缓存上下文编辑扩展思考工作量流式消息批量处理引用多语言支持Token 计数嵌入视觉PDF 支持Files API搜索结果结构化输出Google Sheets 插件
    工具
    概览如何实现工具使用Token 高效的工具使用细粒度工具流式处理Bash 工具代码执行工具程序化工具调用计算机使用工具文本编辑器工具Web 获取工具Web 搜索工具内存工具工具搜索工具
    Agent 技能
    概览快速入门最佳实践在 API 中使用技能
    Agent SDK
    概览TypeScript SDKPython SDK迁移指南
    指南
    流式输入处理权限会话管理SDK 中的结构化输出托管 Agent SDK修改系统提示词SDK 中的 MCP自定义工具SDK 中的子 AgentSDK 中的斜杠命令SDK 中的 Agent 技能跟踪成本和使用情况待办事项列表SDK 中的插件
    API 中的 MCP
    MCP 连接器远程 MCP 服务器
    第三方平台上的 Claude
    Amazon BedrockMicrosoft FoundryVertex AI
    提示词工程
    概览提示词生成器使用提示词模板提示词改进器清晰直接使用示例(多轮提示)让 Claude 思考(CoT)使用 XML 标签给 Claude 一个角色(系统提示词)预填充 Claude 的响应链接复杂提示词长上下文提示扩展思考提示
    测试与评估
    定义成功标准开发测试用例使用评估工具降低延迟
    加强防护栏
    减少幻觉提高输出一致性缓解越狱流式拒绝减少提示词泄露保持 Claude 的角色
    管理和监控
    Admin API 概览使用和成本 APIClaude Code 分析 API
    Console
    Log in
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...

    Solutions

    • AI agents
    • Code modernization
    • Coding
    • Customer support
    • Education
    • Financial services
    • Government
    • Life sciences

    Partners

    • Amazon Bedrock
    • Google Cloud's Vertex AI

    Learn

    • Blog
    • Catalog
    • Courses
    • Use cases
    • Connectors
    • Customer stories
    • Engineering at Anthropic
    • Events
    • Powered by Claude
    • Service partners
    • Startups program

    Company

    • Anthropic
    • Careers
    • Economic Futures
    • Research
    • News
    • Responsible Scaling Policy
    • Security and compliance
    • Transparency

    Learn

    • Blog
    • Catalog
    • Courses
    • Use cases
    • Connectors
    • Customer stories
    • Engineering at Anthropic
    • Events
    • Powered by Claude
    • Service partners
    • Startups program

    Help and security

    • Availability
    • Status
    • Support
    • Discord

    Terms and policies

    • Privacy policy
    • Responsible disclosure policy
    • Terms of service: Commercial
    • Terms of service: Consumer
    • Usage policy
    工具

    令牌高效的工具使用

    从 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。

    为了保持提示缓存的优势,请为您想要缓存的请求一致地使用测试版标头。如果您选择性地使用它,提示缓存将失败。