API reference

Count tokens

Count or estimate the input tokens in a Messages request.

Request fields come from the gateway's OpenAPI document. See authentication and headers and errors.

The OpenAPI document does not define response schemas for these routes. Missing response fields below do not mean the API returns an empty response.

POST
/v1/messages/count_tokens

Authorization

headerAuthorizationBearer <token>

Request Body

application/json
  1. body
model*string
Length1 <= length
system?string|array<>
messages*array<|>
Items1 <= items
temperature?number
Range0 <= value <= 1
top_p?number
Range0 <= value <= 1
top_k?integer
Range0 <= value <= 9007199254740991
stop_sequences?array<string>
tools?array<>
cache_control?|null
tool_choice?|
thinking?|||
output_config?
metadata?
[key: string]?unknown

Response Body

Default Response

curl -X POST 'https://unused.market/v1/messages/count_tokens' \  -H 'Content-Type: application/json' \  -d '{  "model": "string",  "messages": [    {      "role": "user",      "content": "string"    }  ],  "property1": null,  "property2": null}'
Empty