curl --request POST \
--url https://api.edgee.ai/v1/count_tokens \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "openai/gpt-5.2",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "What is the capital of France?"
}
]
}
'{
"input_tokens": 42
}Estimate token count for a set of messages without making an LLM call
curl --request POST \
--url https://api.edgee.ai/v1/count_tokens \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "openai/gpt-5.2",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "What is the capital of France?"
}
]
}
'{
"input_tokens": 42
}Estimates the number of input tokens for a set of messages without sending the request to an LLM provider. Useful for pre-flight cost estimation, rate-limit planning, and prompt optimization.Documentation Index
Fetch the complete documentation index at: https://www.edgee.ai/docs/llms.txt
Use this file to discover all available pages before exploring further.
ID of the target model. Format: {author_id}/{model_id}. The gateway uses this to pick the appropriate tokenizer when tokenizer is not provided.
"openai/gpt-5.2"
Optional array of message objects to count tokens for. Accepts both OpenAI chat format (with system, user, assistant roles) and Anthropic Messages format; the format is auto-detected from the message structure. Defaults to an empty array.
Show child attributes
Optional system prompt. Accepts a plain string or an array of Anthropic content blocks. Used when counting tokens for an Anthropic-style request.
Explicit tokenizer override. When omitted, the gateway picks one based on model.
cl100k_base, o200k_base Token count estimated successfully
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.
x >= 042
Was this page helpful?