Google Cloud · Cost per useful result
AI Tokenomics on Google Cloud: Measure Gemini Cost per Task
Measure every Gemini call behind one task, separate token and pricing categories, and test a cost change without sacrificing answer quality.
A short question can trigger a long piece of work
Harborlane, the illustrative booking company in this guide, uses an assistant to investigate checkout failures. One short question can trigger retrieval, log queries, retries and several Gemini calls. Measure that whole task to understand its cost.
Build a record of cost, duration and answer quality for one workflow. The token counts below are teaching examples; use the current rates for your model, endpoint, location and serving mode.
01 · Name the unit correctly
A token is a processing unit, not a word
Tokens are pieces of text or other model input. Words, punctuation, code and media contribute differently. Use the model’s supported token-count method for an estimate and returned usage metadata for completed requests; multimodal estimates can differ from final consumption.
Inspect everything sent with the question
In Harborlane’s example request, retrieved documents account for 6,000 of 10,000 input tokens. Inspect retrieval before trying to shorten the engineer’s question.
Read the diagram
This illustrative request contains 10,000 input tokens: 1,000 for instructions and tools, 1,000 for the question and history, 6,000 for retrieved documents, and 2,000 for log results. Retrieved documents account for most of the input in this example; these are invented token counts, not prices or measured savings.
Check instructions, history, document passages, tool schemas and log results. Remove irrelevant or duplicated material while keeping the evidence needed for a correct answer.
02 · Measure actual usage
Record the whole run, not just the last model call
Give each user task a run ID. Record every call, model, token bucket, tool action, retry, duration and outcome under it. The GenerateContent response distinguishes these fields:
| Field | Interpretation | Practical check |
|---|---|---|
promptTokenCount | Prompt input, including cached content when used | Do not add cached input to this total again |
cachedContentTokenCount | The cached portion used by the request | Track cache effectiveness separately |
candidatesTokenCount | Generated candidate tokens | Check answer length and repeated attempts |
thoughtsTokenCount | Generated thinking tokens, where applicable | A short visible answer can still involve more generation |
toolUsePromptTokenCount | Reported tool-execution-result tokens, where applicable | Understand the API’s schema before combining buckets |
totalTokenCount | The API’s combined request total | Useful for usage; not one universal billing rate |
This Python fragment inspects a response already returned by the Google GenAI SDK:
# response is the result of your existing generation call.
usage = response.usage_metadata
if usage is not None:
record = {
"prompt_tokens": getattr(usage, "prompt_token_count", None),
"cached_tokens": getattr(usage, "cached_content_token_count", None),
"candidate_tokens": getattr(usage, "candidates_token_count", None),
"thinking_tokens": getattr(usage, "thoughts_token_count", None),
"total_tokens": getattr(usage, "total_token_count", None),
}
print(record)Adapt field names to your SDK version. A missing field does not mean zero usage. Store counts and approved trace metadata; avoid logging confidential prompts or tool results.
Translate the buckets into a transparent estimate
Record the pricing date, currency, unit and deployment details. Separate fresh input, cached input, generation and applicable service charges.
Example: a 10,000-token prompt includes 6,000 cached tokens; generation produces 600 candidate and 400 thinking tokens. With no separate tool-use or other charges in this simplified example:
Fresh-input estimate = 4,000 / 1,000,000 × fresh-input rate
Cached-input estimate = 6,000 / 1,000,000 × cached-input rate
Generation estimate = (600 + 400) / 1,000,000 × applicable generation rateUse these formulas only where the model prices response and reasoning together. Include applicable grounding, cache storage, media and other charges separately. Reconcile estimates with Cloud Billing.
03 · Change the part you can explain
Consider caching when stable context is genuinely reused
Harborlane repeatedly uses an unchanged operations manual. Eligible context caching may help, but support, minimum sizes and rates depend on the model and API. For implicit caching, keep shared content in a stable prefix and verify reported cache use. For explicit caching, include creation and storage costs.
Preserve document permissions and freshness. A rarely reused cache can cost more than it saves.
One question may contain several model calls
Sum all calls in the run, including calls after tool results and retries. Enforce limits on steps, elapsed time, retries, tool-result size and concurrency in application code. Define when to return a limitation or escalate to a person.
Compare one change against a fixed set of tasks
Fix a test set with known answer requirements: ordinary questions, ambiguous incidents, missing evidence and permission failures. Change one variable—retrieval size, log window, conversation history or model—and compare:
A lower unit rate is useful only if the workflow still passes its quality checks. Repeated attempts, slower responses and human corrections can outweigh it.
| Record | Why it matters |
|---|---|
| Model and configuration | Makes the comparison reproducible |
| All calls, retries and token buckets | Exposes work hidden behind one answer |
| Accepted result and failure reason | Prevents “cheap but wrong” from looking efficient |
| Latency and human correction | Shows whether the workflow actually helps |
| Estimated and reconciled cost | Separates instrumentation from the final bill |
04 · Make the result visible
Put usage beside the behavior it paid for
Group dashboards by feature, run and call. Track completion rate, latency, retries and failures alongside tokens. A cost increase may reflect more useful work, larger context or a retry loop; inspect a sanitized trace before choosing a fix.

Use billing controls alongside application controls
Assign an owner and response plan to budget notifications. Alerts-only budgets notify; they do not stop spending. Eligible spend caps can pause new usage, but enforcement is delayed and in-flight activity or fixed charges may continue. Check scope and the application’s fallback before enabling one.
Continue with Google Cloud FinOps for Beginners for billing ownership, or the ADK/MCP guide for tool execution.
Your first tokenomics review is complete when…
- You can identify a user-visible task and all model calls beneath it.
- You know which input components are large and which are repeated.
- Your estimate uses the right pricing categories without double counting.
- You have a quality baseline and a measured comparison for one change.
- Retries, tool results, time, and agent steps have enforceable limits.
- A named owner understands the alerts and the consequences of any cap.
Quick answers
Should I fill the context window?
Use relevant evidence and test the result. Available capacity does not establish usefulness.
Does caching make requests free?
No. Check cached-input rates and any creation or storage charges.
End with a decision you can defend
Choose Harborlane’s first improvement from the measurements: narrower retrieval, a smaller log result, caching or fewer retries. Record the change and its quality result, then repeat when traffic or model behavior changes.
Official sources for the review
Current model pricing · Token-count estimates · GenerateContent usage schema · Thinking controls
Caching capabilities and costs · Spend-cap behavior and limitations · Google’s token-efficient engineering guide · Monitoring example

Gemini token pricing makes it clear that agents burn most of the bill on tool-result context, not the system prompt. Caching the stable prefix and metering per-tool budgets cuts runaway spend more than model shopping alone. We track token and MCP tool costs the same way in our Lava MCP docs. Do you see teams capping tool calls per session or only daily spend?
I see both as important, but per-session limits are more effective at preventing runaway costs. Daily spend caps act as a safety net, while per-tool token budgets, call limits, and execution thresholds provide better control. The key is moving beyond just counting tool calls to measuring the actual context and token consumption of each MCP interaction.