[アップデート] Amazon Bedrock で CountTokens API が登場しました

[アップデート] Amazon Bedrock で CountTokens API が登場しました

2025.08.21

こんにちは!クラウド事業本部コンサルティング部のたかくに(@takakuni_)です。

日課で Amazon Bedrock の API 更新を見ているのですが、CountTokens なる API が新しく登場していました。

https://awsapichanges.com/archive/changes/f0b3e8-bedrock-runtime.html

CountTokens API

名前の通り、トークン数をカウントするための API のようです。

当たり前ではあるのですが、説明文を読むとインプットトークン数を事前に知るための API のようです。

また、InvokeModel, Converse API の両方の API に対応しています。

Token counting is model-specific because different models use different tokenization strategies. The token count returned by this operation will match the token count that would be charged if the same input were sent to the model in an InvokeModel or Converse request.

今まで、事前に渡すインプットトークンを調べるには、各社の API や Tokenizer を利用する必要があったのですが、今回のアップデートで Bedrock の API からも把握できるようになりました。

https://docs.anthropic.com/en/api/messages-count-tokens

モデルごとにトークン数は異なるため、各モデルを比較する時に SDK を切り替えて確認のような作業がなくなっていくのは嬉しいですね。

やってみた

実際に CountTokens API を試してみましょう。

先にネタバレしてしまうのですが、 ListFoundationModels API から取得した、モデル ID を指定した Invalid なモデルもあったため、推論プロファイルも指定してみました。

import boto3
import json
import os

# Use profile if specified
profile_name = os.environ.get('AWS_PROFILE', 'takakuni-tf')
session = boto3.Session(profile_name=profile_name)
bedrock_runtime = session.client("bedrock-runtime", region_name="us-east-1")
bedrock = session.client("bedrock", region_name="us-east-1")

models = bedrock.list_foundation_models()

# modelId のみを取得
model_ids = [model["modelId"] for model in models["modelSummaries"]]

print("=== Testing Foundation Models ===\n")
for model_id in model_ids:
    try:
        response = bedrock_runtime.count_tokens(
            modelId=model_id,
            input={
                'converse': {
                    'messages': [
                        {
                            'role': 'user',
                            'content': [
                                {
                                    'text': 'Hello, world! How are you today?'
                                }
                            ]
                        }
                    ]
                }
            }
        )
        print(f"Model: {model_id}")
        print(json.dumps(response, indent=2, default=str))
        print("-" * 50)
    except Exception as e:
        print(f"Error with model {model_id}: {e}")
        print("-" * 50)

# inferenceProfileId のみを取得
inference_profiles = bedrock.list_inference_profiles()
inference_profile_ids = [profile["inferenceProfileId"] for profile in inference_profiles["inferenceProfileSummaries"]]

print("\n=== Testing Inference Profiles ===\n")
for profile_id in inference_profile_ids:
    try:
        response = bedrock_runtime.count_tokens(
            modelId=profile_id,
            input={
                'converse': {
                    'messages': [
                        {
                            'role': 'user',
                            'content': [
                                {
                                    'text': 'Hello, world! How are you today?'
                                }
                            ]
                        }
                    ]
                }
            }
        )
        print(f"Inference Profile: {profile_id}")
        print(json.dumps(response, indent=2, default=str))
        print("-" * 50)
    except Exception as e:
        print(f"Error with inference profile {profile_id}: {e}")
        print("-" * 50)

実行結果から、すべてのモデルをサポートしているようではなく、以下のモデルがサポートされていました。

  • anthropic.claude-3-5-sonnet-20240620-v1:0
  • anthropic.claude-3-5-sonnet-20241022-v2:0
  • anthropic.claude-3-7-sonnet-20250219-v1:0
  • anthropic.claude-3-5-haiku-20241022-v1:0
  • anthropic.claude-opus-4-20250514-v1:0
  • anthropic.claude-sonnet-4-20250514-v1:0
実行結果
=== Testing Foundation Models ===

