Skip to main content
POST
cURL
Takes the same headers and the same body as /messages (model, messages, and optionally system and tools) and returns the input token count without generating anything: {"input_tokens": 9}. It isn’t billed, but it counts toward your request rate limit. Errors use Anthropic’s shape, with the request ID in the body and in a request-id header; see the Inference API overview.

Authorizations

x-api-key
string
header
required

Your inference API key. Send this or Authorization; if you send both, they must carry the same key.

Headers

anthropic-version
string
required

One value, for example 2023-06-01. Missing returns 400.

Example:

"2023-06-01"

Body

application/json
model
string
required

A chat model ID from GET /models. A model that doesn't serve Messages returns 404.

messages
object[]
required

The conversation, alternating user and assistant turns. Content is a string or an array of blocks; replay returned thinking and tool_use blocks, and answer each tool use with a tool_result block carrying its ID.

system

The system prompt.

tools
object[]

Tool definitions. Support varies by model.

Response

The input token count.

input_tokens
integer

The input token count.