← All notes

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

Multimodal input

See also

Claims

Sources

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

Permanent ID: iil:note:qh3e2a33

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.},
}

Markdown

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.