Skip to main content

Messages

POST /anthropic/v1/messages

Anthropic's native Messages API, served by Claude subscriptions. Requests and responses are Anthropic's own format, unconverted, streaming and non-streaming. Point an official Anthropic SDK at https://api.tokhive.ai/anthropic and call it as usual.

Example​

curl https://api.tokhive.ai/anthropic/v1/messages \
-H "x-api-key: $HIVE_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-opus-5-5",
"max_tokens": 1024,
"messages": [{"role": "user", "content": "Reply with exactly OK."}]
}'

The response is Anthropic's message object (IDs shortened):

{
"id": "msg_...",
"type": "message",
"role": "assistant",
"model": "claude-opus-5-5",
"content": [{ "type": "text", "text": "OK" }],
"stop_reason": "end_turn",
"stop_sequence": null,
"usage": {
"input_tokens": 14,
"cache_creation_input_tokens": 0,
"cache_read_input_tokens": 0,
"output_tokens": 4,
"service_tier": "standard"
}
}

Request​

HeaderNotes
x-api-key or Authorization: BearerYour TokHive API key.
anthropic-versionRequired, and must be 2023-06-01. The SDKs send it for you.
anthropic-betaOptional beta features, passed through.
FieldNotes
modelRequired. An ID from /anthropic/v1/models.
max_tokensRequired, a positive integer.
messagesRequired, non-empty.
streamtrue for server-sent events.
speedAlways served as "standard"; see Fast mode is not offered.
system, tools, tool_choice, thinking, metadata, temperature, output_config, context_management and other fieldsPassed through unchanged.

Fast mode is not offered​

TokHive serves every Messages request at the standard speed. A request that asks for fast mode, with "speed": "fast" or any value other than "standard", is quietly changed to "speed": "standard" before it is sent. It runs at the standard speed and is billed at the standard price. There is no error and no extra marker in the response. A request without speed is sent as it is.

This is because, on a Claude subscription, fast mode does not use the plan's quota. It is billed from the first token to the provider's prepaid extra usage, at the API's premium price, which TokHive does not price. If your client has fast mode switched on, for example with /fast in Claude Code, it keeps working, just at the standard speed.

Streaming​

With "stream": true, events arrive as Anthropic sends them: message_start, the content block events, message_delta and message_stop, with ping in between. TokHive holds back the final message_stop event until the result is verified and settled, so it can arrive a moment after the last content. A non-streaming response is likewise returned only after verification.

If a stream fails after output has started, it ends with an error event, and nothing is charged.

Usage and billing​

Claude's input_tokens counts uncached input only. Each kind of token is billed at its own price:

Usage fieldBilled as
input_tokensInput
cache_read_input_tokensCache read
cache_creation.ephemeral_5m_input_tokens5-minute cache write
cache_creation.ephemeral_1h_input_tokens1-hour cache write
output_tokensOutput, including thinking

Conversations​

A conversation keeps to the provider account that served it, which keeps the upstream prompt cache warm. TokHive recognizes the conversation from the x-claude-code-session-id header, or from the session in metadata.user_id. If both are present, they must agree. Session identifiers are replaced with a digest scoped to you before they reach the upstream.

When the original account is unavailable:

  • Plain text, client tool calls and their results, and inline base64 images can continue on another account.
  • Thinking signatures, file references, remote image URLs, containers and unknown content blocks only make sense on the original account, so the call returns 409 session_context_unavailable. With a Retry-After header, the same history can continue later; without one, start a new conversation.

Token counting​

POST /anthropic/v1/messages/count_tokens

Counts the input tokens of a Messages request, as the upstream counts them. Anthropic does not publish the tokenizer of current models, so TokHive does not estimate locally. The body is the same as for Messages, without stream; max_tokens is not required.

curl https://api.tokhive.ai/anthropic/v1/messages/count_tokens \
-H "x-api-key: $HIVE_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-opus-5-5",
"messages": [{"role": "user", "content": "Hello"}]
}'
{ "input_tokens": 8 }
  • Free. Counting is never charged, but it needs a positive balance and counts toward your key's concurrency limit.
  • Counting does not influence which account later Messages calls use.
  • When the upstream rejects the request (400, 413 or 422), its error is passed through. Other failures return 502.