/v1/messages/count_tokensCount 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.
レスポンス
200The estimate.
レスポンス
input_tokensintegerEstimated input tokens.
x-experiential-ignored-parametersarray<string>Always includes
input_tokens->estimated(gateway_tokenizer).
400Invalid request, in the Anthropic envelope. The message names the field.
レスポンス
typestringerrorobjecterror
typestringFor example
invalid_request_error,authentication_error,permission_error,rate_limit_error,api_error.messagestring
401The key is missing or invalid.
レスポンス
typestringerrorobjecterror
typestringFor example
invalid_request_error,authentication_error,permission_error,rate_limit_error,api_error.messagestring
404The model is unknown or not callable by this key.
レスポンス
typestringerrorobjecterror
typestringFor 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