Loading...
    • Guida per sviluppatori
    • Riferimento API
    • MCP
    • Risorse
    • Note di rilascio
    Search...
    ⌘K

    Primi passi

    Introduzione a ClaudeGuida rapida

    Modelli e prezzi

    Panoramica dei modelliScegliere un modelloNovità in Claude 4.5Migrazione a Claude 4.5Deprecazioni dei modelliPrezzi

    Crea con Claude

    Panoramica delle funzionalitàLavorare con l'API MessagesFinestre di contestoMigliori pratiche di prompt engineering

    Capacità

    Caching dei promptModifica del contestoPensiero estesoStreaming dei MessaggiElaborazione batchCitazioniSupporto multilingueConteggio dei tokenEmbeddingsVisioneSupporto PDFFiles APIRisultati di ricercaComponente aggiuntivo di Google Sheets

    Strumenti

    PanoramicaCome implementare l'uso degli strumentiUtilizzo efficiente dei token per gli strumentiStreaming granulare degli strumentiStrumento BashStrumento di esecuzione del codiceStrumento di utilizzo del computerStrumento editor di testoStrumento di recupero webStrumento di ricerca webStrumento memoria

    Competenze Agente

    PanoramicaIniziare con Agent Skills nell'APIMigliori pratiche per la creazione di SkillsUtilizzo di Skills

    Agent SDK

    Panoramica dell'Agent SDKRiferimento SDK Agent - TypeScriptRiferimento SDK Agent - Python

    Guide

    Input in StreamingGestione dei PermessiGestione delle SessioniHosting dell'Agent SDKModifica dei prompt di sistemaMCP nell'SDKStrumenti PersonalizzatiSubagenti nell'SDKComandi Slash nell'SDKAgent Skills nell'SDKTracciamento di Costi e UtilizzoListe TodoPlugin nell'SDK

    MCP nell'API

    Connettore MCPServer MCP remoti

    Claude su piattaforme di terze parti

    Amazon BedrockVertex AI

    Ingegneria dei prompt

    PanoramicaGeneratore di promptUsa template di promptMiglioratore di promptSii chiaro e direttoUsa esempi (prompt multishot)Lascia pensare Claude (CoT)Usa i tag XMLDare un ruolo a Claude (system prompt)Precompila la risposta di ClaudeConcatena prompt complessiSuggerimenti contesto lungoSuggerimenti per il pensiero esteso

    Testa e valuta

    Definisci criteri di successoSviluppare casi di testUtilizzo dello Strumento di ValutazioneRidurre la latenza

    Rafforza le protezioni

    Ridurre le allucinazioniAumentare la coerenza dell'outputMitigare i jailbreakhandle-streaming-refusalsRidurre la fuga di promptMantenere Claude nel personaggio

    Amministrazione e monitoraggio

    Panoramica dell'API AdminAPI di Utilizzo e CostiAPI di analisi del codice Claude
    Console
    Strumenti

    Utilizzo efficiente dei token per gli strumenti

    A partire da Claude Sonnet 3.7, Claude è in grado di chiamare gli strumenti in modo efficiente dal punto di vista dei token. Le richieste risparmiano in media il 14% dei token di output, fino al 70%, il che riduce anche la latenza. La riduzione esatta dei token e i miglioramenti della latenza dipendono dalla forma e dalle dimensioni complessive della risposta.

    L'utilizzo efficiente dei token per gli strumenti è una funzionalità beta che funziona solo con Claude 3.7 Sonnet. Per utilizzare questa funzionalità beta, aggiungi l'intestazione beta token-efficient-tools-2025-02-19 a una richiesta di utilizzo dello strumento. Questa intestazione non ha alcun effetto su altri modelli Claude.

    Tutti i modelli Claude 4 supportano l'utilizzo efficiente dei token per gli strumenti per impostazione predefinita. Non è necessaria alcuna intestazione beta.

    L'utilizzo efficiente dei token per gli strumenti attualmente non funziona con disable_parallel_tool_use.

    Ecco un esempio di come utilizzare gli strumenti efficienti dai token con l'API in 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());
        }
    }

    La richiesta di cui sopra dovrebbe, in media, utilizzare meno token di input e output rispetto a una richiesta normale. Per confermarlo, prova a fare la stessa richiesta ma rimuovi token-efficient-tools-2025-02-19 dall'elenco delle intestazioni beta.

    Per mantenere i vantaggi della memorizzazione nella cache dei prompt, utilizza l'intestazione beta in modo coerente per le richieste che desideri memorizzare nella cache. Se la utilizzi selettivamente, la memorizzazione nella cache dei prompt avrà esito negativo.

      © 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