openclaw - ✅(Solved) Fix MiniMax token usage shows 0 in Control UI Usage page (only message count works) [1 pull requests, 1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#75026Fetched 2026-05-01 05:39:00
View on GitHub
Comments
1
Participants
2
Timeline
2
Reactions
2
Author
Timeline (top)
commented ×1cross-referenced ×1

The MiniMax provider shows tokens: 0 in the Control UI Usage page, while only message counts are correctly tracked. DeepSeek (OpenAI format) works fine.

Root Cause

  1. MiniMax API correctly returns token usage:

    • Anthropic format: {"input_tokens": 23, "output_tokens": 10, "cache_read_input_tokens": 0, "cache_creation_input_tokens": 0}
    • OpenAI format: {"prompt_tokens": 23, "completion_tokens": 10, "total_tokens": 33}
  2. normalizeUsage() in usage-DHoo33i9.js correctly handles both formats:

    const input = raw.input ?? raw.inputTokens ?? raw.input_tokens ?? raw.promptTokens ?? raw.prompt_tokens ?? ...
    const output = raw.output ?? raw.outputTokens ?? raw.output_tokens ?? raw.completionTokens ?? raw.completion_tokens ?? ...
  3. But session JSONL files show zero usage for MiniMax runs:

    {"input": 0, "output": 0, "cacheRead": 0, "cacheWrite": 0, "totalTokens": 0}
  4. The bug is in the pipeline: API response usagelastAssistant.usagemergeUsageIntoAccumulatorsession store. The Anthropic-format usage data from MiniMax is not being propagated to attempt.lastAssistant.usage.

Fix Action

Workaround

Switching to MiniMax's OpenAI-compatible endpoint (api.minimaxi.com/v1/chat/completions) instead of the Anthropic-compatible one may work as a temporary fix.

PR fix notes

PR #75136: [codex] fix(minimax): preserve anthropic stream usage

Description (problem / solution / changelog)

Summary

Fixes #75026.

This keeps MiniMax Anthropic-compatible streaming usage from being lost before session persistence:

  • normalizes transport usage with the shared normalizeUsage() helper, so OpenAI-style aliases such as prompt_tokens, completion_tokens, and total_tokens are accepted on the Anthropic-compatible stream path
  • applies usage snapshots from message_start, message_delta, and compatible-provider message_stop events
  • adds MiniMax-shaped SSE regression coverage for alias usage and message_stop usage
  • adds an Unreleased changelog entry

Root cause

The Anthropic stream transport only copied native Anthropic usage keys (input_tokens, output_tokens, cache_read_input_tokens, cache_creation_input_tokens) from message_start and message_delta. MiniMax-compatible streams can expose nonzero usage through OpenAI-style aliases or at message_stop, so the assistant usage snapshot stayed zero and downstream session/Usage UI summaries showed token totals as 0.

Validation

  • pnpm exec oxfmt --check --threads=1 src/agents/anthropic-transport-stream.ts src/agents/anthropic-transport-stream.test.ts CHANGELOG.md
  • pnpm test src/agents/anthropic-transport-stream.test.ts src/agents/usage.test.ts src/agents/pi-embedded-runner/usage-accumulator.test.ts src/infra/session-cost-usage.test.ts
  • pnpm tsgo:core
  • pnpm tsgo:core:test
  • pnpm check:changed
  • git diff --check origin/main..HEAD

I did not run a live MiniMax CN request; the regression is covered with deterministic SSE fixtures at the transport boundary where usage was being dropped.

AI-assisted

  • Built with Codex
  • Focused tests and changed-lane checks run locally
  • Author reviewed the diff before opening this PR

Changed files

  • CHANGELOG.md (modified, +1/-0)
  • src/agents/anthropic-transport-stream.test.ts (modified, +102/-0)
  • src/agents/anthropic-transport-stream.ts (modified, +40/-33)

Code Example

const input = raw.input ?? raw.inputTokens ?? raw.input_tokens ?? raw.promptTokens ?? raw.prompt_tokens ?? ...
   const output = raw.output ?? raw.outputTokens ?? raw.output_tokens ?? raw.completionTokens ?? raw.completion_tokens ?? ...

---

{"input": 0, "output": 0, "cacheRead": 0, "cacheWrite": 0, "totalTokens": 0}
RAW_BUFFERClick to expand / collapse

Summary

The MiniMax provider shows tokens: 0 in the Control UI Usage page, while only message counts are correctly tracked. DeepSeek (OpenAI format) works fine.

Root Cause Analysis

  1. MiniMax API correctly returns token usage:

    • Anthropic format: {"input_tokens": 23, "output_tokens": 10, "cache_read_input_tokens": 0, "cache_creation_input_tokens": 0}
    • OpenAI format: {"prompt_tokens": 23, "completion_tokens": 10, "total_tokens": 33}
  2. normalizeUsage() in usage-DHoo33i9.js correctly handles both formats:

    const input = raw.input ?? raw.inputTokens ?? raw.input_tokens ?? raw.promptTokens ?? raw.prompt_tokens ?? ...
    const output = raw.output ?? raw.outputTokens ?? raw.output_tokens ?? raw.completionTokens ?? raw.completion_tokens ?? ...
  3. But session JSONL files show zero usage for MiniMax runs:

    {"input": 0, "output": 0, "cacheRead": 0, "cacheWrite": 0, "totalTokens": 0}
  4. The bug is in the pipeline: API response usagelastAssistant.usagemergeUsageIntoAccumulatorsession store. The Anthropic-format usage data from MiniMax is not being propagated to attempt.lastAssistant.usage.

Steps to Reproduce

  1. Use MiniMax as the primary model
  2. Make multiple API calls
  3. Check Control UI → Usage page → MiniMax shows tokens=0, messages=N
  4. Compare: DeepSeek shows both tokens and messages correctly

Environment

  • OpenClaw 2026.4.27 (cbc2ba0)
  • MiniMax CN endpoint (api.minimaxi.com/anthropic)
  • macOS + node v22.22.0

Workaround

Switching to MiniMax's OpenAI-compatible endpoint (api.minimaxi.com/v1/chat/completions) instead of the Anthropic-compatible one may work as a temporary fix.

extent analysis

TL;DR

Switching to MiniMax's OpenAI-compatible endpoint may resolve the token tracking issue for MiniMax in the Control UI Usage page.

Guidance

  • Verify that the normalizeUsage() function in usage-DHoo33i9.js is correctly handling the Anthropic format by logging the input and output values.
  • Check the mergeUsageIntoAccumulator function to ensure it is correctly propagating the usage data from API response usage to lastAssistant.usage.
  • Inspect the session JSONL files to confirm that the usage data is being written correctly after making the API calls.
  • Test the workaround by switching to the OpenAI-compatible endpoint and checking if the token usage is correctly tracked.

Example

No code snippet is provided as the issue is more related to the data flow and propagation rather than a specific code block.

Notes

The issue seems to be specific to the MiniMax provider and the Anthropic format, and the workaround may not be a permanent solution. Further investigation into the pipeline and the mergeUsageIntoAccumulator function may be necessary to resolve the issue.

Recommendation

Apply the workaround by switching to the OpenAI-compatible endpoint, as it may provide a temporary fix for the token tracking issue.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - ✅(Solved) Fix MiniMax token usage shows 0 in Control UI Usage page (only message count works) [1 pull requests, 1 comments, 2 participants]