Skip to content

API docs · Chat & images

Anthropic Messages API

POST /v1/messages: x-api-key auth, event streams, usage and errors.

POST https://api.aitoken.tools/v1/messages is compatible with the Anthropic Messages API and suits the anthropic SDK and Claude Code. Only models whose capabilities list anthropic in formats can use it.

Auth and headers

  • x-api-key: your platform key (Authorization: Bearer also works).
  • anthropic-version is optional: the platform always calls the upstream with 2023-06-01. anthropic-beta is passed through as is.

Request fields

FieldDescription
modelRequired. A chat model name from this site
max_tokensRequired, positive integer. It is also the output bound for this request's hold
messagesRequired, non-empty array
system, tools, stream, temperature…Other fields are passed through to the upstream

Streaming

With stream: true you get the Anthropic event stream (message_start, content_block_delta, message_delta, message_stop). The platform reads usage from message_start and message_delta to settle; the events themselves are forwarded unchanged (with model set to this site's name).

Token counting

POST https://api.aitoken.tools/v1/messages/count_tokens returns the number of input tokens in a request (input_tokens); Claude Code calls it to track context size. It is free but counts toward RPM. For models whose upstream has no token counting it returns an estimate.

Error format

Errors use the Anthropic shape { "type": "error", "error": { "type", "message" } }. Statuses mean the same as in the OpenAI-compatible API, with error.type set to authentication_error, billing_error, permission_error, not_found_error, invalid_request_error, rate_limit_error or overloaded_error. A missing max_tokens returns 400 invalid_request_error. Invalid-key and RPM errors use the platform's general shape, as described for the OpenAI-compatible API.

curl https://api.aitoken.tools/v1/messages \
  -H "x-api-key: $AITOKEN_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-sonnet-4-5",
    "max_tokens": 1024,
    "messages": [{ "role": "user", "content": "Hello" }]
  }'