Files
litellm/tests
Cesar Garcia bdd05475bc fix: correct cost calculation when reasoning_tokens present without text_tokens (#18607)
Fixes #18599

When OpenAI models (gpt-5-nano, o1-*, o3-*) and other providers return
reasoning_tokens in completion_tokens_details but don't provide text_tokens,
LiteLLM was incorrectly calculating costs using only reasoning_tokens,
ignoring the remaining completion tokens.

Changes:
- Modified generic_cost_per_token() in llm_cost_calc/utils.py to calculate
  text_tokens as: completion_tokens - reasoning_tokens - audio_tokens - image_tokens
  when text_tokens is not explicitly provided
- Added comprehensive test case test_reasoning_tokens_without_text_tokens_gpt5_nano()
  to verify all completion_tokens are billed correctly

Example:
- completion_tokens: 977
- reasoning_tokens: 768
- Before: only 768 tokens billed (21% less)
- After: all 977 tokens billed correctly

Affected models:
- OpenAI: gpt-5-nano, o1-*, o3-*
- Perplexity: sonar-reasoning*
- Any model returning reasoning_tokens without text_tokens
2026-01-04 00:09:00 +05:30
..
2025-10-04 10:57:02 -07:00
2025-10-31 20:32:03 -07:00
2026-01-02 17:38:52 +09:00
2025-11-15 10:34:24 -08:00

In total litellm runs 1000+ tests

[02/20/2025] Update:

To make it easier to contribute and map what behavior is tested,

we've started mapping the litellm directory in tests/test_litellm

This folder can only run mock tests.