Skip to content

Count message input tokens

POST
/messages/count_tokens
curl --request POST \
--url https://api.katara.com/v1/messages/count_tokens \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{ "model": "katara/cortex", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "example", "cache_control": { "type": "ephemeral", "ttl": "5m" } } ] } ], "system": [ { "type": "text", "text": "example", "cache_control": { "type": "ephemeral", "ttl": "5m" } } ], "tools": [ { "type": "custom", "name": "example", "description": "example", "input_schema": { "type": "object" }, "strict": true, "input_examples": [ "example" ], "eager_input_streaming": true, "allowed_callers": [ "example" ], "defer_loading": false, "cache_control": { "type": "ephemeral", "ttl": "5m" } } ], "tool_choice": { "type": "auto", "name": "example", "disable_parallel_tool_use": true }, "thinking": { "type": "example" }, "output_config": { "effort": "example", "format": {} }, "output_format": {}, "cache_control": { "type": "ephemeral", "ttl": "5m" }, "context_management": {}, "compaction": {}, "metadata": { "user_id": "example" }, "katara": { "task": "example", "session": "example", "reset_session": true, "summary": "example", "community": true, "knowledge": true, "cache": {}, "context_edits": {}, "compaction": {} } }'

A conservative estimate of the request’s input for context management. Runs no model and holds no payment; billed usage comes only from inference. Text, tool calls and tool definitions count one token per three bytes, plus 16 for the request, 4 per message and 16 per tool; an image counts 2,240, a PDF page 1,120 and a stored file 4,480. Generation controls are accepted and ignored.

Media typeapplication/json

Fields not listed here are refused, except the accepted and ignored service_tier, speed, inference_geo, top_k, diagnostics, fallbacks, fallback_credit_token and metadata.user_id. thread is refused; send the whole conversation in messages.

object
model

Any model name; every one is served by Katara Cortex. Without a key, katara/cortex-genius or katara/cortex-smart fix the model; a request with a key that names either is refused with model_requires_x402.

string
default: katara/cortex
messages
required

The last message must be from the user; assistant prefill is refused.

Array<object>
>= 1 items
object
role
required
string
Allowed values: user assistant
content
required
One of:
string
system
One of:
string
tools
Array
Any of:

A client tool.

object
type
string
Allowed values: custom
name
required
string
/^[a-zA-Z0-9_-]{1,128}$/
description
string
input_schema
required
object
type
required
Allowed value: object
key
additional properties
any
strict
boolean
input_examples
Array
eager_input_streaming
boolean
allowed_callers
Array<string>
defer_loading
boolean
cache_control
object
type
required
Allowed value: ephemeral
ttl
string
Allowed values: 5m 1h
tool_choice
object
type
required
string
Allowed values: auto none any tool
name

Required with type tool; must name a declared tool.

string
disable_parallel_tool_use

True gets at most one tool call per reply.

boolean
thinking

Accepted in every form and ignored; Katara Cortex decides how much the model reasons.

object
type
string
key
additional properties
any
output_config
object
effort

Accepted and ignored.

string
format

A JSON schema output format.

object
key
additional properties
any
output_format

A JSON schema output format.

object
cache_control
object
type
required
Allowed value: ephemeral
ttl
string
Allowed values: 5m 1h
context_management

clear_tool_uses_20250919, clear_thinking_20251015 and compact_20260112 edits, served by Katara’s context management.

object
key
additional properties
any
compaction

Served by Katara’s compaction.

object
key
additional properties
any
metadata
object
user_id

Discarded before inference.

string
katara
object
task
string
session

Opaque routing token from the last served reply; it grants no payment authority.

string
reset_session

Start a new routing session explicitly.

boolean
summary

A short step summary, limited to 80 words by Katara Cortex.

string
community
boolean
knowledge
boolean
cache

As katara.cache on Chat Completions.

object
key
additional properties
any
context_edits

As katara.context_edits on Chat Completions.

object
key
additional properties
any
compaction

As katara.compaction on Chat Completions.

object
key
additional properties
any

The estimate.

Media typeapplication/json
object
input_tokens
required
integer
katara
object
estimated
required
boolean
estimation_method
required
string
Allowed value: conservative-v2
bytes_per_token
integer
Allowed value: 3
Example
{
"katara": {
"estimated": true,
"estimation_method": "conservative-v2",
"bytes_per_token": 3
}
}
X-Katara-Token-Count
string
Allowed value: conservative-estimate

Malformed input.

Media typeapplication/json
object
type
required
Allowed value: error
error
required
object
type
required
string
message
required
string
code
required
string
key
additional properties
any
key
additional properties
any
Example
{
"type": "error"
}

Missing, expired or invalid key.

Media typeapplication/json
object
type
required
Allowed value: error
error
required
object
type
required
string
message
required
string
code
required
string
key
additional properties
any
key
additional properties
any
Example
{
"type": "error"
}