POST/v1/messages/count_tokens

Count message tokens

Estimates the input tokens of a Messages request with the gateway's own tokenizer. Free, never billed, and an estimate, not the provider's count; the body says so in x-experiential-ignored-parameters.

認証: AuthorizationヘッダーにBearer形式のAPIキー

リクエストボディ

  • modelstring必須

    A model slug your key can call.

  • messagesarray<object>必須

    The messages to count, as in POST /v1/messages.

  • systemstring | array<object>

    Optional system prompt.

  • toolsarray<object>

    Optional tool definitions.

レスポンス

  • 200

    The estimate.

    レスポンス
    • input_tokensinteger

      Estimated input tokens.

    • x-experiential-ignored-parametersarray<string>

      Always includes input_tokens->estimated(gateway_tokenizer).

  • 400

    Invalid request, in the Anthropic envelope. The message names the field.

    レスポンス
    • typestring
    • errorobject
      error
      • typestring

        For example invalid_request_error, authentication_error, permission_error, rate_limit_error, api_error.

      • messagestring
  • 401

    The key is missing or invalid.

    レスポンス
    • typestring
    • errorobject
      error
      • typestring

        For example invalid_request_error, authentication_error, permission_error, rate_limit_error, api_error.

      • messagestring
  • 404

    The model is unknown or not callable by this key.

    レスポンス
    • typestring
    • errorobject
      error
      • typestring

        For example invalid_request_error, authentication_error, permission_error, rate_limit_error, api_error.

      • messagestring

リクエスト

curl -X POST https://api.experientiallabs.ai/v1/messages/count_tokens \
  -H "x-api-key: YOUR_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{
  "model": "claude-sonnet-5.5",
  "messages": [
    {
      "role": "user",
      "content": "Explain a mutex in one sentence."
    }
  ]
}'

レスポンス

{
  "input_tokens": 15,
  "x-experiential-ignored-parameters": [
    "input_tokens->estimated(gateway_tokenizer)"
  ]
}

https://api.experientiallabs.ai/v1/messages/count_tokens