Repository navigation
Description
Summary
When using deepseek/deepseek-v4-flash (or deepseek/deepseek-v4-pro) via the official DeepSeek API, the DeepSeek V4 API returns usage.cost.total: 0 in completion responses. OpenClaw treats this 0 as a valid cost value and skips the fallback estimate-usage-cost logic, so the Control UI "Spend" section shows ¥0.00 for all V4 model usage.
Steps to Reproduce
- Configure
deepseek/deepseek-v4-flashas the default model - Use the model normally (sending and receiving messages)
- Check Control UI → Spend panel
- Observe that DeepSeek shows ¥0.00 spend despite having actual token usage
Or inspect the transcript:
// In the session transcript, each assistant message has:
"usage": { "input": 95029, ... },
"cost": { "input": 0, "output": 0, "cacheRead": 0, "cacheWrite": 0, "total": 0 }Expected Behavior
DeepSeek V4 spend should be estimated from token counts and known pricing, since the API does not return cost directly. For example:
deepseek-v4-flash: input ¥0.14/10K tokens, output ¥0.28/10K tokensdeepseek-v4-pro: input ¥1.74/10K tokens, output ¥3.48/10K tokens
Actual Behavior
Spend shows ¥0.00 in Control UI for all DeepSeek V4 usage.
Root Cause
The extractCostBreakdown() function in src/infra/session-cost-usage.ts returns { total: 0, ... } from the API response. Downstream in scanTranscriptFile(), the cost aggregation logic checks:
// Line ~738-748
if (tieredPricing) { estimate }
else if (!isModelPricingKnown(cost) && (costTotal === 0 || !costTotal)) { mark missing }
else if (costTotal === undefined) { estimate }Since isModelPricingKnown(cost) returns true (pricing IS configured/known), and costTotal === 0 (not undefined), both estimate paths are skipped. The 0 is accepted as fact.
Possible Fix
In extractCostBreakdown() or the downstream aggregation paths, treat total: 0 as an unknown/not-provided value rather than a valid zero-cost entry when token counts are non-zero.
Environment
- OpenClaw version: 2026.6.10 (also applies to current main)
- Provider:
deepseek(official API at api.deepseek.com) - Model:
deepseek/deepseek-v4-flash - Plugin:
@openclaw/deepseek-provider(v2026.6.10)
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity
Yachiyo1680 commentedon Jun 26, 2026
Additional Context
This issue did not exist before updating from OpenClaw 2026.6.1 to 2026.6.10.
The
deepseek/deepseek-v4-flashmodel was in use before the update and Control UI Spend displayed correctly. After updating to 2026.6.10 (which externalized the DeepSeek provider into the@openclaw/deepseek-providernpm plugin), the Cost Spend in Control UI started showing ¥0.00 for all DeepSeek V4 model usage.The same API key, the same model, and the same pricing — only the OpenClaw version changed.
clawsweeper commentedon Jun 26, 2026
Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed June 26, 2026, 11:11 AM ET / 15:11 UTC.
Summary
Keep open: current
mainand latest release still preserve a recordedcost.total: 0for nonzero usage when the model has known flat pricing, and the DeepSeek V4 catalog entries do have positive pricing. I did not find a merged fix or canonical duplicate that already owns this exact zero-cost-with-known-pricing path.Reproducibility: yes. for a source-level reproduction: a transcript entry with nonzero usage, DeepSeek provider/model, and
cost.total: 0is parsed as a real zero and skips flat-pricing estimation. I did not run a live DeepSeek API call in this read-only review.Next step
Safe focused repair candidate: the scanner branch, pricing source, UI/gateway consumer, and regression test location are clear, with live DeepSeek proof useful but not required to start a narrow fixture-backed fix.
Review details
Best possible solution:
Ensure nonzero token usage with known positive pricing is estimated instead of preserved as a fabricated zero, while preserving true unknown-pricing and genuinely zero-token behavior.
Do we have a high-confidence way to reproduce the issue?
Yes for a source-level reproduction: a transcript entry with nonzero usage, DeepSeek provider/model, and
cost.total: 0is parsed as a real zero and skips flat-pricing estimation. I did not run a live DeepSeek API call in this read-only review.Is this the best way to solve the issue?
Unclear as a final fix location: the summary bug is clear, but a repair should first check whether externalized DeepSeek runtime model resolution is dropping
model.cost. The maintained end state should avoid DeepSeek-specific special casing unless the provider boundary proves it is needed.AGENTS.md: found and applied where relevant.
Remaining risk / open question:
model.costbefore aggregation; an aggregation-only fix may leave transcript-level cost metadata wrong even if Control UI spend recovers.Codex review notes: model internal, reasoning high; reviewed against 1cd6f81a46ae.
Label changes
Label changes:
P2: Incorrect DeepSeek V4 spend accounting is a user-visible regression with a limited provider and usage-summary blast radius.impact:data-loss: Derived session spend data is silently corrupted to zero despite nonzero token usage and known pricing.impact:session-state: The affected path reads persisted session transcript usage/cost entries that feed Control UI spend summaries.issue-rating: 🦞 diamond lobster: Current issue advisory state selects this label.clawsweeper:source-repro: Current issue advisory state selects this label.clawsweeper:queueable-fix: Current issue advisory state selects this label.clawsweeper:fix-shape-clear: Current issue advisory state selects this label.Label justifications:
P2: Incorrect DeepSeek V4 spend accounting is a user-visible regression with a limited provider and usage-summary blast radius.impact:data-loss: Derived session spend data is silently corrupted to zero despite nonzero token usage and known pricing.impact:session-state: The affected path reads persisted session transcript usage/cost entries that feed Control UI spend summaries.Evidence reviewed
Acceptance criteria:
What I checked:
extractCostBreakdown()acceptscost.totalwhen it is finite and non-negative, so0becomes a parsedcostTotalandcostBreakdownfor downstream aggregation. (src/infra/session-cost-usage.ts:841, 1cd6f81a46ae)scanTranscriptFile()recomputes only tiered pricing, marks zero as missing only when pricing is unknown, and estimates flat pricing only whencostTotalis undefined; a known-priced DeepSeek row withcostTotal === 0falls through unchanged. (src/infra/session-cost-usage.ts:1147, 1cd6f81a46ae)deepseek-v4-flashanddeepseek-v4-propositive input/output/cache-read pricing, so these models count as known-priced underisModelPricingKnown(). (extensions/deepseek/openclaw.plugin.json:30, 1cd6f81a46ae)usage.costhandler loadsloadCostUsageSummaryCached(), and the Control UI usage controller requestsusage.costfor the spend panel data. (src/gateway/server-methods/usage.ts:925, 1cd6f81a46ae)src/infra/session-cost-usage.test.ts:200, 1cd6f81a46ae)v2026.6.10contains the same scanTranscriptFile zero-cost branch and the same DeepSeek V4 manifest pricing, so the latest release does not already fix this issue. (src/infra/session-cost-usage.ts:1147, aa69b12d0086)Likely related people:
src/infra/session-cost-usage.tsincludes session log retention, shared session cost totals, and empty timeseries scan fixes. (role: recent area contributor; confidence: high; commits: 00f8b10567ff, eb03d0ee2ba1, a8bc1716ddc6; files:src/infra/session-cost-usage.ts)src/infra/session-cost-usage.ts,src/infra/session-cost-usage.test.ts)extensions/deepseek/openclaw.plugin.json)extensions/deepseek/openclaw.plugin.json,src/agents/openai-transport-stream.ts)How this review workflow works
@clawsweeper re-reviewcomments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.@clawsweeper re-reviewor@clawsweeper re-runon an open PR or issue to request a fresh review only.@clawsweeper reviewto request a fresh review only.@clawsweeper autofix,@clawsweeper automerge,@clawsweeper fix ci, or@clawsweeper address review.@clawsweeper explainto ask for more context, or@clawsweeper stopto stop active automation.vincentkoc commentedon Jul 3, 2026
Fixed on
main:Known-priced transcript turns with tokens no longer remain at a fabricated zero cost. Provider-authoritative zero billing is preserved when nonzero component costs are recorded, and session-log pricing now falls back to top-level transcript provider/model metadata.
Proof: post-land focused tests passed 119/119; Testbox
check:changedpassed for thecoreandcoreTestslanes; fresh autoreview was clean.