nanocoder icon indicating copy to clipboard operation
nanocoder copied to clipboard

[Bug] /usage shows "—" for Cumulative Session once any call used an unpriced model

Open harpreetkbadhan opened this issue 1 week ago • 1 comments

Description

/usage shows "—" for Cumulative Session as soon as one call in the session used a model that has no models.dev price, which hides the cost of every priced call.

For an unpriced model, usage.tsx uses {input: NaN, output: NaN} as the pricing. calculateUsageCost then returns NaN, not undefined, so the ?? 0 on line 239 does not catch it, cumulativeSession becomes NaN, and formatCost renders "—". The per-provider subtotal of the provider that served the unpriced model turns into "—" the same way, even when that provider also had priced calls.

Environment

  • OS: macOS
  • Node version: v22.23.4
  • Nanocoder version: 1.32.0 (main at 2f2d5f10)
  • Provider / model: a hosted model with a models.dev price plus any model without one (a fine-tune, a gateway alias)

Steps to Reproduce

Call usageCommand.handler with the active model gpt-4o on openai and:

  1. apiCallHistory: [{provider: 'openai', model: 'gpt-4o', inputTokens: 100_000, outputTokens: 20_000}] gives cumulativeSession: 0.45.
  2. Add {provider: 'my-proxy', model: 'my-finetune-xyz', inputTokens: 1000, outputTokens: 100} (no models.dev entry).

Expected Behavior

Cumulative Session stays $0.45, and only my-proxy shows "—" in the per-provider breakdown.

Actual Behavior

cumulativeSession: NaN ("—") and perProvider: {openai: 0.45, 'my-proxy': NaN}.

The existing spec for the multi-provider breakdown checks only that the unpriced provider shows "—", not the Cumulative Session line, so it passes.

Suggested fix

Only add finite call costs to the totals (Number.isFinite(callCost)), and keep a provider whose calls are all unpriced as "—" in the breakdown. A few lines plus a spec assertion on Cumulative Session.

Happy to send a PR if you'd like to assign it to me.

Additional Context

  • [x] I have searched existing issues to ensure this is not a duplicate (#2271 is the pricing-override feature; it doesn't change this)
  • [x] I can reproduce this issue consistently
  • [x] This issue occurs with the latest version of nanocoder

harpreetkbadhan avatar Nov 24 '26 13:11 harpreetkbadhan

Withdrawn: I missed that the reporter offered to send the PR themselves. Leaving it to them, sorry for the noise.

sniwas avatar Nov 24 '26 15:11 sniwas