litellm - 💡(How to fix) Fix [Bug]: Cost calculation ignores custom pricing intermittently

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Custom pricing is sometimes ignored, causing cost calculations to use default provider prices instead.

Root Cause

  1. When models are registered via Router.add_deployment(), the litellm_provider field is not included in the model_info dict passed to register_model().
  2. Inside register_model() (utils.py:2887-2892), get_model_info() is called without custom_llm_provider, which returns a dict with litellm_provider: None.
  3. This None value gets merged into the model_cost entry via _update_dictionary().
  4. _check_provider_match() (utils.py:5425-5463) has inconsistent behavior: - Key does NOT exist → returns True (cost calculation works) ✅ - Key exists with None value → returns False (cost calculation fails) ❌

Impact

  • Custom pricing is ignored
  • Default provider pricing is used instead
  • Cost calculations are incorrect
  • Budget enforcement fails

Suggested Fix

  1. Include litellm_provider during registration: Router.add_deployment() should include the litellm_provider key in the model_info dict when calling register_model(). For OpenAI models, this should be set to "openai".
  2. Handle None consistently in _check_provider_match: The function should treat a missing litellm_provider key the same as litellm_provider: None. Both cases should return True to allow the cost calculation to proceed:

Fix Action

Fix / Workaround

  1. When models are registered via Router.add_deployment(), the litellm_provider field is not included in the model_info dict passed to register_model().
  2. Inside register_model() (utils.py:2887-2892), get_model_info() is called without custom_llm_provider, which returns a dict with litellm_provider: None.
  3. This None value gets merged into the model_cost entry via _update_dictionary().
  4. _check_provider_match() (utils.py:5425-5463) has inconsistent behavior: - Key does NOT exist → returns True (cost calculation works) ✅ - Key exists with None value → returns False (cost calculation fails) ❌
RAW_BUFFERClick to expand / collapse

Check for existing issues

  • I have searched the existing issues and checked that my issue is not a duplicate.

What happened?

Description

Custom pricing is sometimes ignored, causing cost calculations to use default provider prices instead.

Investigation

  • When custom pricing works: The model_info dict returned by _get_model_info_from_model_cost() does not have a litellm_provider key. _check_provider_match() returns True, and custom pricing is used.
  • When custom pricing fails: The model_info dict contains litellm_provider key set to None. _check_provider_match() returns False, causing cost calculation to fall back to default prices.

Root Cause

  1. When models are registered via Router.add_deployment(), the litellm_provider field is not included in the model_info dict passed to register_model().
  2. Inside register_model() (utils.py:2887-2892), get_model_info() is called without custom_llm_provider, which returns a dict with litellm_provider: None.
  3. This None value gets merged into the model_cost entry via _update_dictionary().
  4. _check_provider_match() (utils.py:5425-5463) has inconsistent behavior: - Key does NOT exist → returns True (cost calculation works) ✅ - Key exists with None value → returns False (cost calculation fails) ❌

Impact

  • Custom pricing is ignored
  • Default provider pricing is used instead
  • Cost calculations are incorrect
  • Budget enforcement fails

Suggested Fix

  1. Include litellm_provider during registration: Router.add_deployment() should include the litellm_provider key in the model_info dict when calling register_model(). For OpenAI models, this should be set to "openai".
  2. Handle None consistently in _check_provider_match: The function should treat a missing litellm_provider key the same as litellm_provider: None. Both cases should return True to allow the cost calculation to proceed:

Steps to Reproduce

  1. Create a model with custom pricing via the /model/new API
  2. Create an API key with a budget limit
  3. Send completion requests to the model
  4. Observe that custom pricing is not always used for cost calculations

Relevant log output

What part of LiteLLM is this about?

Proxy

What LiteLLM version are you on ?

v1.83.14

Twitter / LinkedIn details

No response

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

litellm - 💡(How to fix) Fix [Bug]: Cost calculation ignores custom pricing intermittently