Loading...
    • Guia do Desenvolvedor
    • Referência da API
    • MCP
    • Recursos
    • Notas de Lançamento
    Search...
    ⌘K

    Primeiros passos

    introget-started

    Modelos e preços

    overviewchoosing-a-modelwhats-new-claude-4-5migrating-to-claude-4model-deprecationspricing

    Criar com Claude

    overviewworking-with-messagescontext-windowsclaude-4-best-practices

    Capacidades

    prompt-cachingcontext-editingextended-thinkingstreamingbatch-processingcitationsmultilingual-supporttoken-countingembeddingsvisionpdf-supportfilessearch-resultsclaude-for-sheets

    Ferramentas

    overviewimplement-tool-usetoken-efficient-tool-usefine-grained-tool-streamingbash-toolcode-execution-toolcomputer-use-tooltext-editor-toolweb-fetch-toolweb-search-toolmemory-tool

    Habilidades do Agente

    overviewquickstartbest-practicesskills-guide

    SDK do Agente

    overviewtypescriptpython

    Guias

    streaming-vs-single-modepermissionssessionshostingmodifying-system-promptsmcpcustom-toolssubagentsslash-commandsskillscost-trackingtodo-trackingplugins

    MCP na API

    mcp-connectorremote-mcp-servers

    Claude em plataformas de terceiros

    claude-on-amazon-bedrockclaude-on-vertex-ai

    Engenharia de prompts

    overviewprompt-generatorprompt-templates-and-variablesprompt-improverbe-clear-and-directmultishot-promptingchain-of-thoughtuse-xml-tagssystem-promptsprefill-claudes-responsechain-promptslong-context-tipsextended-thinking-tips

    Testar e avaliar

    define-successdevelop-testseval-toolreduce-latency

    Fortalecer proteções

    reduce-hallucinationsincrease-consistencymitigate-jailbreakshandle-streaming-refusalsreduce-prompt-leakkeep-claude-in-character

    Administração e monitoramento

    administration-apiusage-cost-apiclaude-code-analytics-api
    Console
    Ferramentas

    Uso eficiente de tokens em ferramentas

    A partir do Claude Sonnet 3.7, Claude é capaz de chamar ferramentas de forma eficiente em tokens. As solicitações economizam em média 14% em tokens de saída, chegando a 70%, o que também reduz a latência. A redução exata de tokens e as melhorias de latência dependem da forma e tamanho geral da resposta.

    O uso eficiente de tokens em ferramentas é um recurso beta que funciona apenas com Claude 3.7 Sonnet. Para usar este recurso beta, adicione o cabeçalho beta token-efficient-tools-2025-02-19 a uma solicitação de uso de ferramentas. Este cabeçalho não tem efeito em outros modelos Claude.

    Todos os modelos Claude 4 suportam uso eficiente de tokens em ferramentas por padrão. Nenhum cabeçalho beta é necessário.

    O uso eficiente de tokens em ferramentas atualmente não funciona com disable_parallel_tool_use.

    Aqui está um exemplo de como usar ferramentas eficientes em tokens com a API no Claude Sonnet 3.7:

    Shell
    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'
    Python
    import anthropic
    
    client = anthropic.Anthropic()
    
    response = client.beta.messages.create(
        max_tokens=1024,
        model="claude-3-7-sonnet-20250219",
        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."
        }],
        betas=["token-efficient-tools-2025-02-19"]
    )
    
    print(response.usage)
    TypeScript
    import Anthropic from '@anthropic-ai/sdk';
    
    const anthropic = new Anthropic();
    
    const message = await anthropic.beta.messages.create({
      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." 
      }],
      betas: ["token-efficient-tools-2025-02-19"]
    });
    
    console.log(message.usage);
    Java
    import java.util.List;
    import java.util.Map;
    
    import com.anthropic.client.AnthropicClient;
    import com.anthropic.client.okhttp.AnthropicOkHttpClient;
    import com.anthropic.core.JsonValue;
    import com.anthropic.models.beta.messages.BetaMessage;
    import com.anthropic.models.beta.messages.BetaTool;
    import com.anthropic.models.beta.messages.MessageCreateParams;
    
    import static com.anthropic.models.beta.AnthropicBeta.TOKEN_EFFICIENT_TOOLS_2025_02_19;
    
    public class TokenEfficientToolsExample {
    
        public static void main(String[] args) {
            AnthropicClient client = AnthropicOkHttpClient.fromEnv();
    
            BetaTool.InputSchema schema = BetaTool.InputSchema.builder()
                    .properties(JsonValue.from(Map.of(
                            "location",
                            Map.of(
    "type", "string",
    "description", "The city and state, e.g. San Francisco, CA"
                            )
                    )))
                    .putAdditionalProperty("required", JsonValue.from(List.of("location")))
                    .build();
    
            MessageCreateParams params = MessageCreateParams.builder()
                    .model("claude-3-7-sonnet-20250219")
                    .maxTokens(1024)
                    .betas(List.of(TOKEN_EFFICIENT_TOOLS_2025_02_19))
                    .addTool(BetaTool.builder()
                            .name("get_weather")
                            .description("Get the current weather in a given location")
                            .inputSchema(schema)
                            .build())
                    .addUserMessage("Tell me the weather in San Francisco.")
                    .build();
    
            BetaMessage message = client.beta().messages().create(params);
            System.out.println(message.usage());
        }
    }

    A solicitação acima deve, em média, usar menos tokens de entrada e saída do que uma solicitação normal. Para confirmar isso, tente fazer a mesma solicitação, mas remova token-efficient-tools-2025-02-19 da lista de cabeçalhos beta.

    Para manter os benefícios do cache de prompt, use o cabeçalho beta consistentemente para solicitações que você gostaria de armazenar em cache. Se você usá-lo seletivamente, o cache de prompt falhará.

      © 2025 ANTHROPIC PBC

      Products

      • Claude
      • Claude Code
      • Max plan
      • Team plan
      • Enterprise plan
      • Download app
      • Pricing
      • Log in

      Features

      • Claude and Slack
      • Claude in Excel

      Models

      • Opus
      • Sonnet
      • Haiku

      Solutions

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

      Claude Developer Platform

      • Overview
      • Developer docs
      • Pricing
      • Amazon Bedrock
      • Google Cloud’s Vertex AI
      • Console login

      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

      Help and security

      • Availability
      • Status
      • Support center

      Terms and policies

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

      Products

      • Claude
      • Claude Code
      • Max plan
      • Team plan
      • Enterprise plan
      • Download app
      • Pricing
      • Log in

      Features

      • Claude and Slack
      • Claude in Excel

      Models

      • Opus
      • Sonnet
      • Haiku

      Solutions

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

      Claude Developer Platform

      • Overview
      • Developer docs
      • Pricing
      • Amazon Bedrock
      • Google Cloud’s Vertex AI
      • Console login

      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

      Help and security

      • Availability
      • Status
      • Support center

      Terms and policies

      • Privacy policy
      • Responsible disclosure policy
      • Terms of service: Commercial
      • Terms of service: Consumer
      • Usage policy
      © 2025 ANTHROPIC PBC