Count message input tokens
const url = 'https://api.katara.com/v1/messages/count_tokens';const options = { method: 'POST', headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'}, body: '{"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":{}}}'};
try { const response = await fetch(url, options); const data = await response.json(); console.log(data);} catch (error) { console.error(error);}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.
Authorizations
Section titled “Authorizations”Request Bodyrequired
Section titled “Request Bodyrequired”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
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.
The last message must be from the user; assistant prefill is refused.
object
object
object
object
Base64 with media_type (image/jpeg, image/png, image/gif or image/webp) and data; url with an https url; or file with a file_id.
object
object
object
Base64 PDF, text, content blocks or file with a file_id. A url source is refused.
object
object
object
object
object
object
object
object
object
Text, image, document and search_result blocks.
object
object
object
Empty on Katara’s replies; any value is accepted in history.
Accepted in history and dropped.
object
object
object
object
object
object
object
object
A client tool.
object
object
object
An Anthropic versioned client tool, expanded into an ordinary tool with its published name and schema.
object
object
Web search, run by Katara; the model calls after the first search run on managed models. At most five searches per request. A request that ends without an answer is charged nothing for its searches or the calls after them.
object
Lowers the cap of five.
Not with allowed_domains.
object
object
object
Required with type tool; must name a declared tool.
True gets at most one tool call per reply.
Accepted in every form and ignored; Katara Cortex decides how much the model reasons.
object
object
Accepted and ignored.
A JSON schema output format.
object
A JSON schema output format.
object
object
clear_tool_uses_20250919, clear_thinking_20251015 and compact_20260112 edits, served by Katara’s context management.
object
Served by Katara’s compaction.
object
object
Discarded before inference.
object
Opaque routing token from the last served reply; it grants no payment authority.
Start a new routing session explicitly.
A short step summary, limited to 80 words by Katara Cortex.
As katara.cache on Chat Completions.
object
As katara.context_edits on Chat Completions.
object
As katara.compaction on Chat Completions.
object
Responses
Section titled “Responses”The estimate.
object
object
Example
{ "katara": { "estimated": true, "estimation_method": "conservative-v2", "bytes_per_token": 3 }}Headers
Section titled “Headers”Malformed input.
object
object
Example
{ "type": "error"}Missing, expired or invalid key.
object
object
Example
{ "type": "error"}