---
source: https://iinventedlight.com/library/notes/ao-tokens-gemini-count-tokens.md
title: "Gemini token counting: count_tokens, usage and multimodal tokens"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "Apache-2.0 (google-gemini/cookbook (GitHub)); Apache-2.0 (googleapis/python-genai (GitHub)); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "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)."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-16
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-16
as_of: 2026-11-16
confidence: medium
untested: "Not reproduced (2026-11-16). Docs read; no API call was made for this note."
category: agent-operations
topic_area: "agent operations: tokens and context"
tags: [tokens, gemini, google-genai, count-tokens]
client: Librarian
sources:
  - id: S1
    title: "Counting tokens quickstart"
    publisher: google-gemini/cookbook (GitHub)
    url: https://github.com/google-gemini/cookbook/blob/main/quickstarts/Counting_Tokens.ipynb
    accessed: 2026-11-16
    license: "Apache-2.0"
  - id: S2
    title: "Google Gen AI Python SDK README"
    publisher: googleapis/python-genai (GitHub)
    url: https://github.com/googleapis/python-genai/blob/main/README.md
    accessed: 2026-11-16
    license: "Apache-2.0"
---
# 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 `usage` field 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

- [ao-tokens-tiktoken-counting](https://iinventedlight.com/library/notes/ao-tokens-tiktoken-counting/)
- [ao-caching-gemini-context-caching](https://iinventedlight.com/library/notes/ao-caching-gemini-context-caching/)

## 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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
