Skip to main content
POST
Count tokens
This endpoint returns an estimate, not an exact model-tokenizer count. It does not run a generation. Use it as a rough input-size signal; final usage and request admission can differ.
string
required
Your derestricted API key. A Bearer token is also accepted. The account must be active and verified.
array
required
Messages to include in the estimate.
string or array
Optional system instructions to include.
array
Optional tool definitions to include.

Example

The response is an object containing input_tokens, an integer estimate.

How to interpret the estimate

The current implementation estimates from the serialized UTF-8 size of system, messages, and tools, adds per-message and fixed overhead, divides by four, and rounds upward. It does not invoke the deployed model’s tokenizer. This endpoint does not reserve credit, check whether your output allowance is affordable, or guarantee that the generation will fit the context/input limits. A later generation can still return a size, credit, or capacity error. Use actual response usage for completed-request token counts. The same 4 MiB JSON-body limit applies. See Messages to generate a response.