Skip to content

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

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)

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