Error with model twelvelabs.pegasus-1-2-v1:0: An error occurred (ValidationException) when calling the CountTokens operation: The provided model identifier is invalid.
--------------------------------------------------
Error with model anthropic.claude-opus-4-1-20250805-v1:0: An error occurred (ValidationException) when calling the CountTokens operation: The provided model identifier is invalid.
--------------------------------------------------
Error with model amazon.titan-tg1-large: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------
Error with model amazon.titan-image-generator-v1:0: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------
Error with model amazon.titan-image-generator-v1: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------
Error with model amazon.titan-image-generator-v2:0: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------
Error with model amazon.nova-premier-v1:0:8k: An error occurred (ResourceNotFoundException) when calling the CountTokens operation: Model not found.
--------------------------------------------------
Error with model amazon.nova-premier-v1:0:20k: An error occurred (ResourceNotFoundException) when calling the CountTokens operation: Model not found.
--------------------------------------------------
Error with model amazon.nova-premier-v1:0:1000k: An error occurred (ResourceNotFoundException) when calling the CountTokens operation: Model not found.
--------------------------------------------------
Error with model amazon.nova-premier-v1:0:mm: An error occurred (ResourceNotFoundException) when calling the CountTokens operation: Model not found.
--------------------------------------------------
Error with model amazon.nova-premier-v1:0: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------
Error with model amazon.titan-text-premier-v1:0: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------
Error with model amazon.nova-pro-v1:0:24k: An error occurred (ResourceNotFoundException) when calling the CountTokens operation: Model not found.
--------------------------------------------------
Error with model amazon.nova-pro-v1:0:300k: An error occurred (ResourceNotFoundException) when calling the CountTokens operation: Model not found.
--------------------------------------------------
Error with model amazon.nova-pro-v1:0: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------
Error with model amazon.nova-lite-v1:0:24k: An error occurred (ResourceNotFoundException) when calling the CountTokens operation: Model not found.
--------------------------------------------------
Error with model amazon.nova-lite-v1:0:300k: An error occurred (ResourceNotFoundException) when calling the CountTokens operation: Model not found.
--------------------------------------------------
Error with model amazon.nova-lite-v1:0: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------
Error with model amazon.nova-canvas-v1:0: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------
Error with model amazon.nova-reel-v1:0: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------
Error with model amazon.nova-reel-v1:1: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------
Error with model amazon.nova-micro-v1:0:24k: An error occurred (ResourceNotFoundException) when calling the CountTokens operation: Model not found.
--------------------------------------------------
Error with model amazon.nova-micro-v1:0:128k: An error occurred (ResourceNotFoundException) when calling the CountTokens operation: Model not found.
--------------------------------------------------
Error with model amazon.nova-micro-v1:0: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------
Error with model amazon.nova-sonic-v1:0: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------
Error with model amazon.titan-embed-g1-text-02: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------
Error with model amazon.titan-text-lite-v1:0:4k: An error occurred (ResourceNotFoundException) when calling the CountTokens operation: Model not found.
--------------------------------------------------
Error with model amazon.titan-text-lite-v1: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------
Error with model amazon.titan-text-express-v1:0:8k: An error occurred (ResourceNotFoundException) when calling the CountTokens operation: Model not found.
--------------------------------------------------
Error with model amazon.titan-text-express-v1: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------
Error with model amazon.titan-embed-text-v1:2:8k: An error occurred (ResourceNotFoundException) when calling the CountTokens operation: Model not found.
--------------------------------------------------
Error with model amazon.titan-embed-text-v1: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------
Error with model amazon.titan-embed-text-v2:0:8k: An error occurred (ResourceNotFoundException) when calling the CountTokens operation: Model not found.
--------------------------------------------------
Error with model amazon.titan-embed-text-v2:0: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------
Error with model amazon.titan-embed-image-v1:0: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------
Error with model amazon.titan-embed-image-v1: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------
Error with model stability.stable-diffusion-xl-v1:0: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------
Error with model stability.stable-diffusion-xl-v1: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------
Error with model ai21.jamba-instruct-v1:0: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------
Error with model ai21.jamba-1-5-large-v1:0: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------
Error with model ai21.jamba-1-5-mini-v1:0: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------
Error with model anthropic.claude-instant-v1:2:100k: An error occurred (ResourceNotFoundException) when calling the CountTokens operation: Model not found.
--------------------------------------------------
Error with model anthropic.claude-instant-v1: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------
Error with model anthropic.claude-v2:0:18k: An error occurred (ResourceNotFoundException) when calling the CountTokens operation: Model not found.
--------------------------------------------------
Error with model anthropic.claude-v2:0:100k: An error occurred (ResourceNotFoundException) when calling the CountTokens operation: Model not found.
--------------------------------------------------
Error with model anthropic.claude-v2:1:18k: An error occurred (ResourceNotFoundException) when calling the CountTokens operation: Model not found.
--------------------------------------------------
Error with model anthropic.claude-v2:1:200k: An error occurred (ResourceNotFoundException) when calling the CountTokens operation: Model not found.
--------------------------------------------------
Error with model anthropic.claude-v2:1: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------
Error with model anthropic.claude-v2: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------
Error with model anthropic.claude-3-sonnet-20240229-v1:0:28k: An error occurred (ResourceNotFoundException) when calling the CountTokens operation: Model not found.
--------------------------------------------------
Error with model anthropic.claude-3-sonnet-20240229-v1:0:200k: An error occurred (ResourceNotFoundException) when calling the CountTokens operation: Model not found.
--------------------------------------------------
Error with model anthropic.claude-3-sonnet-20240229-v1:0: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------
Error with model anthropic.claude-3-haiku-20240307-v1:0:48k: An error occurred (ResourceNotFoundException) when calling the CountTokens operation: Model not found.
--------------------------------------------------
Error with model anthropic.claude-3-haiku-20240307-v1:0:200k: An error occurred (ResourceNotFoundException) when calling the CountTokens operation: Model not found.
--------------------------------------------------
Error with model anthropic.claude-3-haiku-20240307-v1:0: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------
Error with model anthropic.claude-3-opus-20240229-v1:0:12k: An error occurred (ResourceNotFoundException) when calling the CountTokens operation: Model not found.
--------------------------------------------------
Error with model anthropic.claude-3-opus-20240229-v1:0:28k: An error occurred (ResourceNotFoundException) when calling the CountTokens operation: Model not found.
--------------------------------------------------
Error with model anthropic.claude-3-opus-20240229-v1:0:200k: An error occurred (ResourceNotFoundException) when calling the CountTokens operation: Model not found.
--------------------------------------------------
Error with model anthropic.claude-3-opus-20240229-v1:0: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------
Model: anthropic.claude-3-5-sonnet-20240620-v1:0
{
  "ResponseMetadata": {
    "RequestId": "dc8bae99-667e-4af4-bb16-6f5421a21e02",
    "HTTPStatusCode": 200,
    "HTTPHeaders": {
      "date": "Wed, 20 Aug 2025 22:40:05 GMT",
      "content-type": "application/json",
      "content-length": "18",
      "connection": "keep-alive",
      "x-amzn-requestid": "dc8bae99-667e-4af4-bb16-6f5421a21e02"
    },
    "RetryAttempts": 0
  },
  "inputTokens": 16
}
--------------------------------------------------
Model: anthropic.claude-3-5-sonnet-20241022-v2:0
{
  "ResponseMetadata": {
    "RequestId": "e39728bc-7fac-4a4a-b04c-9669e3ec75e4",
    "HTTPStatusCode": 200,
    "HTTPHeaders": {
      "date": "Wed, 20 Aug 2025 22:40:05 GMT",
      "content-type": "application/json",
      "content-length": "18",
      "connection": "keep-alive",
      "x-amzn-requestid": "e39728bc-7fac-4a4a-b04c-9669e3ec75e4"
    },
    "RetryAttempts": 0
  },
  "inputTokens": 16
}
--------------------------------------------------
Model: anthropic.claude-3-7-sonnet-20250219-v1:0
{
  "ResponseMetadata": {
    "RequestId": "2ec1a22a-4d06-41c6-aea8-d29418e67730",
    "HTTPStatusCode": 200,
    "HTTPHeaders": {
      "date": "Wed, 20 Aug 2025 22:40:05 GMT",
      "content-type": "application/json",
      "content-length": "18",
      "connection": "keep-alive",
      "x-amzn-requestid": "2ec1a22a-4d06-41c6-aea8-d29418e67730"
    },
    "RetryAttempts": 0
  },
  "inputTokens": 16
}
--------------------------------------------------
Model: anthropic.claude-3-5-haiku-20241022-v1:0
{
  "ResponseMetadata": {
    "RequestId": "456863fe-c63d-4b26-84ff-1d055cfc4789",
    "HTTPStatusCode": 200,
    "HTTPHeaders": {
      "date": "Wed, 20 Aug 2025 22:40:06 GMT",
      "content-type": "application/json",
      "content-length": "18",
      "connection": "keep-alive",
      "x-amzn-requestid": "456863fe-c63d-4b26-84ff-1d055cfc4789"
    },
    "RetryAttempts": 0
  },
  "inputTokens": 16
}
--------------------------------------------------
Model: anthropic.claude-opus-4-20250514-v1:0
{
  "ResponseMetadata": {
    "RequestId": "b7ece73f-052a-46ee-b102-0ec91b4d52b5",
    "HTTPStatusCode": 200,
    "HTTPHeaders": {
      "date": "Wed, 20 Aug 2025 22:40:06 GMT",
      "content-type": "application/json",
      "content-length": "18",
      "connection": "keep-alive",
      "x-amzn-requestid": "b7ece73f-052a-46ee-b102-0ec91b4d52b5"
    },
    "RetryAttempts": 0
  },
  "inputTokens": 16
}
--------------------------------------------------
Model: anthropic.claude-sonnet-4-20250514-v1:0
{
  "ResponseMetadata": {
    "RequestId": "e115bd13-c70f-40e4-a48f-be5e4af97da5",
    "HTTPStatusCode": 200,
    "HTTPHeaders": {
      "date": "Wed, 20 Aug 2025 22:40:06 GMT",
      "content-type": "application/json",
      "content-length": "18",
      "connection": "keep-alive",
      "x-amzn-requestid": "e115bd13-c70f-40e4-a48f-be5e4af97da5"
    },
    "RetryAttempts": 0
  },
  "inputTokens": 16
}
--------------------------------------------------
Error with model cohere.command-r-v1:0: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------
Error with model cohere.command-r-plus-v1:0: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------
Error with model cohere.embed-english-v3:0:512: An error occurred (ResourceNotFoundException) when calling the CountTokens operation: Model not found.
--------------------------------------------------
Error with model cohere.embed-english-v3: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------
Error with model cohere.embed-multilingual-v3:0:512: An error occurred (ResourceNotFoundException) when calling the CountTokens operation: Model not found.
--------------------------------------------------
Error with model cohere.embed-multilingual-v3: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------
Error with model deepseek.r1-v1:0: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------
Error with model meta.llama3-8b-instruct-v1:0: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------
Error with model meta.llama3-70b-instruct-v1:0: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------
Error with model meta.llama3-1-8b-instruct-v1:0: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------
Error with model meta.llama3-1-70b-instruct-v1:0: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------
Error with model meta.llama3-2-11b-instruct-v1:0: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------
Error with model meta.llama3-2-90b-instruct-v1:0: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------
Error with model meta.llama3-2-1b-instruct-v1:0: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------
Error with model meta.llama3-2-3b-instruct-v1:0: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------
Error with model meta.llama3-3-70b-instruct-v1:0: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------
Error with model meta.llama4-scout-17b-instruct-v1:0: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------
Error with model meta.llama4-maverick-17b-instruct-v1:0: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------
Error with model mistral.mistral-7b-instruct-v0:2: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------
Error with model mistral.mixtral-8x7b-instruct-v0:1: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------
Error with model mistral.mistral-large-2402-v1:0: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------
Error with model mistral.mistral-small-2402-v1:0: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------
Error with model mistral.pixtral-large-2502-v1:0: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------
Error with model twelvelabs.marengo-embed-2-7-v1:0: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------

