Skip to content

fix(cost): count V4 reasoning tokens in usage output#762

Merged
Hmbown merged 1 commit into
mainfrom
codex/v0.8.14-cost-only
May 6, 2026
Merged

fix(cost): count V4 reasoning tokens in usage output#762
Hmbown merged 1 commit into
mainfrom
codex/v0.8.14-cost-only

Conversation

@Hmbown

@Hmbown Hmbown commented May 6, 2026

Copy link
Copy Markdown
Owner

Closes #754

Summary

  • bump workspace and npm wrapper versions to 0.8.14 for the hotfix release
  • count DeepSeek V4 completion_tokens_details.reasoning_tokens as output tokens when the API reports zero completion tokens
  • add a regression test proving thinking-token-only usage produces a non-zero V4 Pro cost

Test plan

  • cargo fmt --all -- --check
  • cargo test -p deepseek-tui parse_usage_counts_reasoning_tokens_when_completion_tokens_are_zero --locked
  • cargo build --workspace --all-features --locked
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings
  • cargo test --workspace --all-features --locked

Copilot AI review requested due to automatic review settings May 6, 2026 00:41

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request bumps the version of the workspace and all internal crates from 0.8.13 to 0.8.14. It also updates the usage parsing logic in the TUI client to correctly account for reasoning tokens when completion tokens are reported as zero, ensuring accurate cost calculations. A review comment suggests simplifying the token normalization logic using .max() to improve robustness and avoid the use of unstable language features.

Comment thread crates/tui/src/client.rs
Comment on lines +820 to +824
if output_tokens == 0
&& let Some(reasoning_tokens) = reasoning_tokens_raw
{
output_tokens = reasoning_tokens;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The logic to normalize output_tokens can be simplified and made more robust by using .max(). This ensures that output_tokens is at least the number of reasoning tokens, even if completion_tokens is non-zero but incorrectly reported as less than the reasoning count by the API. Additionally, this avoids the use of the unstable let_chains feature, which may cause compilation issues on stable Rust toolchains.

    output_tokens = output_tokens.max(reasoning_tokens_raw.unwrap_or(0));

@Hmbown Hmbown merged commit ab59ef8 into main May 6, 2026
11 of 12 checks passed
@Hmbown Hmbown deleted the codex/v0.8.14-cost-only branch May 6, 2026 00:57
@Hmbown Hmbown review requested due to automatic review settings May 6, 2026 01:04
MMMarcinho pushed a commit to MMMarcinho/DeepSeek-TUI that referenced this pull request May 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(cost): session cost shows $0.00 or nothing — possibly usage-parsing gap with V4 reasoning modes

1 participant