Anthropic

Estimate input tokens for an Anthropic Messages request

Heuristic input-token estimator. Accepts the same shape as /v1/messages minus max_tokens (optional here per the Anthropic spec). Returns {"input_tokens": N}.

v1 is a heuristic (4 chars/token + per-message overhead + per-image fixed cost), not a real BPE tokenizer call. Targets ±10 % accuracy across representative shapes. Sufficient for Claude Code's advisory context-window display.

Auth identical to /v1/messages: Authorization: Bearer tp_<64 hex>, validated by the unified middleware before dispatch.

post/v1/messages/count_tokens

Request

  • Base URL: http://localhost:9998
  • URL: http://localhost:9998/v1/messages/count_tokens
  • Auth: HTTP bearer

Request body

modelstring required
max_tokensinteger

Optional here. If present, must still be a positive integer ≤ 100000.

temperaturenumber
top_pnumber
top_kinteger
stop_sequencesstring[]
metadataobject

Response

Estimated input token count

input_tokensinteger required

Heuristic estimate (4 chars/token + per-message + per-image cost).

Changes

No recorded changes to this operation across all 1 revision of this API.