Skip to content
API referenceCount the tokens in a message

Count the tokens in a message

POST/v1/messages/count_tokens

Count the tokens in a message.

Compatible with Anthropic's Count Message Tokens API: the body is a Messages request (without max_tokens) and the answer is {"input_tokens": N}, the input tokens that request would use, from Anthropic's own counter (Anthropic, or Claude on Vertex). Same credentials and virtual key checks as creating a message. Nothing is generated, so nothing is billed or logged, and no cache, retries, fallbacks or guardrails apply.

Errors are in Anthropic's shape: 400 for an invalid request, a key for any other provider, or a routing config (x-config); 401 for a missing or invalid credential; 403 when the virtual key is disabled, expired or the model is not allowed.

Compatible with the Anthropic Count Message Tokens API. The request and response bodies are the provider's own format, passed through by the gateway: see the Anthropic Count Message Tokens API reference for every field. The credentials and headers below are what VectorAxis adds.

Authorization

  • AuthorizationBearer <slug>.<secret>

    A virtual key's API key (vk-....<secret>), as Authorization: Bearer. What the OpenAI SDK sends from its api_key. Used by the inference endpoints.

  • orx-virtual-keyheader

    A virtual key's API key in the x-virtual-key header, for clients that keep Authorization for something else.

  • orx-api-keyheader

    Direct credentials: the provider's own API key in x-api-key, with the provider named in x-provider (for example openai). On /v1/messages a virtual key is accepted in x-api-key too, which is what the Claude SDK sends.

Headers

  • x-providerstring

    With direct credentials: the provider x-api-key belongs to, for example openai or anthropic (case and dashes are normalised). Not used with a virtual key.

  • x-vertex-projectstring

    Google Vertex AI keys only: the GCP project to call, instead of the one stored with the key.

  • x-vertex-regionstring

    Google Vertex AI keys only: the region to call (or global), instead of the one stored with the key.

  • anthropic-betastring

    Anthropic beta features, comma-separated (for example context-management-2025-06-27). Forwarded to Anthropic and Claude on Vertex only; at most 32 names of lower-case letters, digits and dashes.

Responses

200application/json
NVIDIA Inception Program member

VectorAxis is built by GK Labs, a member of NVIDIA Inception.