# Counting tokens

> Find out how many input tokens a request uses before you send it.

## What it is for

Tokens are what you are billed for and how much a conversation can hold is measured in. To see how large a request is before you send it, post the same body to `/v1/count-tokens`. It returns `input_tokens` and does not produce a reply. Counting is free and not billed, and is limited to 100 a minute per key. The SDK methods are `client.chat.countTokens` in TypeScript and `client.chat.count_tokens` in Python.

## Count a request

```bash
curl https://antarya.ai/v1/count-tokens \
  -H "Authorization: Bearer $ANTARYA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "system": "Answer in plain English.",
    "messages": [
      {"role": "user", "content": "Summarise this contract'"'"'s termination clause."}
    ]
  }'
```

```python
from antarya import Antarya

client = Antarya()

count = client.chat.count_tokens(
    system="Answer in plain English.",
    messages=[{"role": "user", "content": "Summarise this contract's termination clause."}],
)
print(count.input_tokens)
```

```typescript
import Antarya from "antarya";

const client = new Antarya();

const count = await client.chat.countTokens({
  system: "Answer in plain English.",
  messages: [{ role: "user", content: "Summarise this contract's termination clause." }],
});
console.log(count.input_tokens);
```

Output:

```
{"input_tokens": 23}
```

## What it counts

The count covers everything the request sends: `system`, every message, tool descriptions, a response schema, and files and images in the messages. It does not count the reply, which is only known afterwards in `usage.output_tokens`.

## Parameters

- `messages` (array, required): The conversation to count, as in a chat request.
- `system` (text, optional): Counted with the messages.
- `tools` (array, optional): Counted with the messages.
- `response_format` (object, optional): Counted with the messages.

## Limits

| Limit | Value |
|---|---|
| Counting requests per minute | 100 a minute per key |
| Cost of a count | Free, not billed |

## Next steps

- [Models](https://antarya.ai/docs/models.md): How much a request can hold, and the longest reply.
- [Files and images](https://antarya.ai/docs/guides/files-and-images.md): What an attachment adds to a request.
- [Conversations](https://antarya.ai/docs/guides/conversations.md): Why a long history costs more each turn.
