도구
토큰 효율적인 도구 사용
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를 사용하여 토큰 효율적인 도구를 사용하는 방법의 예시입니다:
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());
}
}위의 요청은 평균적으로 일반 요청보다 더 적은 입력 및 출력 토큰을 사용해야 합니다. 이를 확인하려면 동일한 요청을 만들되 베타 헤더 목록에서 token-efficient-tools-2025-02-19를 제거해 보세요.
프롬프트 캐싱의 이점을 유지하려면 캐시하려는 요청에 대해 베타 헤더를 일관되게 사용하세요. 선택적으로 사용하면 프롬프트 캐싱이 실패합니다.