Count Tokens
Anthropic Messages token-counting compatible endpoint. Returns the number of input tokens a Messages request would consume, without creating a message. Mirrors Anthropic’s POST /v1/messages/count_tokens (same request body as the Messages endpoint, minus the required max_tokens). Supported for Claude models; other models return 400.
Authorizations
API key authentication. Pass your API key as a Bearer token.
Headers
Function name for tracing and project-level guardrail function-scope filtering.
Parent span ID for distributed tracing context.
Comma-separated key:value usage-attribution tags (e.g. tenant:acme,project:demo, max 8). Recorded on the generation's billing/metrics rows; group spend by any key via GET /v2/analytics/usage?group_by=. Header-borne twin of the /v3/session URL prefix tags (which win per key when both are present); opper.-prefixed keys and session_id are reserved. Malformed values return 400.
Body
Opt in to top-level automatic prompt caching: {"type":"ephemeral"} (optionally "ttl":"1h"). Places one moving breakpoint on the largest cacheable prefix. Explicit per-block cache_control on system/message/tool content takes precedence. Caching is off unless set. Cache writes cost 1.25x input and reads 0.1x
Any value
Any value
Any value
Response
Successful response
The number of input tokens the request would consume.