# Token counts (/api-v2/token-counts)



A small helper that returns the input-token count for a piece of text, so you can size a request before running it. See [billing and budgets](/guides/billing-budgets) for how tokens map to charges.

All requests require a bearer API key. See [authentication](/api-reference/authentication).

## Count tokens [#count-tokens]

`POST /v2/token-counts`

<ParamField body="input" type="string">
  The text to count. Must not be empty.
</ParamField>

```bash
curl https://api.zumik.ai/v2/token-counts \
  -H "Authorization: Bearer $ZUMIK_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "input": "Summarize the diff in three bullets." }'
```

```python
from zumik import Zumik

zk = Zumik()
count = zk.token_counts.create(input="Summarize the diff in three bullets.")
```

```json
{
  "object": "token_count",
  "input_tokens": 10
}
```

<ResponseField name="object" type="string">
  Always `token_count`.
</ResponseField>

<ResponseField name="input_tokens" type="integer">
  The estimated input-token count.
</ResponseField>

## Errors [#errors]

| Status | Code                    | When                        |
| ------ | ----------------------- | --------------------------- |
| 400    | `invalid_request_error` | `input` is empty.           |
| 401    | `invalid_api_key`       | Missing or invalid API key. |

See the full table on [errors](/api-reference/errors).
