Claude는 도구 및 함수와 상호작용할 수 있어 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-opus-4-20250514",
    "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는 두 가지 유형의 도구를 지원합니다:

  1. 클라이언트 도구: 사용자의 시스템에서 실행되는 도구로, 다음을 포함합니다:

  2. 서버 도구: 웹 검색 도구와 같이 Anthropic의 서버에서 실행되는 도구입니다. 이러한 도구는 API 요청에 지정되어야 하지만 사용자 측에서 구현할 필요는 없습니다.

Anthropic이 정의한 도구는 버전이 지정된 유형(예: web_search_20250305, text_editor_20250124)을 사용하여 모델 버전 간의 호환성을 보장합니다.

클라이언트 도구

다음 단계에 따라 클라이언트 도구를 Claude와 통합하세요:

1

Claude에게 도구와 사용자 프롬프트 제공

  • API 요청에 이름, 설명 및 입력 스키마가 포함된 클라이언트 도구를 정의합니다.
  • “샌프란시스코의 날씨는 어떤가요?”와 같이 이러한 도구가 필요할 수 있는 사용자 프롬프트를 포함합니다.
2

Claude가 도구 사용을 결정

  • Claude는 사용자의 쿼리에 도움이 될 수 있는 도구가 있는지 평가합니다.
  • 있다면, Claude는 적절하게 형식이 지정된 도구 사용 요청을 구성합니다.
  • 클라이언트 도구의 경우, API 응답의 stop_reasontool_use로 표시되어 Claude의 의도를 알립니다.
3

도구 실행 및 결과 반환

  • Claude의 요청에서 도구 이름과 입력을 추출합니다
  • 사용자 시스템에서 도구 코드를 실행합니다
  • tool_result 콘텐츠 블록이 포함된 새 user 메시지로 결과를 반환합니다
4

Claude가 도구 결과를 사용하여 응답 작성

  • Claude는 도구 결과를 분석하여 원래 사용자 프롬프트에 대한 최종 응답을 작성합니다.

참고: 3단계와 4단계는 선택 사항입니다. 일부 워크플로우의 경우, Claude의 도구 사용 요청(2단계)만으로 충분하며 결과를 Claude에 다시 보낼 필요가 없을 수 있습니다.

서버 도구

서버 도구는 다른 워크플로우를 따릅니다:

1

Claude에게 도구와 사용자 프롬프트 제공

  • 웹 검색과 같은 서버 도구에는 고유한 매개변수가 있습니다.
  • “AI에 관한 최신 뉴스를 검색해 주세요”와 같이 이러한 도구가 필요할 수 있는 사용자 프롬프트를 포함합니다.
2

Claude가 서버 도구 실행

  • Claude는 사용자의 쿼리에 서버 도구가 도움이 될 수 있는지 평가합니다.
  • 그렇다면, Claude는 도구를 실행하고 결과는 자동으로 Claude의 응답에 통합됩니다.
3

Claude가 서버 도구 결과를 사용하여 응답 작성

  • Claude는 서버 도구 결과를 분석하여 원래 사용자 프롬프트에 대한 최종 응답을 작성합니다.
  • 서버 도구 실행에는 추가적인 사용자 상호작용이 필요하지 않습니다.

도구 사용 예시

다음은 다양한 도구 사용 패턴과 기술을 보여주는 몇 가지 코드 예시입니다. 간결함을 위해 도구는 간단한 도구이며, 도구 설명은 최상의 성능을 보장하기 위해 이상적인 것보다 짧습니다.


가격 책정

Tool use requests are priced based on:

  1. The total number of input tokens sent to the model (including in the tools parameter)
  2. The number of output tokens generated
  3. For server-side tools, additional usage-based pricing (e.g., web search charges per search performed)

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:

  • The tools parameter in API requests (tool names, descriptions, and schemas)
  • tool_use content blocks in API requests and responses
  • tool_result content blocks in API requests

When 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.

ModelTool choiceTool use system prompt token count
Claude Opus 4auto, none
any, tool
346 tokens
313 tokens
Claude Sonnet 4auto, none
any, tool
346 tokens
313 tokens
Claude Sonnet 3.7auto, none
any, tool
346 tokens
313 tokens
Claude Sonnet 3.5 (Oct)auto, none
any, tool
346 tokens
313 tokens
Claude Sonnet 3.5 (June)auto, none
any, tool
294 tokens
261 tokens
Claude Haiku 3.5auto, none
any, tool
264 tokens
340 tokens
Claude Opus 3auto, none
any, tool
530 tokens
281 tokens
Claude Sonnet 3auto, none
any, tool
159 tokens
235 tokens
Claude Haiku 3auto, none
any, 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 메트릭의 일부로 입력 및 출력 토큰 수를 모두 출력합니다.


다음 단계

쿡북에서 바로 구현할 수 있는 도구 사용 코드 예시 저장소를 살펴보세요: