# Count tokens

> POST /v1/count-tokens returns the input tokens of a chat request without writing a reply.

## Count a request

`POST https://antarya.ai/v1/count-tokens`

Send the body you would send to [`/v1/chat`](https://antarya.ai/docs/api/chat.md). Antarya returns the number of input tokens and does not write a reply. Counting is free and is not billed. It is limited to 100 a minute per key, apart from the [chat limits](https://antarya.ai/docs/api/rate-limits.md). The [guide](https://antarya.ai/docs/guides/counting-tokens.md) explains what the count covers.

### Headers

| Header | Value |
|---|---|
| `Authorization` | `Bearer $ANTARYA_API_KEY` |
| `Content-Type` | `application/json` |

```bash
curl https://antarya.ai/v1/count-tokens \
  -H "Authorization: Bearer $ANTARYA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "messages": [
      {"role": "user", "content": "Draft a reply that declines the meeting."}
    ]
  }'
```

```python
from antarya import Antarya

client = Antarya()

count = client.chat.count_tokens(
    messages=[{"role": "user", "content": "Draft a reply that declines the meeting."}],
)
print(count.input_tokens)
```

```typescript
import Antarya from "antarya";

const client = new Antarya();

const count = await client.chat.countTokens({
  messages: [{ role: "user", content: "Draft a reply that declines the meeting." }],
});
console.log(count.input_tokens);
```

Output:

```
{"input_tokens": 12}
```

## Request body

- `messages` (array, required): The conversation to count, as in a chat request.
- `model` (text, optional): The id or alias of the model. Models can count tokens differently.
- `system` (text, optional): Counted with the messages.
- `tools` (array, optional): Counted with the messages.
- `response_format` (object, optional): Counted with the messages.

## Response

- `input_tokens` (number, required): The tokens the request would use as input.

## Next steps

- [Chat](https://antarya.ai/docs/api/chat.md): Send the request once you know its size.
- [Counting tokens guide](https://antarya.ai/docs/guides/counting-tokens.md): What the count covers.
- [Rate limits](https://antarya.ai/docs/api/rate-limits.md): How many requests a key can make.
