---
title: "Count tokens for texts"
method: POST
path: "/v3/collections/token-count"
tags: ["Collections"]
---

# Count tokens for texts

`POST /v3/collections/token-count`

Count the number of tokens in the provided texts using the BGE M3 tokenizer.
This is useful for checking if texts will fit within the embedding model's token limit
(8,192 tokens per text) before sending them for embedding.

## Request body

- CountTokensRequestV3 — Request body for counting tokens against the embedding tokenizer.
  - `texts` string[], required — One or more texts to tokenize.

## Response `200`

The request has succeeded.

- CountTokensResponseV3 — Response for the token count endpoint.
  - `token_counts` CountTokensItemV3[] — Per-text tokenization results in the same order as the request.
    - `index` integer — Zero-based position of this entry in the request `texts` array.
    - `token_count` integer — Number of tokens produced by the tokenizer.
    - `exceeds_limit` boolean — True if `token_count` exceeds the embedding model's per-text limit.
    - `char_count` integer — Character count of the input text.
  - `total_tokens` integer — Sum of `token_count` across all texts.
  - `max_token_limit` integer — Maximum tokens allowed per text by the embedding model.
  - `texts_exceeding_limit` integer — Number of input texts that exceed `max_token_limit`.

## Other responses

- `400` — The server could not understand the request due to invalid syntax.
- `500` — Server error

---

[API](https://skmtc.dev/bem-team/apis/bem-api.md) · [All operations](https://skmtc.dev/bem-team/apis/bem-api/llms.txt) · [OpenAPI document](https://skmtc-service-production.skmtc.workers.dev/v1/apis/bem-team/bem-api/revisions/a6e4624117c6/schema)
