Tokens

Count tokens

Estimate text tokens locally without a provider call. Requires model, accepts optional messages and system. Counts plain content strings and type:text blocks only. Images, tool definitions, non-text blocks and message framing overhead are not counted; this is not a provider billing estimate. Tokenizer selection uses the configured provider model name unless explicitly overridden.

post/v1/count_tokens

Request

  • Base URL: https://edgee.io
  • URL: https://edgee.io/v1/count_tokens
  • Auth: one of:
    • HTTP bearer
    • API key in header x-api-key

Request body

modelstring required

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.

messagesobject[]

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.

tokenizer'cl100k_base' | 'o200k_base'

Explicit tokenizer override. When omitted, the gateway picks one based on model.

Example request

{
  "model": "openai/gpt-5.2"
}

Response

Token count estimated successfully

input_tokensinteger required

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.

Example response

{
  "input_tokens": 42
}

Changes

No recorded changes to this operation across all 1 revision of this API.