Count tokens

⚠️
Preview — this feature is being built; the design below is the spec.
POST https://app.syntic.ai/v1/chat/completions/count_tokens

Count the input tokens a chat completion would use, without running the model. The body is the same as for Create a chat completion; output-only fields such as max_tokens and stream are accepted and ignored, so you can pass your real request unchanged. Counting is free and does not use plan allowance.

For how this fits into a full workflow, see Token counting.

Headers

HeaderRequiredValue
AuthorizationYesBearer <key>: a private inference key (sk_live_...). See Authentication.
Content-TypeYesapplication/json

Body parameters

ParameterTypeRequiredNotes
modelstringYesTokenizers differ between models, so the model is required here.
messagesarrayYesCounted in full, including tool calls and results.
toolsarrayNoCounted as presented to the model.
response_formatobjectNoA schema adds input tokens.

Response

200 OK, Content-Type: application/json

{
  "object": "token_count",
  "model": "Amara S1.2",
  "input_tokens": 18342,
  "details": {
    "system_tokens": 412,
    "message_tokens": 15210,
    "tool_tokens": 1890,
    "image_tokens": 765,
    "document_tokens": 0
  },
  "context_window": 262144,
  "remaining_tokens": 243802
}
FieldTypeDescription
input_tokensintegerWhat usage.prompt_tokens would report for the same request, including the Syntic identity instruction.
detailsobjectBreakdown by source; the parts add up to input_tokens.
context_windowintegerThe model’s context size.
remaining_tokensintegercontext_window minus input_tokens. The reply must fit here.

Examples

curl -sS https://app.syntic.ai/v1/chat/completions/count_tokens \
  -H "Authorization: Bearer $SYNTIC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
      "model": "Amara S1.2",
      "messages": [
        {
          "role": "system",
          "content": "You are a careful contracts assistant."
        },
        {
          "role": "user",
          "content": "Summarise clause 14 of the lease below. ..."
        }
      ]
    }'

Errors

Errors use the error envelope and carry a request_id. Codes specific to this operation:

StatustypecodeWhen
400invalid_request_errormessages_requiredNo messages.
400invalid_request_errormodel_requiredmodel is missing. Counting has no default model.
404not_found_errormodel_not_foundUnknown model name.
401authentication_errorinvalid_api_keyThe key is missing, unknown, revoked or expired.
429rate_limit_errorrate_limitedToo many requests; wait for Retry-After. See Rate-limit headers.

Limits

Counting is capped separately from inference, at 100 calls a minute per key. Server-side tool results added during a real request (for example web search results) cannot be known in advance and are not included.

Was this page helpful?