> ## Documentation Index
> Fetch the complete documentation index at: https://docs.stateset.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Anthropic-compatible token counting (POST /v1/messages/count_tokens).

> Claude Code and the Anthropic SDKs call this before sending requests. **Required scope:** write

Claude Code and the Anthropic SDKs call this before sending requests.

**Required scope:** `write`

### Request body

JSON body of type `any`.

### Response

`CountTokensResponse`

<ResponseField name="input_tokens" type="integer (int32)" required />

### Status codes

| Code  | Meaning                                            |
| ----- | -------------------------------------------------- |
| `200` | Estimated input token count                        |
| `401` | Unauthorized — missing or invalid credentials      |
| `403` | Forbidden — the key/token lacks the required scope |
| `429` | Rate limited — see Retry-After / X-RateLimit-Reset |

<RequestExample>
  ```bash cURL theme={null}
  curl --request POST \
    --url 'https://api.nsr.stateset.com/v1/messages/count_tokens' \
    --header 'X-API-Key: YOUR_API_KEY' \
    --header 'Content-Type: application/json' \
    --data '{}'
  ```
</RequestExample>

<ResponseExample>
  ```json 200 theme={null}
  {
    "input_tokens": 1
  }
  ```
</ResponseExample>
