POST /ai/v1/messages/count_tokensCount input tokens for a supported Anthropic deployment without generating content or charging credits.
Servers
[ { "url": "https://api.veryfront.com" }]Authentication
[ { "bearerAuth": [] }, { "apiKeyAuth": [] }]{ "bearerAuth": { "type": "http", "scheme": "bearer", "bearerFormat": "JWT or API Key", "description": "Use a JWT bearer token or a Veryfront API key in the `Authorization` header." }, "apiKeyAuth": { "type": "apiKey", "in": "header", "name": "X-API-Key", "description": "Alternative API key header for `vf_<prefix>_<secret>` tokens." }}Parameters
Parameter contracts
[ { "schema": { "type": "string", "minLength": 1, "maxLength": 255, "description": "Canonical project selector: a UUID or slug for model access, inference and billing context. A signed project scope takes precedence. Otherwise, send only one project selector header." }, "required": false, "name": "x-veryfront-project-reference", "in": "header" }, { "schema": { "type": "string", "minLength": 1, "maxLength": 255, "description": "Compatibility selector accepting a project UUID. Prefer x-veryfront-project-reference." }, "required": false, "name": "x-veryfront-project-id", "in": "header" }, { "schema": { "type": "string", "minLength": 1, "maxLength": 255, "description": "Compatibility selector accepting a project slug. Prefer x-veryfront-project-reference." }, "required": false, "name": "x-veryfront-project-slug", "in": "header" }, { "schema": { "type": "string", "minLength": 1, "maxLength": 245, "description": "Durable run ID. Required for run-bound service-account credentials." }, "required": false, "name": "x-veryfront-agent-run-id", "in": "header" }, { "schema": { "type": "string", "minLength": 1, "maxLength": 255, "description": "Durable conversation ID. Required with agent run attribution." }, "required": false, "name": "x-veryfront-conversation-id", "in": "header" }, { "schema": { "type": "string", "minLength": 1, "maxLength": 255, "description": "Durable message ID. Required with agent run attribution." }, "required": false, "name": "x-veryfront-message-id", "in": "header" }, { "schema": { "type": "string", "minLength": 1, "maxLength": 255, "description": "Agent ID. Must match the authenticated run-bound credential." }, "required": false, "name": "x-veryfront-agent-id", "in": "header" }, { "schema": { "type": "string", "minLength": 1, "maxLength": 255, "description": "Optional billing group. Run requests are pinned to agent-run:<run-id>." }, "required": false, "name": "x-veryfront-billing-group-id", "in": "header" }]Request body
{ "required": true, "content": { "application/json": { "schema": { "title": "NeutralAnthropicCountTokensRequest", "description": "Anthropic-compatible input-token count request. Requires a permitted deployment that serves count-tokens. Unsupported model deployments return a typed 404; counting performs no generation or credit charge.", "type": "object", "properties": { "model": { "type": "string", "description": "Catalog model ID or alias. Required: the request is routed by model, not by base URL." }, "messages": { "type": "array", "items": {}, "description": "Vendor-shaped messages, forwarded as sent." } }, "required": [ "model", "messages" ], "additionalProperties": true } } }}Responses
200
Input-token count for the permitted deployment; no generation or credit charge.
{ "description": "Input-token count for the permitted deployment; no generation or credit charge.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/AnthropicTokenCountResponse" } } }}400
Invalid request
{ "description": "Invalid request", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/NeutralAnthropicError" } } }}401
Unauthorized
{ "description": "Unauthorized", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/NeutralAnthropicError" } } }}402
Insufficient AI credits, an exhausted monthly AI budget, or a provider spend limit
{ "description": "Insufficient AI credits, an exhausted monthly AI budget, or a provider spend limit", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/NeutralAnthropicError" } } }}403
Project access denied
{ "description": "Project access denied", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/NeutralAnthropicError" } } }}404
The selected model has no permitted token-counting deployment. Clients may fall back to a character estimate.
{ "description": "The selected model has no permitted token-counting deployment. Clients may fall back to a character estimate.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/NeutralAnthropicError" } } }}413
Request body over the 32 MiB limit (code request_too_large), or an upstream 413 re-rendered in this envelope
{ "description": "Request body over the 32 MiB limit (code request_too_large), or an upstream 413 re-rendered in this envelope"}429
Optional API-key limits or mandatory token-count user, originating-key, project or platform request/attempt quotas were exceeded. Gateway refusals include Retry-After; upstream 429s retain any provider retry headers.
{ "description": "Optional API-key limits or mandatory token-count user, originating-key, project or platform request/attempt quotas were exceeded. Gateway refusals include Retry-After; upstream 429s retain any provider retry headers."}500
Gateway error, or an upstream 500 re-rendered in this envelope
{ "description": "Gateway error, or an upstream 500 re-rendered in this envelope"}502
Gateway proxy error, or an upstream 502 re-rendered in this envelope
{ "description": "Gateway proxy error, or an upstream 502 re-rendered in this envelope"}503
No available deployment, auth unavailable, or an upstream 503 re-rendered in this envelope
{ "description": "No available deployment, auth unavailable, or an upstream 503 re-rendered in this envelope"}529
Upstream provider overloaded, re-rendered in this envelope
{ "description": "Upstream provider overloaded, re-rendered in this envelope"}default
Any other status the upstream provider returned, with the upstream status and its body (if any) re-rendered in this envelope
{ "description": "Any other status the upstream provider returned, with the upstream status and its body (if any) re-rendered in this envelope"}Referenced contracts
components/schemas/AnthropicTokenCountResponse
{ "type": "object", "properties": { "input_tokens": { "type": "integer", "minimum": 0, "maximum": 9007199254740991 } }, "required": [ "input_tokens" ]}components/schemas/NeutralAnthropicError
{ "type": "object", "properties": { "type": { "type": "string", "enum": [ "error" ] }, "error": { "type": "object", "properties": { "type": { "type": "string" }, "message": { "type": "string" }, "code": { "type": "string" }, "veryfront": { "type": "object", "additionalProperties": {} } }, "required": [ "type", "message" ] } }, "required": [ "type", "error" ]}Operation contract
{ "operationId": "neutralCountTokens", "tags": [ "ai-gateway/Inference/Anthropic Messages" ], "summary": "Count input tokens", "description": "Count input tokens for a supported Anthropic deployment without generating content or charging credits.", "parameters": [ { "schema": { "type": "string", "minLength": 1, "maxLength": 255, "description": "Canonical project selector: a UUID or slug for model access, inference and billing context. A signed project scope takes precedence. Otherwise, send only one project selector header." }, "required": false, "name": "x-veryfront-project-reference", "in": "header" }, { "schema": { "type": "string", "minLength": 1, "maxLength": 255, "description": "Compatibility selector accepting a project UUID. Prefer x-veryfront-project-reference." }, "required": false, "name": "x-veryfront-project-id", "in": "header" }, { "schema": { "type": "string", "minLength": 1, "maxLength": 255, "description": "Compatibility selector accepting a project slug. Prefer x-veryfront-project-reference." }, "required": false, "name": "x-veryfront-project-slug", "in": "header" }, { "schema": { "type": "string", "minLength": 1, "maxLength": 245, "description": "Durable run ID. Required for run-bound service-account credentials." }, "required": false, "name": "x-veryfront-agent-run-id", "in": "header" }, { "schema": { "type": "string", "minLength": 1, "maxLength": 255, "description": "Durable conversation ID. Required with agent run attribution." }, "required": false, "name": "x-veryfront-conversation-id", "in": "header" }, { "schema": { "type": "string", "minLength": 1, "maxLength": 255, "description": "Durable message ID. Required with agent run attribution." }, "required": false, "name": "x-veryfront-message-id", "in": "header" }, { "schema": { "type": "string", "minLength": 1, "maxLength": 255, "description": "Agent ID. Must match the authenticated run-bound credential." }, "required": false, "name": "x-veryfront-agent-id", "in": "header" }, { "schema": { "type": "string", "minLength": 1, "maxLength": 255, "description": "Optional billing group. Run requests are pinned to agent-run:<run-id>." }, "required": false, "name": "x-veryfront-billing-group-id", "in": "header" } ], "requestBody": { "required": true, "content": { "application/json": { "schema": { "title": "NeutralAnthropicCountTokensRequest", "description": "Anthropic-compatible input-token count request. Requires a permitted deployment that serves count-tokens. Unsupported model deployments return a typed 404; counting performs no generation or credit charge.", "type": "object", "properties": { "model": { "type": "string", "description": "Catalog model ID or alias. Required: the request is routed by model, not by base URL." }, "messages": { "type": "array", "items": {}, "description": "Vendor-shaped messages, forwarded as sent." } }, "required": [ "model", "messages" ], "additionalProperties": true } } } }, "responses": { "200": { "description": "Input-token count for the permitted deployment; no generation or credit charge.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/AnthropicTokenCountResponse" } } } }, "400": { "description": "Invalid request", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/NeutralAnthropicError" } } } }, "401": { "description": "Unauthorized", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/NeutralAnthropicError" } } } }, "402": { "description": "Insufficient AI credits, an exhausted monthly AI budget, or a provider spend limit", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/NeutralAnthropicError" } } } }, "403": { "description": "Project access denied", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/NeutralAnthropicError" } } } }, "404": { "description": "The selected model has no permitted token-counting deployment. Clients may fall back to a character estimate.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/NeutralAnthropicError" } } } }, "413": { "description": "Request body over the 32 MiB limit (code request_too_large), or an upstream 413 re-rendered in this envelope" }, "429": { "description": "Optional API-key limits or mandatory token-count user, originating-key, project or platform request/attempt quotas were exceeded. Gateway refusals include Retry-After; upstream 429s retain any provider retry headers." }, "500": { "description": "Gateway error, or an upstream 500 re-rendered in this envelope" }, "502": { "description": "Gateway proxy error, or an upstream 502 re-rendered in this envelope" }, "503": { "description": "No available deployment, auth unavailable, or an upstream 503 re-rendered in this envelope" }, "529": { "description": "Upstream provider overloaded, re-rendered in this envelope" }, "default": { "description": "Any other status the upstream provider returned, with the upstream status and its body (if any) re-rendered in this envelope" } }, "x-documentation-source-tag": "Anthropic Messages", "x-canonical-documentation": { "domain": "ai-gateway", "resource": "Inference", "subgroup": "Anthropic Messages", "name": "Count input tokens", "description": "Count input tokens for a supported Anthropic deployment without generating content or charging credits.", "operationId": "neutralCountTokens" }, "x-mint": { "href": "/cloud/rest/api-reference/ai-gateway-inference-anthropic-messages/count-input-tokens" }}