Loading...
    • 開発者ガイド
    • API リファレンス
    • MCP
    • リソース
    • リリースノート
    Search...
    ⌘K

    はじめの一歩

    Claudeの紹介クイックスタート

    モデルと料金

    モデル概要モデルの選択Claude 4.5の新機能Claude 4.5への移行モデルの廃止予定価格設定

    Claudeで構築する

    機能概要Messages API の使用コンテキストウィンドウプロンプトのベストプラクティス

    機能

    プロンプトキャッシングコンテキスト編集拡張思考ストリーミングメッセージバッチ処理引用多言語サポートトークンカウント埋め込みビジョンPDFサポートFiles API検索結果Google Sheetsアドオン

    ツール

    概要ツール使用の実装方法トークン効率的なツール使用細粒度ツールストリーミングBashツールコード実行ツールコンピュータ使用ツールテキストエディタツールWeb fetch toolウェブ検索ツールメモリツール

    エージェントスキル

    概要クイックスタートスキル作成のベストプラクティスAPIでエージェントスキルを使用する

    Agent SDK

    概要Agent SDK リファレンス - TypeScriptPython SDK

    ガイド

    ストリーミング入力権限の処理セッション管理Agent SDKのホスティングシステムプロンプトの変更SDK内のMCPカスタムツールSDKにおけるサブエージェントSDKでのスラッシュコマンドSDK内のエージェントスキルコストと使用量の追跡Todo リストSDK のプラグイン

    API内のMCP

    MCPコネクタリモートMCPサーバー

    Claude on 3rd-party platforms

    Amazon BedrockVertex AI

    プロンプトエンジニアリング

    概要プロンプトジェネレータープロンプトテンプレートの使用プロンプト改善ツール明確で直接的な指示例(マルチショットプロンプト)を使用してClaudeの動作を導くClaudeに考えさせる(CoT)XMLタグを使用Claudeに役割を与える(システムプロンプト)Claudeの応答を事前入力複雑なプロンプトのチェーン化長文コンテキストのヒント拡張思考のヒント

    テストと評価

    成功基準を定義するテストケースを開発する評価ツールの使用レイテンシの削減

    ガードレールを強化

    幻覚を減らす出力の一貫性を高めるジェイルブレイクの軽減handle-streaming-refusalsプロンプトリークの削減Claudeのキャラクターを維持

    管理とモニタリング

    Admin API概要使用量とコストAPIClaude Code Analytics API
    Console
    機能

    トークンカウント

    Claudeにメッセージを送信する前にメッセージ内のトークン数を決定し、プロンプトと使用量について情報に基づいた決定を行うのに役立ちます。

    トークンカウントにより、Claudeにメッセージを送信する前にメッセージ内のトークン数を決定でき、プロンプトと使用量について情報に基づいた決定を行うのに役立ちます。トークンカウントを使用すると、以下のことができます:

    • レート制限とコストを積極的に管理する
    • スマートなモデルルーティング決定を行う
    • 特定の長さになるようにプロンプトを最適化する

    メッセージトークンをカウントする方法

    トークンカウントエンドポイントは、システムプロンプト、ツール、画像、PDFのサポートを含む、メッセージ作成のための同じ構造化された入力リストを受け入れます。レスポンスには入力トークンの総数が含まれます。

    トークン数は推定値として考慮すべきです。場合によっては、メッセージ作成時に使用される実際の入力トークン数が少量異なる場合があります。

    トークン数には、システム最適化のためにAnthropicによって自動的に追加されたトークンが含まれる場合があります。システムが追加したトークンについては請求されません。請求はあなたのコンテンツのみを反映します。

    サポートされているモデル

    すべてのアクティブなモデルがトークンカウントをサポートしています。

    基本メッセージのトークンをカウントする

    Python
    import anthropic
    
    client = anthropic.Anthropic()
    
    response = client.messages.count_tokens(
        model="claude-sonnet-4-5",
        system="You are a scientist",
        messages=[{
            "role": "user",
            "content": "Hello, Claude"
        }],
    )
    
    print(response.json())
    TypeScript
    import Anthropic from '@anthropic-ai/sdk';
    
    const client = new Anthropic();
    
    const response = await client.messages.countTokens({
      model: 'claude-sonnet-4-5',
      system: 'You are a scientist',
      messages: [{
        role: 'user',
        content: 'Hello, Claude'
      }]
    });
    
    console.log(response);
    Shell
    curl https://api.anthropic.com/v1/messages/count_tokens \
        --header "x-api-key: $ANTHROPIC_API_KEY" \
        --header "content-type: application/json" \
        --header "anthropic-version: 2023-06-01" \
        --data '{
          "model": "claude-sonnet-4-5",
          "system": "You are a scientist",
          "messages": [{
            "role": "user",
            "content": "Hello, Claude"
          }]
        }'
    Java
    import com.anthropic.client.AnthropicClient;
    import com.anthropic.client.okhttp.AnthropicOkHttpClient;
    import com.anthropic.models.messages.MessageCountTokensParams;
    import com.anthropic.models.messages.MessageTokensCount;
    import com.anthropic.models.messages.Model;
    
    public class CountTokensExample {
    
        public static void main(String[] args) {
            AnthropicClient client = AnthropicOkHttpClient.fromEnv();
    
            MessageCountTokensParams params = MessageCountTokensParams.builder()
                    .model(Model.CLAUDE_SONNET_4_20250514)
                    .system("You are a scientist")
                    .addUserMessage("Hello, Claude")
                    .build();
    
            MessageTokensCount count = client.messages().countTokens(params);
            System.out.println(count);
        }
    }
    JSON
    { "input_tokens": 14 }

    ツールを含むメッセージのトークンをカウントする

    サーバーツールのトークン数は最初のサンプリング呼び出しにのみ適用されます。

    import anthropic
    
    client = anthropic.Anthropic()
    
    response = client.messages.count_tokens(
        model="claude-sonnet-4-5",
        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())
    JSON
    { "input_tokens": 403 }

    画像を含むメッセージのトークンをカウントする

    #!/bin/sh
    
    IMAGE_URL="https://upload.wikimedia.org/wikipedia/commons/a/a7/Camponotus_flavomarginatus_ant.jpg"
    IMAGE_MEDIA_TYPE="image/jpeg"
    IMAGE_BASE64=$(curl "$IMAGE_URL" | base64)
    
    curl https://api.anthropic.com/v1/messages/count_tokens \
         --header "x-api-key: $ANTHROPIC_API_KEY" \
         --header "anthropic-version: 2023-06-01" \
         --header "content-type: application/json" \
         --data \
    '{
        "model": "claude-sonnet-4-5",
        "messages": [
            {"role": "user", "content": [
                {"type": "image", "source": {
                    "type": "base64",
                    "media_type": "'$IMAGE_MEDIA_TYPE'",
                    "data": "'$IMAGE_BASE64'"
                }},
                {"type": "text", "text": "Describe this image"}
            ]}
        ]
    }'
    JSON
    { "input_tokens": 1551 }

    拡張思考を含むメッセージのトークンをカウントする

    拡張思考でコンテキストウィンドウがどのように計算されるかの詳細についてはこちらをご覧ください

    • 以前のアシスタントターンからの思考ブロックは無視され、入力トークンにカウントされません
    • 現在のアシスタントターンの思考は入力トークンにカウントされます
    curl https://api.anthropic.com/v1/messages/count_tokens \
        --header "x-api-key: $ANTHROPIC_API_KEY" \
        --header "content-type: application/json" \
        --header "anthropic-version: 2023-06-01" \
        --data '{
          "model": "claude-sonnet-4-5",
          "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. Lets 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?"
            }
          ]
        }'
    JSON
    { "input_tokens": 88 }

    PDFを含むメッセージのトークンをカウントする

    トークンカウントは、Messages APIと同じ制限でPDFをサポートします。

    curl https://api.anthropic.com/v1/messages/count_tokens \
        --header "x-api-key: $ANTHROPIC_API_KEY" \
        --header "content-type: application/json" \
        --header "anthropic-version: 2023-06-01" \
        --data '{
          "model": "claude-sonnet-4-5",
          "messages": [{
            "role": "user",
            "content": [
              {
                "type": "document",
                "source": {
                  "type": "base64",
                  "media_type": "application/pdf",
                  "data": "'$(base64 -i document.pdf)'"
                }
              },
              {
                "type": "text",
                "text": "Please summarize this document."
              }
            ]
          }]
        }'
    JSON
    { "input_tokens": 2188 }

    価格とレート制限

    トークンカウントは無料で使用できますが、使用量ティアに基づく分あたりのリクエスト数のレート制限の対象となります。より高い制限が必要な場合は、Claude Consoleを通じて営業にお問い合わせください。

    使用量ティア分あたりのリクエスト数(RPM)
    1100
    22,000
    34,000
    48,000

    トークンカウントとメッセージ作成には別々の独立したレート制限があります -- 一方の使用は他方の制限にカウントされません。


    FAQ

    • PDFを含むメッセージのトークンをカウントする
    • FAQ
    © 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