Skip to content

Conversation

@mikehostetler
Copy link
Contributor

Closes #198

Summary

Adds reasoning_cost as a separate field in the cost breakdown, allowing users to see how much they're spending on reasoning tokens.

Changes

  • lib/req_llm/billing.ex: Add reasoning_cost calculation via token_reasoning_item?/1 filter and include it in the returned cost map
  • lib/req_llm/usage/cost.ex: Expose reasoning_cost in breakdown and merge it into usage
  • lib/req_llm/step/usage.ex: Include reasoning_cost in telemetry events
  • test/req_llm/billing_test.exs: Add tests for reasoning cost calculation

How It Works

  • Models with token.reasoning pricing components (xAI grok-3-mini, Azure, Google Gemini 2.5, OpenRouter models) now have their reasoning token costs tracked separately
  • reasoning_cost is included in output_cost (for backwards compatibility) but also exposed independently
  • For models without separate reasoning pricing, reasoning_cost is 0

Testing

mix test  # 2035 tests, 0 failures
mix quality  # passes

- Add reasoning_cost field to billing cost breakdown
- Expose reasoning_cost in Usage.Cost module
- Include reasoning_cost in telemetry events
- Add tests for reasoning token cost calculation

Models with token.reasoning pricing (xAI, Azure, Google, etc.) now
have their reasoning token costs tracked separately from output_cost.
For models without separate reasoning pricing, reasoning_cost is 0.

Amp-Thread-ID: https://ampcode.com/threads/T-019c117b-7aa8-72ba-9556-23dc1118034f
Co-authored-by: Amp <[email protected]>
@mikehostetler mikehostetler merged commit 5ba3d0b into main Jan 31, 2026
6 checks passed
@mikehostetler mikehostetler deleted the feat/198-reasoning-token-cost branch January 31, 2026 01:31
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.

Add support for reasoning token cost calculation

2 participants