=== Testing Inference Profiles ===

Error with inference profile us.anthropic.claude-3-sonnet-20240229-v1:0: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------
Error with inference profile us.anthropic.claude-3-opus-20240229-v1:0: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------
Error with inference profile us.anthropic.claude-3-haiku-20240307-v1:0: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------
Error with inference profile us.meta.llama3-2-11b-instruct-v1:0: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------
Error with inference profile us.meta.llama3-2-3b-instruct-v1:0: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------
Error with inference profile us.meta.llama3-2-90b-instruct-v1:0: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------
Error with inference profile us.meta.llama3-2-1b-instruct-v1:0: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------
Error with inference profile us.anthropic.claude-3-5-sonnet-20240620-v1:0: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------
Error with inference profile us.anthropic.claude-3-5-haiku-20241022-v1:0: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------
Error with inference profile us.meta.llama3-1-8b-instruct-v1:0: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------
Error with inference profile us.meta.llama3-1-70b-instruct-v1:0: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------
Error with inference profile us.meta.llama3-3-70b-instruct-v1:0: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------
Error with inference profile us.anthropic.claude-3-5-sonnet-20241022-v2:0: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------
Error with inference profile us.deepseek.r1-v1:0: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------
Error with inference profile us.mistral.pixtral-large-2502-v1:0: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------
Error with inference profile us.meta.llama4-scout-17b-instruct-v1:0: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------
Error with inference profile us.meta.llama4-maverick-17b-instruct-v1:0: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------
Error with inference profile us.amazon.nova-premier-v1:0: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------
Error with inference profile us.anthropic.claude-opus-4-20250514-v1:0: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------
Error with inference profile us.anthropic.claude-3-7-sonnet-20250219-v1:0: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------
Error with inference profile us.amazon.nova-pro-v1:0: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------
Error with inference profile us.anthropic.claude-sonnet-4-20250514-v1:0: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------
Error with inference profile us.anthropic.claude-opus-4-1-20250805-v1:0: An error occurred (ValidationException) when calling the CountTokens operation: The provided model doesn't support counting tokens.
--------------------------------------------------

まとめ

以上、「Amazon Bedrock で CountTokens API が登場しました」でした。

トークン数のカウントですが、私個人としてはちょくちょく使うので、Bedrock の API でわかるようになったのは嬉しいですね。

現状、サポートされているモデルが限られていますが、順次拡大していくとありがたいですね。

クラウド事業本部コンサルティング部のたかくに(@takakuni_)でした!

この記事をシェアする

facebookのロゴhatenaのロゴtwitterのロゴ

© Classmethod, Inc. All rights reserved.