Loading...
    • 빌드
    • 관리
    • 모델 및 가격
    • 클라이언트 SDK
    • API 참조
    Search...
    ⌘K
    첫 단계
    Claude 소개빠른 시작
    Claude로 빌드하기
    기능 개요Messages API 사용Claude API 스킬중지 이유 처리
    모델 기능
    Extended thinkingAdaptive thinking노력작업 예산 (베타)빠른 모드 (베타: 연구 미리보기)구조화된 출력인용메시지 스트리밍배치 처리검색 결과거부 스트리밍다국어 지원임베딩
    도구
    개요도구 사용 방식웹 검색 도구웹 가져오기 도구코드 실행 도구어드바이저 도구메모리 도구Bash 도구컴퓨터 사용 도구텍스트 편집기 도구
    도구 인프라
    도구 참조도구 검색프로그래밍 방식 도구 호출세분화된 도구 스트리밍
    컨텍스트 관리
    컨텍스트 윈도우압축컨텍스트 편집프롬프트 캐싱토큰 계산
    파일 작업
    Files APIPDF 지원이미지 및 비전
    스킬
    개요빠른 시작모범 사례엔터프라이즈용 스킬API의 스킬
    MCP
    원격 MCP 서버MCP 커넥터
    프롬프트 엔지니어링
    개요프롬프팅 모범 사례Console 프롬프팅 도구
    테스트 및 평가
    성공 정의 및 평가 구축Console에서 평가 도구 사용지연 시간 감소
    보안 강화
    환각 감소출력 일관성 증가탈옥 완화프롬프트 유출 감소
    리소스
    용어집
    릴리스 노트
    Claude Platform
    Console
    Log in
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...

    Solutions

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

    Partners

    • Amazon Bedrock
    • Google Cloud's Vertex AI

    Learn

    • Blog
    • 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

    Learn

    • Blog
    • Courses
    • Use cases
    • Connectors
    • Customer stories
    • Engineering at Anthropic
    • Events
    • Powered by Claude
    • Service partners
    • Startups program

    Help and security

    • Availability
    • Status
    • Support
    • Discord

    Terms and policies

    • Privacy policy
    • Responsible disclosure policy
    • Terms of service: Commercial
    • Terms of service: Consumer
    • Usage policy
    컨텍스트 관리

    토큰 계산

    메시지를 Claude에 보내기 전에 메시지의 토큰 수를 결정하여 프롬프트 및 사용량에 대해 정보에 입각한 결정을 내릴 수 있습니다.

    토큰 계산을 통해 메시지를 Claude에 보내기 전에 메시지의 토큰 수를 결정할 수 있으므로 프롬프트 및 사용량에 대해 정보에 입각한 결정을 내릴 수 있습니다. 토큰 계산을 사용하면 다음을 수행할 수 있습니다.

    • 속도 제한 및 비용을 사전에 관리
    • 스마트한 모델 라우팅 결정 내리기
    • 프롬프트를 특정 길이로 최적화

    This feature is eligible for Zero Data Retention (ZDR). When your organization has a ZDR arrangement, data sent through this feature is not stored after the API response is returned.


    메시지 토큰을 계산하는 방법

    토큰 계산 엔드포인트는 시스템 프롬프트, 도구, 이미지, PDF에 대한 지원을 포함하여 메시지를 생성하기 위한 동일한 구조화된 입력 목록을 허용합니다. 응답에는 입력 토큰의 총 개수가 포함됩니다.

    토큰 개수는 추정값으로 간주되어야 합니다. 경우에 따라 메시지를 생성할 때 실제로 사용되는 입력 토큰의 수는 약간 다를 수 있습니다.

    토큰 개수에는 시스템 최적화를 위해 Anthropic에서 자동으로 추가한 토큰이 포함될 수 있습니다. 시스템에서 추가한 토큰에 대해서는 청구되지 않습니다. 청구는 귀하의 콘텐츠만 반영합니다.

    지원되는 모델

    모든 활성 모델은 토큰 계산을 지원합니다.

    기본 메시지에서 토큰 계산

    client = anthropic.Anthropic()
    
    response = client.messages.count_tokens(
        model="claude-opus-4-7",
        system="You are a scientist",
        messages=[{"role": "user", "content": "Hello, Claude"}],
    )
    
    print(response.json())
    Output
    { "input_tokens": 14 }

    도구를 사용하는 메시지에서 토큰 계산

    서버 도구 토큰 개수는 첫 번째 샘플링 호출에만 적용됩니다.

    client = anthropic.Anthropic()
    
    response = client.messages.count_tokens(
        model="claude-opus-4-7",
        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's the weather like in San Francisco?"}],
    )
    
    print(response.json())
    Output
    { "input_tokens": 403 }

    이미지가 있는 메시지에서 토큰 계산

    import base64
    import httpx
    
    image_url = "https://upload.wikimedia.org/wikipedia/commons/a/a7/Camponotus_flavomarginatus_ant.jpg"
    image_media_type = "image/jpeg"
    image_data = base64.standard_b64encode(httpx.get(image_url).content).decode("utf-8")
    
    client = anthropic.Anthropic()
    
    response = client.messages.count_tokens(
        model="claude-opus-4-7",
        messages=[
            {
                "role": "user",
                "content": [
                    {
                        "type": "image",
                        "source": {
                            "type": "base64",
                            "media_type": image_media_type,
                            "data": image_data,
                        },
                    },
                    {"type": "text", "text": "Describe this image"},
                ],
            }
        ],
    )
    print(response.json())
    Output
    { "input_tokens": 1551 }

    확장 사고를 사용한 메시지의 토큰 계산

    확장 사고를 사용한 컨텍스트 윈도우 계산 방법에서 자세한 내용을 확인하세요

    • 이전 어시스턴트 턴의 사고 블록은 무시되며 입력 토큰에 계산되지 않습니다
    • 현재 어시스턴트 턴의 사고는 입력 토큰에 계산됩니다
    client = anthropic.Anthropic()
    
    response = client.messages.count_tokens(
        model="claude-sonnet-4-6",
        thinking={"type": "enabled", "budget_tokens": 16000},
        messages=[
            {
                "role": "user",
                "content": "Are there an infinite number of prime numbers such that n mod 4 == 3?",
            },
            {
                "role": "assistant",
                "content": [
                    {
                        "type": "thinking",
                        "thinking": "This is a nice number theory question. Let's think about it step by step...",
                        "signature": "EuYBCkQYAiJAgCs1le6/Pol5Z4/JMomVOouGrWdhYNsH3ukzUECbB6iWrSQtsQuRHJID6lWV...",
                    },
                    {
                        "type": "text",
                        "text": "Yes, there are infinitely many prime numbers p such that p mod 4 = 3...",
                    },
                ],
            },
            {"role": "user", "content": "Can you write a formal proof?"},
        ],
    )
    
    print(response.json())
    Output
    { "input_tokens": 88 }

    PDF를 사용한 메시지의 토큰 계산

    토큰 계산은 Messages API와 동일한 제한사항을 가진 PDF를 지원합니다.

    import base64
    import anthropic
    
    client = anthropic.Anthropic()
    
    with open("document.pdf", "rb") as pdf_file:
        pdf_base64 = base64.standard_b64encode(pdf_file.read()).decode("utf-8")
    
    response = client.messages.count_tokens(
        model="claude-opus-4-7",
        messages=[
            {
                "role": "user",
                "content": [
                    {
                        "type": "document",
                        "source": {
                            "type": "base64",
                            "media_type": "application/pdf",
                            "data": pdf_base64,
                        },
                    },
                    {"type": "text", "text": "Please summarize this document."},
                ],
            }
        ],
    )
    
    print(response.json())
    Output
    { "input_tokens": 2188 }

    가격 및 속도 제한

    토큰 계산은 무료로 사용할 수 있지만 사용 계층에 따른 분당 요청 수 속도 제한이 적용됩니다. 더 높은 제한이 필요한 경우 Claude Console을 통해 영업팀에 문의하세요.

    사용 계층분당 요청 수(RPM)
    1100
    22,000
    34,000
    48,000

    토큰 계산과 메시지 생성은 별도의 독립적인 속도 제한을 가집니다. 하나의 사용이 다른 하나의 제한에 영향을 주지 않습니다.


    FAQ

    Was this page helpful?

    • PDF를 사용한 메시지의 토큰 계산
    • FAQ