Skip to content
LLM Router
Gateway API

Anthropic Token Count

Count input tokens using the Anthropic provider tokenizer

POST/v1/messages/count_tokens

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.

POSThttps://edgee.io/v1/messages/count_tokens

Try 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
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.

modelstringrequired

Model 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.

messagesarrayrequired

Array of message objects

Show schema
rolestringrequired

The role of the message

Values: user, assistant
contentunionrequired
Show schema
Option 1

Simple text content

string
Option 2

Array 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.

Option 1
typestringrequired
Values: text
textstringrequired
cache_controlobject
Option 2
typestringrequired
Values: tool_use
idstringrequired
namestringrequired
inputobjectrequired
Option 3
typestringrequired
Values: tool_result
tool_use_idstringrequired
contentunionrequired
is_errorboolean
Default: false
cache_controlobject
Option 4
typestringrequired
Values: image
sourceunionrequired
cache_controlobject
Option 5
typestringrequired
Values: thinking
thinkingstringrequired
signaturestring

Preserve provider-issued signatures when replaying history. Unsigned thinking blocks are stripped before upstream Anthropic calls.

Option 6
typestringrequired
Values: redacted_thinking
datastringrequired
systemunion
Show schema
Option 1

System prompt as a string

string
Option 2

System 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.

Option 1
typestringrequired
Values: text
textstringrequired
cache_controlobject
Show schema
typestringrequired
Values: ephemeral
ttlstring
Values: 5m, 1h
Option 2
typestringrequired
Values: tool_use
idstringrequired
namestringrequired
inputobjectrequired
Option 3
typestringrequired
Values: tool_result
tool_use_idstringrequired
contentunionrequired
Show schema
Option 1
string
Option 2
Option 1
typestringrequired
Values: text
textstringrequired
cache_controlobject
Option 2
typestringrequired
Values: image
sourceunionrequired
is_errorboolean
Default: false
cache_controlobject
Show schema
typestringrequired
Values: ephemeral
ttlstring
Values: 5m, 1h
Option 4
typestringrequired
Values: image
sourceunionrequired
Show schema
Option 1
typestringrequired
Values: url
urlstringrequired
Option 2
typestringrequired
Values: base64
media_typestringrequired
datastringrequired
cache_controlobject
Show schema
typestringrequired
Values: ephemeral
ttlstring
Values: 5m, 1h
Option 5
typestringrequired
Values: thinking
thinkingstringrequired
signaturestring

Preserve provider-issued signatures when replaying history. Unsigned thinking blocks are stripped before upstream Anthropic calls.

Option 6
typestringrequired
Values: redacted_thinking
datastringrequired
toolsarray

Tool definitions

Show schema
namestringrequired

The name of the tool

descriptionstring

Description of what the tool does

input_schemaobject

JSON Schema describing the tool's input parameters

Default: {"type":"object","properties":{}}
cache_controlobject
Show schema
typestringrequired
Values: ephemeral
ttlstring
Values: 5m, 1h
tool_choiceobject
Show schema
Option 1
typestringrequired

Model decides whether to use tools

Values: auto
Option 2
typestringrequired

Model must use one of the provided tools

Values: any
Option 3
typestringrequired
Values: tool
namestringrequired

Name 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_tokensintegerrequired

Estimated 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

Option 1
typestringrequired
Values: error
errorobjectrequired
Show schema
typestringrequired
messagestringrequired
request_idstring
Option 2

OpenAI-shaped Gateway error. Native upstream errors can retain provider-specific details.

errorobjectrequired
Show schema
messagestringrequired

A human-readable error message.

typestringrequired

High-level error category.

codestring

Machine-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.

paramstring

Name of the request parameter that caused the error, when applicable.

401Missing or invalid API credentials.

application/json

Option 1
typestringrequired
Values: error
errorobjectrequired
Show schema
typestringrequired
messagestringrequired
request_idstring
Option 2

OpenAI-shaped Gateway error. Native upstream errors can retain provider-specific details.

errorobjectrequired
Show schema
messagestringrequired

A human-readable error message.

typestringrequired

High-level error category.

codestring

Machine-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.

paramstring

Name of the request parameter that caused the error, when applicable.

403Key inactive, expired, model restriction or other permission failure.

application/json

Option 1
typestringrequired
Values: error
errorobjectrequired
Show schema
typestringrequired
messagestringrequired
request_idstring
Option 2

OpenAI-shaped Gateway error. Native upstream errors can retain provider-specific details.

errorobjectrequired
Show schema
messagestringrequired

A human-readable error message.

typestringrequired

High-level error category.

codestring

Machine-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.

paramstring

Name of the request parameter that caused the error, when applicable.

500Internal processing error.

application/json

Option 1
typestringrequired
Values: error
errorobjectrequired
Show schema
typestringrequired
messagestringrequired
request_idstring
Option 2

OpenAI-shaped Gateway error. Native upstream errors can retain provider-specific details.

errorobjectrequired
Show schema
messagestringrequired

A human-readable error message.

typestringrequired

High-level error category.

codestring

Machine-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.

paramstring

Name of the request parameter that caused the error, when applicable.

Download the OpenAPI specification