Anthropic Token Count
Count input tokens using the Anthropic provider tokenizer
This endpoint sends the request to Anthropic's tokenizer. The selected model must have an Anthropic provider route and available provider credentials. Include model and messages; max_tokens is not required.
For a local text-only estimate without a provider call, use Count Tokens.
Count tokens using Anthropic’s provider tokenizer. Requires a model with an Anthropic provider route and provider credentials. Unlike /v1/count_tokens, this sends the request to Anthropic and includes supported tool/system input. max_tokens is not required. Subscription passthrough is a separate CLI flow.
https://edgee.io/v1/messages/count_tokensTry this endpoint
Configure your request, then run the curl command in your terminal or send it from this page.
Run in your terminal
Set EDGEE_API_KEY to your Gateway API key in your terminal, then copy and run this command. Gateway requests may consume credits.
curl --include --no-buffer --globoff --request POST 'https://edgee.io/v1/messages/count_tokens' \
--header "Authorization: Bearer $EDGEE_API_KEY" \
--header 'Content-Type: application/json' \
--data-raw '{
"model": "anthropic/claude-sonnet-4-6",
"messages": [
{
"role": "user",
"content": "Hello!"
}
]
}'Send from browser
Your request is relayed through the Edgee documentation server to the Gateway. Your key is used only for this request and is not stored.
Authentication
Use an Edgee Gateway API key. Send it as Authorization: Bearer <key> or x-api-key: <key>.
Request body
Anthropic provider token counting. No max_tokens is required. Requires an available Anthropic provider route for the selected model; this is not the local estimator.
modelstringrequiredModel identifier from GET /v1/models, in author/model format, or a configured global alias. Append :provider to request a specific provider route. Available models and providers depend on your key and organization policies.
messagesarrayrequiredArray of message objects
Show schema
rolestringrequiredThe role of the message
contentunionrequiredShow schema
Simple text content
stringArray of content blocks
Common Anthropic content blocks. Native dispatch can carry additional provider-specific blocks; conversion paths only preserve supported content. Cross-provider reasoning is emitted as text, never as forged signed thinking blocks.
typestringrequiredtextstringrequiredcache_controlobjecttypestringrequiredidstringrequirednamestringrequiredinputobjectrequiredtypestringrequiredtool_use_idstringrequiredcontentunionrequiredis_errorbooleancache_controlobjecttypestringrequiredsourceunionrequiredcache_controlobjecttypestringrequiredthinkingstringrequiredsignaturestringPreserve provider-issued signatures when replaying history. Unsigned thinking blocks are stripped before upstream Anthropic calls.
typestringrequireddatastringrequiredsystemunionShow schema
System prompt as a string
stringSystem prompt as content blocks
Common Anthropic content blocks. Native dispatch can carry additional provider-specific blocks; conversion paths only preserve supported content. Cross-provider reasoning is emitted as text, never as forged signed thinking blocks.
typestringrequiredtextstringrequiredcache_controlobjectShow schema
typestringrequiredttlstringtypestringrequiredidstringrequirednamestringrequiredinputobjectrequiredtypestringrequiredtool_use_idstringrequiredcontentunionrequiredShow schema
stringtypestringrequiredtextstringrequiredcache_controlobjecttypestringrequiredsourceunionrequiredis_errorbooleancache_controlobjectShow schema
typestringrequiredttlstringtypestringrequiredsourceunionrequiredShow schema
typestringrequiredurlstringrequiredtypestringrequiredmedia_typestringrequireddatastringrequiredcache_controlobjectShow schema
typestringrequiredttlstringtypestringrequiredthinkingstringrequiredsignaturestringPreserve provider-issued signatures when replaying history. Unsigned thinking blocks are stripped before upstream Anthropic calls.
typestringrequireddatastringrequiredtoolsarrayTool definitions
Show schema
namestringrequiredThe name of the tool
descriptionstringDescription of what the tool does
input_schemaobjectJSON Schema describing the tool's input parameters
cache_controlobjectShow schema
typestringrequiredttlstringtool_choiceobjectShow schema
typestringrequiredModel decides whether to use tools
typestringrequiredModel must use one of the provided tools
typestringrequirednamestringrequiredName of the specific tool to use
{
"model": "anthropic/claude-sonnet-4-6",
"messages": [
{
"role": "user",
"content": "Hello!"
}
]
}Responses
200Token count estimated successfully
application/json
input_tokensintegerrequiredEstimated number of input tokens for the provided messages. This is an approximation, counts may differ from provider-native tokenizers. Use for estimation and budgeting, not exact billing.
{
"input_tokens": 14
}400Malformed request, invalid/disabled model or provider, or unsupported conversion.
application/json
typestringrequirederrorobjectrequiredShow schema
typestringrequiredmessagestringrequiredrequest_idstringOpenAI-shaped Gateway error. Native upstream errors can retain provider-specific details.
errorobjectrequiredShow schema
messagestringrequiredA human-readable error message.
typestringrequiredHigh-level error category.
codestringMachine-readable error code, for example unauthorized, invalid_json, bad_model_id, model_disabled, provider_disabled, usage_limit_exceeded, usage_unavailable, provider_error or internal_error. Not an exhaustive enum.
paramstringName of the request parameter that caused the error, when applicable.
401Missing or invalid API credentials.
application/json
typestringrequirederrorobjectrequiredShow schema
typestringrequiredmessagestringrequiredrequest_idstringOpenAI-shaped Gateway error. Native upstream errors can retain provider-specific details.
errorobjectrequiredShow schema
messagestringrequiredA human-readable error message.
typestringrequiredHigh-level error category.
codestringMachine-readable error code, for example unauthorized, invalid_json, bad_model_id, model_disabled, provider_disabled, usage_limit_exceeded, usage_unavailable, provider_error or internal_error. Not an exhaustive enum.
paramstringName of the request parameter that caused the error, when applicable.
403Key inactive, expired, model restriction or other permission failure.
application/json
typestringrequirederrorobjectrequiredShow schema
typestringrequiredmessagestringrequiredrequest_idstringOpenAI-shaped Gateway error. Native upstream errors can retain provider-specific details.
errorobjectrequiredShow schema
messagestringrequiredA human-readable error message.
typestringrequiredHigh-level error category.
codestringMachine-readable error code, for example unauthorized, invalid_json, bad_model_id, model_disabled, provider_disabled, usage_limit_exceeded, usage_unavailable, provider_error or internal_error. Not an exhaustive enum.
paramstringName of the request parameter that caused the error, when applicable.
500Internal processing error.
application/json
typestringrequirederrorobjectrequiredShow schema
typestringrequiredmessagestringrequiredrequest_idstringOpenAI-shaped Gateway error. Native upstream errors can retain provider-specific details.
errorobjectrequiredShow schema
messagestringrequiredA human-readable error message.
typestringrequiredHigh-level error category.
codestringMachine-readable error code, for example unauthorized, invalid_json, bad_model_id, model_disabled, provider_disabled, usage_limit_exceeded, usage_unavailable, provider_error or internal_error. Not an exhaustive enum.
paramstringName of the request parameter that caused the error, when applicable.