Skip to content

[Bug]: DeepSeek V4 API returns usage.cost total as 0, causing Control UI Spend to show zero #97047

Closed

Description

@Yachiyo1680

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

  1. Configure deepseek/deepseek-v4-flash as the default model
  2. Use the model normally (sending and receiving messages)
  3. Check Control UI → Spend panel
  4. 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 tokens
  • deepseek-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)

Activity

  1. Yachiyo1680 commented on Jun 26, 2026

    @Yachiyo1680
    Author

    Additional Context

    This issue did not exist before updating from OpenClaw 2026.6.1 to 2026.6.10.

    The deepseek/deepseek-v4-flash model 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-provider npm 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.

  2. clawsweeper commented on Jun 26, 2026

    @clawsweeper
    Contributor

    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 main and latest release still preserve a recorded cost.total: 0 for 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: 0 is 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: 0 is 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:

    • A repair should verify whether the zero transcript cost comes from the externalized DeepSeek runtime model losing model.cost before 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:

    • add P2: Incorrect DeepSeek V4 spend accounting is a user-visible regression with a limited provider and usage-summary blast radius.
    • add impact:data-loss: Derived session spend data is silently corrupted to zero despite nonzero token usage and known pricing.
    • add impact:session-state: The affected path reads persisted session transcript usage/cost entries that feed Control UI spend summaries.
    • add issue-rating: 🦞 diamond lobster: Current issue advisory state selects this label.
    • add clawsweeper:source-repro: Current issue advisory state selects this label.
    • add clawsweeper:queueable-fix: Current issue advisory state selects this label.
    • add 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:

    • node scripts/run-vitest.mjs src/infra/session-cost-usage.test.ts
    • node scripts/run-vitest.mjs extensions/deepseek/index.test.ts

    What I checked:

    • Current source accepts recorded zero totals: extractCostBreakdown() accepts cost.total when it is finite and non-negative, so 0 becomes a parsed costTotal and costBreakdown for downstream aggregation. (src/infra/session-cost-usage.ts:841, 1cd6f81a46ae)
    • Known-priced flat models skip estimation: scanTranscriptFile() recomputes only tiered pricing, marks zero as missing only when pricing is unknown, and estimates flat pricing only when costTotal is undefined; a known-priced DeepSeek row with costTotal === 0 falls through unchanged. (src/infra/session-cost-usage.ts:1147, 1cd6f81a46ae)
    • DeepSeek V4 pricing is configured: The bundled DeepSeek plugin manifest gives deepseek-v4-flash and deepseek-v4-pro positive input/output/cache-read pricing, so these models count as known-priced under isModelPricingKnown(). (extensions/deepseek/openclaw.plugin.json:30, 1cd6f81a46ae)
    • Control UI spend reads this summary path: The gateway usage.cost handler loads loadCostUsageSummaryCached(), and the Control UI usage controller requests usage.cost for the spend panel data. (src/gateway/server-methods/usage.ts:925, 1cd6f81a46ae)
    • Adjacent tests cover unknown pricing, not this known-pricing case: Existing regression tests cover token-burning entries with all-zero or unknown pricing being counted as missing cost, but there is no analogous fixture for known positive pricing plus a recorded zero total. (src/infra/session-cost-usage.test.ts:200, 1cd6f81a46ae)
    • Latest release has the same behavior: v2026.6.10 contains 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:

    • vincentkoc: Recent GitHub history for src/infra/session-cost-usage.ts includes 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)
    • zeroaltitude: Authored a focused session usage-cost cache performance change with validation in the same cost summary/test surface. (role: adjacent owner; confidence: medium; commits: e6e27c354ca9; files: src/infra/session-cost-usage.ts, src/infra/session-cost-usage.test.ts)
    • shakkernerd: GitHub history shows DeepSeek manifest model catalog and static provider catalog work relevant to the V4 pricing metadata used here. (role: DeepSeek catalog contributor; confidence: medium; commits: 4a195b37d510, 3254e961e943, 00d2c3488932; files: extensions/deepseek/openclaw.plugin.json)
    • steipete: Carried major provider/plugin runtime refactors and earlier DeepSeek plugin refactor history around the manifest-owned provider boundary. (role: provider/plugin refactor contributor; confidence: medium; commits: bb46b79d3c14, b74f35ee6f97, 9f2330363e2a; files: extensions/deepseek/openclaw.plugin.json, src/agents/openai-transport-stream.ts)
    How this review workflow works
    • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
    • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
    • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
    • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
    • Maintainers can also comment @clawsweeper review to request a fresh review only.
    • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
    • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
    • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.
  3. added
    P2Normal backlog priority with limited blast radius.
    impact:data-lossCan lose, corrupt, or silently drop user/session/config data.
    impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.
    no-staleExclude from stale automation
    issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.
    clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.
    clawsweeper:queueable-fixClawSweeper marked this issue as an existing queue_fix_pr work candidate.
    clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.
    on Jun 26, 2026
  4. self-assigned this
    on Jul 3, 2026
  5. vincentkoc commented on Jul 3, 2026

    @vincentkoc
    Member

    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:changed passed for the core and coreTests lanes; fresh autoreview was clean.

  6. locked as resolved and limited conversation to collaborators on Jul 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P2Normal backlog priority with limited blast radius.clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.clawsweeper:queueable-fixClawSweeper marked this issue as an existing queue_fix_pr work candidate.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.impact:data-lossCan lose, corrupt, or silently drop user/session/config data.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.no-staleExclude from stale automation

Type

No type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions