Melious
API Reference

Count tokens

POST /v1/messages/count_tokens — preflight token count for Anthropic-shape requests

Estimate how many input tokens a Messages-API request will use, before you send it. Useful for staying under context limits or budgeting cost per request.

Endpoint:

POST /v1/messages/count_tokens

Auth: Bearer token or x-api-key. Requires scope inference.chat. Required header: anthropic-version — any recent version string.

Example

curl https://api.melious.ai/v1/messages/count_tokens \
  -H "x-api-key: sk-mel-<YOUR_API_KEY>" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-sonnet-4",
    "system": "You are concise.",
    "messages": [{"role": "user", "content": "Name three Hanseatic cities."}]
  }'

Response:

{ "input_tokens": 18 }

Request

ParameterTypeDescription
messagesarrayThe conversation, same shape as Messages.
systemstring | arraySystem prompt (optional).
toolsarrayTool definitions (optional). Name, description, and schema all count.
modelstringModel ID (optional). Present for SDK compatibility.

Image content blocks contribute a fixed per-image cost (the high-detail rate). Tool schemas count as their serialized JSON.

Response

{ "input_tokens": 18 }

Always input_tokens, always a non-negative integer. No environment or billing fields — this endpoint is free.

Errors

  • 400 — missing anthropic-version header or malformed body.
  • AUTH_1015 — insufficient scope.

Messages for the full endpoint • Context window errors.

On this page