Count tokens (Messages)

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

The Messages counterpart of token counting: send a Messages request body and get the input token count without running the model. Free, and validated exactly like the real request.

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
modelstringYesThe model whose tokenizer to use.
systemstring or arrayNoSystem instructions.
messagesarrayYesContent-block messages.
toolsarrayNoTool definitions.

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/messages/count_tokens \
  -H "Authorization: Bearer $SYNTIC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
      "model": "Amara S1.2",
      "system": "You are a careful contracts assistant.",
      "messages": [
        {
          "role": "user",
          "content": [
            {
              "type": "text",
              "text": "Summarise clause 14."
            }
          ]
        }
      ]
    }'

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.
Was this page helpful?