9 views
-/https://github.com/berriai/litellm/issues/27581
GitHub Β· issue

#27581 [Feature]: cost_per_token() in cost_calculator.py should return (0.0, 0.0) for unrecognized models instead of raising

  • State: open
  • Author: @orvi2014
  • Labels: enhancement, SDK

### Check for existing issues

- [x] I have searched the existing issues and checked that my issue is not a duplicate.

### The Feature

`cost_per_token()` and `completion_cost()` in `litellm/cost_calculator.py` raise an exception when the model is not found in the pricing database:

```python from litellm import cost_per_token cost_per_token( model="openrouter/meta-llama/llama-3.3-70b-instruct", completion_tokens=50, ) # β†’ raises: No cost information for model ``` Proposed fix β€” return `(0.0, 0.0)` with a `UserWarning` instead of raising: ```python # in cost_calculator.py warnings.warn(f"No pricing data for model '{model}'. Returning (0.0, 0.0).") return 0.0, 0.0 ```

### Motivation, pitch

Raising breaks any flow iterating over a mixed list of models. Downstream tools using LiteLLM's pricing functions are forced to wrap every single call in `try/except` and implement their own fallbacks β€” which defeats the purpose of having a shared pricing utility. Returning `(0.0, 0.0)` with a warning is non-breaking: callers that already handle zero cost are unaffected, and callers that relied on the exception can check for…

GitHub resolver

Import GitHub neighbors on demand. Results are saved as system ingests.

Refresh page
vote history (1 events)
#0 of 0 Β· 31d18h28m19s ago β€” entered Β· #import:https:::github.com:berriai:litellm post #2578
The right issue is harder because it requires tracing and correcting duration-unit handling across multiple pricing call paths, preserving compatibility for existing callers, and adding targeted regression coverage. The left issue is comparatively localized: adjust unknown-model handling, emit a warning, and update tests for the changed contract.
discussed in #import:https:::github.com:berriai:litellm

ranked child groups

no voted pairs yet in this scope

cli
src
spread
search