Gemini token counting: count_tokens, usage and multimodal tokens
Answer: Gemini has a token-counting endpoint, count_tokens, which returns the number of tokens in a request. You pass the same arguments as you would for generation, and the service returns the number of tokens in that request (response.total_tokens).
After the call
- The response object has a
usagefield that includes the token count information. - In case you are using context caching, the number of cached tokens is indicated in
cached_content_token_count. - Model info reports the max output window (
output_token_limit).
Multimodal input
- All input is tokenized, including images and other non-text modalities.
- Images count as a fixed size, so they consume a fixed number of tokens regardless of display or file size.
- Video and audio are tokenized at a fixed rate per second; current rates are in the API documentation.
See also
Claims
- id: C1 claim: There is a count_tokens endpoint. source: S1 evidence: "The API provides an endpoint for counting the number of tokens in a request"
- id: C2 claim: Images cost a fixed number of tokens. source: S1 evidence: "they consume a fixed number of tokens"
- id: C3 claim: The SDK documents counting tokens. source: S2 evidence: "count_tokens"
Sources
- [S1] Counting tokens quickstart. google-gemini/cookbook (GitHub). https://github.com/google-gemini/cookbook/blob/main/quickstarts/Counting_Tokens.ipynb . License: Apache-2.0. Accessed 2026-11-16.
- [S2] Google Gen AI Python SDK README. googleapis/python-genai (GitHub). https://github.com/googleapis/python-genai/blob/main/README.md . License: Apache-2.0. Accessed 2026-11-16.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: google-gemini/cookbook (GitHub), Counting tokens quickstart, Apache-2.0 (https://raw.githubusercontent.com/google-gemini/cookbook/main/LICENSE); googleapis/python-genai (GitHub), Google Gen AI Python SDK README, Apache-2.0 (https://raw.githubusercontent.com/googleapis/python-genai/main/LICENSE). Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: google-gemini/cookbook (GitHub), Counting tokens quickstart, Apache-2.0 (https://raw.githubusercontent.com/google-gemini/cookbook/main/LICENSE); googleapis/python-genai (GitHub), Google Gen AI Python SDK README, Apache-2.0 (https://raw.githubusercontent.com/googleapis/python-genai/main/LICENSE).
Cite this
iinventedlight. 2026. "Gemini token counting: count_tokens, usage and multimodal tokens." iinventedlight Library, iil:note:qh3e2a33, version of 2026-11-16. https://iinventedlight.com/library/notes/ao-tokens-gemini-count-tokens/. License: CC-BY-4.0.
@misc{iil_note_qh3e2a33,
author = {{iinventedlight}},
title = {{Gemini token counting: count\_tokens, usage and multimodal tokens}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-16},
url = {https://iinventedlight.com/library/notes/ao-tokens-gemini-count-tokens/},
note = {Permanent ID iil:note:qh3e2a33. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/ao-tokens-gemini-count-tokens.md.