Claude는 도구와 함수와 상호작용할 수 있어, Claude의 기능을 확장하여 더 다양한 작업을 수행할 수 있습니다.
다음은 Messages API를 사용하여 Claude에게 도구를 제공하는 방법의 예시입니다:
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" \
-d '{
"model": "claude-sonnet-4-5",
"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": "What is the weather like in San Francisco?"
}
]
}'Claude는 두 가지 유형의 도구를 지원합니다:
클라이언트 도구: 사용자 시스템에서 실행되는 도구로, 다음을 포함합니다:
서버 도구: 웹 검색 및 웹 가져오기 도구와 같이 Anthropic 서버에서 실행되는 도구입니다. 이러한 도구는 API 요청에서 지정되어야 하지만 사용자 측에서 구현할 필요는 없습니다.
Anthropic 정의 도구는 모델 버전 간 호환성을 보장하기 위해 버전이 지정된 유형(예: web_search_20250305, text_editor_20250124)을 사용합니다.
다음 단계에 따라 클라이언트 도구를 Claude와 통합하세요:
Claude에게 도구와 사용자 프롬프트 제공
Claude가 도구 사용을 결정
tool_use의 stop_reason을 가집니다.도구 실행 및 결과 반환
tool_result 콘텐츠 블록을 포함하는 새로운 user 메시지로 결과를 반환합니다Claude가 도구 결과를 사용하여 응답 작성
참고: 3단계와 4단계는 선택사항입니다. 일부 워크플로우의 경우, Claude의 도구 사용 요청(2단계)만으로도 충분할 수 있으며, 결과를 Claude에게 다시 보낼 필요가 없습니다.
서버 도구는 다른 워크플로우를 따릅니다:
Claude에게 도구와 사용자 프롬프트 제공
Claude가 서버 도구 실행
Claude가 서버 도구 결과를 사용하여 응답 작성
다양한 도구 사용 패턴과 기법을 보여주는 몇 가지 코드 예시입니다. 간결함을 위해 도구는 간단한 도구이며, 도구 설명은 최상의 성능을 보장하기 위해 이상적인 것보다 짧습니다.
Tool use requests are priced based on:
tools parameter)Client-side tools are priced the same as any other Claude API request, while server-side tools may incur additional charges based on their specific usage.
The additional tokens from tool use come from:
tools parameter in API requests (tool names, descriptions, and schemas)tool_use content blocks in API requests and responsestool_result content blocks in API requestsWhen you use tools, we also automatically include a special system prompt for the model which enables tool use. The number of tool use tokens required for each model are listed below (excluding the additional tokens listed above). Note that the table assumes at least 1 tool is provided. If no tools are provided, then a tool choice of none uses 0 additional system prompt tokens.
| Model | Tool choice | Tool use system prompt token count |
|---|---|---|
| Claude Opus 4.5 | auto, noneany, tool | 346 tokens 313 tokens |
| Claude Opus 4.1 | auto, noneany, tool | 346 tokens 313 tokens |
| Claude Opus 4 | auto, noneany, tool | 346 tokens 313 tokens |
| Claude Sonnet 4.5 | auto, noneany, tool | 346 tokens 313 tokens |
| Claude Sonnet 4 | auto, noneany, tool | 346 tokens 313 tokens |
| Claude Sonnet 3.7 (deprecated) | auto, noneany, tool | 346 tokens 313 tokens |
| Claude Haiku 4.5 | auto, noneany, tool | 346 tokens 313 tokens |
| Claude Haiku 3.5 | auto, noneany, tool | 264 tokens 340 tokens |
| Claude Opus 3 (deprecated) | auto, noneany, tool | 530 tokens 281 tokens |
| Claude Sonnet 3 | auto, noneany, tool | 159 tokens 235 tokens |
| Claude Haiku 3 | auto, noneany, tool | 264 tokens 340 tokens |
These token counts are added to your normal input and output tokens to calculate the total cost of a request.
현재 모델별 가격은 모델 개요 표를 참조하세요.
도구 사용 프롬프트를 보낼 때, 다른 API 요청과 마찬가지로 응답은 보고된 usage 메트릭의 일부로 입력 및 출력 토큰 수를 모두 출력합니다.
쿡북에서 바로 구현할 수 있는 도구 사용 코드 예시 저장소를 탐색해 보세요: