Description
Session cost in the footer shows $0.00 or nothing. The user reports this happens specifically with reasoning_effort = "auto" but may be broader — cost may not calculate at all in some configurations. Needs investigation and fix for v0.8.14.
Investigation so far
The cost pipeline is:
parse_usage() in client.rs:854 extracts input_tokens, output_tokens, prompt_cache_hit_tokens, prompt_cache_miss_tokens, reasoning_tokens from API response JSON
- Turn loop in
turn_loop.rs:728 calls turn.add_usage(&usage) after each API call
EngineEvent::TurnComplete { usage, .. } is emitted with the accumulated usage
- UI handler at
ui.rs:945 calls calculate_turn_cost_from_usage(&app.model, &usage)
pricing_for_model() in pricing.rs matches the model name to pricing tiers
What I verified works:
parse_usage handles both input_tokens/prompt_tokens and output_tokens/completion_tokens
stream_options.include_usage: true is set (verified at chat.rs:107)
- Usage-only SSE chunks are correctly parsed (verified at
chat.rs:1070)
pricing_for_model matches dated snapshots like deepseek-v4-pro-20260423 (contains "v4-pro")
auto_reasoning.rs does NOT touch model name or cost — it only selects reasoning effort tier
- Tests pass for
parse_usage with both legacy and V4 cached_tokens format
Potential causes to investigate:
-
V4 with reasoning may not include thought tokens in completion_tokens. If reasoning tokens are billed but reported in a separate field that parse_usage does not capture into output_tokens, the cost will be undercounted. parse_usage reads reasoning_tokens from completion_tokens_details.reasoning_tokens but does NOT add them to output_tokens. If the API reports reasoning tokens exclusively in completion_tokens_details.reasoning_tokens and NOT in completion_tokens, output_tokens will be 0 → cost = $0.00.
-
pricing_for_model returns None. If app.model does not contain "deepseek" (e.g. proxy setups, custom endpoints), cost silently becomes None and accrue_session_cost is never called.
-
Usage from resumed sessions. Resumed sessions may have session_cost but the per-turn cost accrual might not trigger on the first resumed turn.
-
Footer rendering. Cost might be calculated correctly but the footer rendering path (footer.rs) might not display $0.00 values, making it look like nothing.
Recommended fix approach
- Add
reasoning_tokens to output_tokens in parse_usage if the field exists and output_tokens is 0 or does not include them
- Add a log/trace when cost calculation produces None (model not matched)
- Add a regression test: API response with only
completion_tokens_details.reasoning_tokens and zero completion_tokens should produce non-zero cost
Environment
- Version: v0.8.13
- Model:
deepseek-v4-pro with reasoning_effort = "auto"
Description
Session cost in the footer shows $0.00 or nothing. The user reports this happens specifically with
reasoning_effort = "auto"but may be broader — cost may not calculate at all in some configurations. Needs investigation and fix for v0.8.14.Investigation so far
The cost pipeline is:
parse_usage()inclient.rs:854extractsinput_tokens,output_tokens,prompt_cache_hit_tokens,prompt_cache_miss_tokens,reasoning_tokensfrom API response JSONturn_loop.rs:728callsturn.add_usage(&usage)after each API callEngineEvent::TurnComplete { usage, .. }is emitted with the accumulated usageui.rs:945callscalculate_turn_cost_from_usage(&app.model, &usage)pricing_for_model()inpricing.rsmatches the model name to pricing tiersWhat I verified works:
parse_usagehandles bothinput_tokens/prompt_tokensandoutput_tokens/completion_tokensstream_options.include_usage: trueis set (verified atchat.rs:107)chat.rs:1070)pricing_for_modelmatches dated snapshots likedeepseek-v4-pro-20260423(contains "v4-pro")auto_reasoning.rsdoes NOT touch model name or cost — it only selects reasoning effort tierparse_usagewith both legacy and V4cached_tokensformatPotential causes to investigate:
V4 with reasoning may not include thought tokens in
completion_tokens. If reasoning tokens are billed but reported in a separate field thatparse_usagedoes not capture intooutput_tokens, the cost will be undercounted.parse_usagereadsreasoning_tokensfromcompletion_tokens_details.reasoning_tokensbut does NOT add them tooutput_tokens. If the API reports reasoning tokens exclusively incompletion_tokens_details.reasoning_tokensand NOT incompletion_tokens, output_tokens will be 0 → cost = $0.00.pricing_for_modelreturns None. Ifapp.modeldoes not contain "deepseek" (e.g. proxy setups, custom endpoints), cost silently becomes None andaccrue_session_costis never called.Usage from resumed sessions. Resumed sessions may have
session_costbut the per-turn cost accrual might not trigger on the first resumed turn.Footer rendering. Cost might be calculated correctly but the footer rendering path (
footer.rs) might not display $0.00 values, making it look like nothing.Recommended fix approach
reasoning_tokenstooutput_tokensinparse_usageif the field exists andoutput_tokensis 0 or does not include themcompletion_tokens_details.reasoning_tokensand zerocompletion_tokensshould produce non-zero costEnvironment
deepseek-v4-prowithreasoning_effort = "auto"