OpenClaw Bug: Gemini Token Usage Shows 0 (How to Verify, Why It Matters, Temporary Workarounds)
OpenClaw News 编辑部
A community report suggests that OpenClaw’s Google provider adapter may fail to map Gemini’s usageMetadata into OpenClaw’s normalized usage fields. The result is confusing but very concrete:
- Your session
.jsonllogs showusage.input = 0andusage.output = 0 - Even though you’re clearly sending prompts and receiving responses
This is not about “display cosmetics”. Token usage is often wired into cost tracking, alerts, and sometimes rate limiting / budgeting logic.
- Source issue: openclaw/openclaw#51743
TL;DR
If you use google/gemini-2.5-flash or google/gemini-2.5-pro via OpenClaw and see 0 tokens recorded:
- Confirm the symptom in your session
.jsonl. - Verify the Gemini raw response includes
usageMetadata. - Treat cost dashboards / budgets as incorrect for Google calls until fixed.
- Use a temporary workaround (switch provider/model, or patch the adapter locally) while tracking the upstream issue.
What the symptom looks like
From the report, assistant messages are recorded like:
{
"type": "message",
"message": {
"role": "assistant",
"provider": "google",
"model": "gemini-2.5-flash",
"usage": {
"input": 0,
"output": 0,
"cacheRead": 0,
"cacheWrite": 0,
"totalTokens": 0,
"cost": { "input": 0, "output": 0, "total": 0 }
}
}
}
Meanwhile, other providers (OpenAI / Anthropic / etc.) show non-zero usage as expected.
Why it matters (practically)
Even if Gemini itself bills correctly, your local observability is now lying.
Common things that become unreliable:
- Cost reports and cost-based alerts
- “budget exceeded” guards (if you have any automation tied to usage)
- Regression detection (e.g., prompts suddenly getting longer)
- Comparisons across providers (Gemini looks “free” when it isn’t)
If you’re operating OpenClaw in any “shared” or “production” environment, incorrect usage logs remove one of your safety rails.
Fast verification checklist
1) Find the session JSONL and confirm it’s not a UI bug
The report points to agent session logs under something like:
~/.openclaw/agents/<agent>/sessions/*.jsonl
Look for the assistant message entry where:
provider: "google"model: "gemini-2.5-*"usage.input == 0 && usage.output == 0
If you see that, it’s not just a dashboard issue—your normalized log entry is missing usage.
2) Confirm Gemini actually returns usageMetadata
In Gemini’s generateContent responses, usage is typically provided as:
usageMetadata.promptTokenCountusageMetadata.candidatesTokenCountusageMetadata.totalTokenCount
If the raw response includes these fields, then the provider adapter should map them.
Fast triage: missing Gemini usage mapping vs broader billing or observability failures
Teams often misclassify this kind of issue because multiple “token usage looks wrong” failures can look similar at first glance.
A more useful split is:
- Only Google / Gemini sessions show zero usage while other providers still log usage correctly
- that points much more strongly to a provider-adapter mapping gap than to a global stats failure.
- The session
.jsonlalready shows zero, and the UI also shows zero- that suggests the problem sits in normalization or log writing, not just dashboard rendering.
- The raw Gemini response does not include
usageMetadataat all- then the investigation should move upstream toward API response shape, model behavior, or response capture, not only OpenClaw's normalized
usagefields.
- then the investigation should move upstream toward API response shape, model behavior, or response capture, not only OpenClaw's normalized
- All providers show broken usage
- in that case, do not keep the blame surface narrowed to the Google adapter. Check broader observability, logging, or post-processing paths.
This distinction matters because it changes whether you should patch a single provider adapter or inspect a much wider accounting pipeline.
Workarounds (until upstream fix lands)
Pick the least risky option for your situation.
Option A: Use a different provider/model for “metered” workloads
If your workflow requires accurate token usage logging (e.g., cost controls), route those sessions temporarily to a provider that currently records usage correctly.
This is the safest operational workaround because it doesn’t involve patching your gateway.
Option B: Patch the Google provider adapter locally (source installs)
The issue includes a suggested mapping:
usageMetadata.promptTokenCount→usage.inputusageMetadata.candidatesTokenCount→usage.outputusageMetadata.totalTokenCount→usage.total(optional)
If you run OpenClaw from source and are comfortable maintaining a small patch until the upstream release, this is a direct fix.
Important: keep the patch minimal and upstream-aligned so you can drop it cleanly after upgrading.
Option C: Add an external cost/usage meter as a temporary guardrail
If you can’t switch models and can’t patch, add a temporary “budget guard” outside of OpenClaw (for example, a daily cap at the provider account level, or separate monitoring at the API gateway / billing dashboard).
What to watch for upstream
Track the issue for a fix and version references:
When a fix lands, re-check a fresh session:
usage.input > 0usage.output > 0totalTokens(or equivalent) increments sensibly
Common rollout questions
When should you stop trusting OpenClaw cost dashboards and treat this as a provider-adapter observability bug instead
If the session transcript clearly shows Gemini requests and replies, but normalized usage.input and usage.output stay at zero while other providers still record usage normally, you should stop treating this as a dashboard glitch. At that point the safer assumption is that OpenClaw's Google adapter is dropping usage metadata during normalization, which means any budget, alerting, or per-session cost view built on top of those fields is now unreliable.
Which teams should block Gemini rollout until usage mapping is fixed or patched locally
Teams with shared budgets, internal chargeback, spend alerts, or automatic cost caps should be the first to pause or patch. If token accounting is part of your approval, governance, or incident response process, zeroed usage is not a cosmetic defect, it removes a core operating signal. Solo experimentation can usually survive with external billing checks, but team or production rollouts should not rely on blind cost telemetry.
Search-intent comparison: Gemini usageMetadata mapping gap vs “the model is just cheap” misreads
A common operator mistake is to explain away zero usage as a pricing anomaly, a free-tier quirk, or a harmless UI bug. That usually slows response.
A better comparison is:
- Usage stays at zero while requests and replies clearly happened
- that points to a telemetry mapping failure, not to "the model consumed no tokens"
- Google billing or quota usage still increases outside OpenClaw
- that further supports the conclusion that the missing signal is in OpenClaw's normalization layer
- Only one dashboard is wrong, but raw provider logs still show counts
- then the issue may sit in presentation or downstream aggregation instead of the adapter itself
- Zero usage appears immediately after a known OpenClaw upgrade or provider change
- that makes a regression in the adapter or response-shape handling more likely than a pricing-side explanation
This distinction matters for search traffic too. People searching for Gemini totalTokens 0 in OpenClaw are usually not asking whether Gemini is free. They are trying to decide whether cost telemetry is trustworthy enough to keep rollout going.
What should the on-call handoff include after mitigation
If you mitigated this issue, leave a short handoff note with these items:
- whether you switched traffic away from Gemini, patched the adapter, or added an external billing guardrail
- one affected model or route that previously showed
usage.input = 0 - whether provider-side billing/usage counters continued to move during the incident
- the upstream issue or version checkpoint the next operator should watch before reverting the workaround
That note saves the next operator from re-running the same cost-trust investigation from scratch.
If troubleshooting traffic lands here, separate Gemini success from usage accounting failure
GA4 now shows this page beside setup and provider troubleshooting entries, so readers may arrive after a Gemini call succeeds but billing, credits, or dashboards still look wrong.
Before changing API keys or model names, split the incident into three checks:
- The Gemini response succeeds but usage is zero: capture the raw
usageMetadata, provider adapter version, and whether input/output token fields were renamed upstream. - The request fails before usage exists: treat it as auth, quota, or model routing, not a usage-mapping bug.
- Only accounting views are wrong: compare logs, credit ledger entries, and dashboard aggregation so the fix lands in mapping or reporting instead of provider calls.
This keeps high-intent provider readers from rotating Gemini credentials when the actual blocker is token usage normalization.
Related reading
- OpenClaw Core Schema Mismatch with the Official Feishu Plugin: Why Messages Fail and What to Check First
- Troubleshooting OpenClaw Agents: What to Check When Tasks Stall or Tools Misbehave
- OpenClaw Bug: NPM Package Misses Control UI Assets and Build Files, Breaking Fresh Upgrades
- OpenClaw ACP One‑Shot Run Looks Empty in sessions_history (Even When .jsonl Transcript Exists)
FAQ for search and cost-trust triage
If OpenClaw shows zero tokens but Google billing is still increasing, which signal should operators trust first?
Trust the provider-side billing, quota, or raw response evidence first, not the local OpenClaw usage fields.
That is the core of this failure mode:
- the calls really happened
- the spend really happened
- but OpenClaw failed to write the normalized
usagevalues
If you keep trusting the local zeroes for budgets or alerts, you will only deepen the misread.
When should this be treated as an adapter-mapping gap instead of a dashboard rendering bug?
If the session .jsonl already records usage.input = 0 and usage.output = 0, the safer assumption is an adapter normalization failure, not a UI-only defect.
The dashboard can misrender numbers, but it cannot rewrite a transcript that is already on disk.
If someone searches for Gemini totalTokens 0, what are the first three checks this page should help them run?
Start with these three:
- whether the session
.jsonlalready shows zero usage - whether the raw Gemini response still includes
usageMetadata - whether other providers continue to log usage correctly
Those checks quickly separate a Google adapter mapping gap from a broader observability failure.
What is the fastest rollback-safe mitigation when finance or ops already depends on token-based alerts?
The safest fast move is usually not to keep debating whether the zeroes are cosmetic. It is to temporarily route cost-sensitive workloads away from Gemini or to add an external provider-side budget guard immediately.
That protects the operating boundary first, while giving the team time to confirm whether the fix should be an adapter patch, a rollout pause, or a provider switch.
What evidence should a team save before they locally patch the Google adapter?
Before applying a local patch, keep a small before-and-after bundle:
- one affected session
.jsonlsample showing zero usage - one raw Gemini response that still includes
usageMetadata - the exact OpenClaw version or commit under test
- one fresh session after patching that shows non-zero usage again
That bundle makes later rollback, upgrade cleanup, and upstream comparison much easier.
Before re-enabling Gemini traffic, run these four recovery checks
When an upstream fix or local patch makes usage non-zero again, do not immediately move all cost-sensitive workloads back to Gemini. Re-enable with a small recovery check first:
- Test a fresh session: trigger a new Gemini request and confirm
usage.input,usage.output, and total token fields increase with the real call. - Compare billing evidence: match a small OpenClaw usage sample against Google quota or billing movement so you know more than the local display recovered.
- Turn cost alerts back on: re-enable budget thresholds, chargeback views, or automatic stop rules before increasing traffic.
- Remove temporary workarounds deliberately: record when provider switching, local patches, or external billing guardrails were removed so stale emergency config does not become permanent.
This is the recovery step high-intent operators need: not only whether the bug exists, but when Gemini traffic is safe to trust again.
Sources
- Issue report and suggested mapping: openclaw/openclaw#51743
