Count message tokens
POST/v1/messages/count_tokens
Counts a Messages request's input tokens without calling a model. Since 1.8.5. On a route to Anthropic the count is Anthropic's own; otherwise it is DVARA's estimate.
Workspace status, policy, prompt templates, PII, and guardrails run on
the request. No model is called, no usage or cost is booked, and the
count does not count against a call cap or the unlicensed call band.
The rate limit counts it as a request. Same key and scope as
/v1/messages.
Request
Responses
- 200
- 400
- 401
- 403
- 413
- 429
- 500
The input token count
Invalid request, unsupported field or capability, unknown model, a missing or other anthropic-version, or a PII BLOCK action (pii_detected).
A key is required. Missing, invalid, revoked, or expired keys are refused.
Policy, guardrail, scope, or IP access refused the call.
The request is over a guardrail size limit (input_too_large). The type is request_too_large.
Per-key rate limit reached.
An unexpected error in the gateway. The type is api_error.