Gemini Token Counts: Estimate Inputs and Check Actual Usage
A token count before a request estimates its input, while usage after the response records what the API reports. Read both and check pricing terms rather than calculating from word counts alone.

Distinguish the token count before a request from usage after the response
Before a request, use countTokens to count prepared input. You cannot yet know the answer's length. After the response, read usage for input, output, and any additional units reported by the API. Gemini's token-counting documentation distinguishes these two stages.
When calling GenerateContent API inspect usageMetadata For example promptTokenCount, candidatesTokenCount and thoughtsTokenCount when present. But for Interactions API the documentation's example reads interaction.usage Fields and their scope can vary across SDKs and endpoints. Check the version you actually use and do not add a total to its component counts again.
A token is not reliably one Thai word or one character. Models split text and other data for processing; images, audio, video, system instructions, and tool descriptions may also count. The shortcut ‘one word = one token’ cannot calculate a bill.
| Data | When to use it | What it indicates |
|---|---|---|
| countTokens | before calling the model | Input quantity according to counted request format |
| usage after answering | After receiving results | Quantity of inputs, outputs, and items reported by the API. |
| Pricing/Billing | During assessment and balance reconciliation | Actual rates and terms by model, plan, and capability |
A measurement method that separates costs from guesswork
The Google example below first counts with count_tokens then reads interaction.usage after the response.
# This will only work for SDK newer than 2.0.0
from google import genai
client = genai.Client()
prompt = "The quick brown fox jumps over the lazy dog."
# Count tokens before sending
total_tokens = client.models.count_tokens(
model="gemini-3.8-flash",
contents=prompt,
)
print('total_tokens:', total_tokens.total_tokens)
# Get usage from interaction
interaction = client.interactions.create(
model="gemini-3.8-flash",
input=prompt,
)
print(interaction.usage)
The documentation says this example requires an SDK newer than 2.0.0 and uses the Interactions API for the response; GenerateContent API fields may differ. We have not run the code or verified the model named in it. Source: Source documentation · Apache-2.0 / CC BY 4.0
- Use the same model for counting and the real request; tokenization and pricing can differ.
- Include the full input: system instructions, repeated history, documents, and tool settings—not just the latest message.
- Use countTokens for your SDK/API to check request size and context limits before sending.
- After the response, read the actual input, output, and additional usage fields returned; do not assume every version returns the same fields.
- Compare each category against Gemini Developer API pricing for the model and tier in use, including extra tool charges where relevant.
In a multi-turn conversation, input usage depends on whether the next request resends history or manages state another way. Counting only the newest question can substantially understate usage, especially with long documents or repeated system instructions.
Hypothetical example: 8,000 input tokens and total cost
Consider a hypothetical request with 8,000 Token and billable output of 2,000 Token Assume an input rate of 0.50 Dollars per 1 Million Tokens and output $2 per million tokens The quantities and rates are only assumptions for this calculation, not Google's prices at the time of writing
- Input = 8,000 ÷ 1,000,000 × 0.50 = 0.004 Dollars
- Output = 2,000 ÷ 1,000,000 × 2 = 0.004 Dollars
- Total for the two components = $0.008 per request under these assumptions.
If all 500 requests use exactly the same amounts, the two categories total 500 × 0.008 = 4 dollars before other charges, credits, taxes, and hosting. Use this as a rough budget, then check the actual bill.
Why actual figures may differ from the examples
Actual usage can change with added history or files, longer answers, thinking or tool tokens reported by some models, and rates for different data types, caching, or other features. Google also says system instructions and tool descriptions affect the count.
Context limits are not a budget: A request that fits the context window is not necessarily free; a low token count does not rule out other charges. To control spending, check usage and the real account's Billing settings.
Count each usage category before applying prices
Use countTokens to size input before sending, then use actual response usage to refine your estimate. Compare each category with current pricing and terms for your model; this is more useful than counting words or applying a single per-million-token rate.
Sources
- Google AI for Developers: Understand and count tokens
- Google AI for Developers: models.countTokens reference
- Google AI for Developers: Gemini Developer API pricing
- Google: GenerateContent UsageMetadata
- Google: source document
Google documentation reviewed October 18, 2026 (Thailand time). No actual Gemini API calls were made. Example token counts and dollar rates illustrate formulas; they are not Google prices, test results, or bills.