Skip to content

fix(cost_calculator): honor base_model's own provider in cost-logging metadata too - #48013

Open
rupeshpoojary9 wants to merge 2 commits into
BerriAI:mainfrom
rupeshpoojary9:fix/base-model-cross-provider-cost-logging
Open

rupeshpoojary9 wants to merge 2 commits into
BerriAI:mainfrom
rupeshpoojary9:fix/base-model-cross-provider-cost-logging

Conversation

@rupeshpoojary9

Copy link
Copy Markdown

Fixes the remaining part of #47908, after #46318.

#46318 fixed completion_cost() to honor base_model's own registered provider when the deployment's transport provider has no rates for it, so spend computes correctly. The diagnostic model_map_information field built in litellm_logging.py (StandardLoggingPayloadSetup.get_model_cost_information) never got the same fix: it still calls get_model_info() with the raw transport custom_llm_provider, which _check_provider_match rejects, so model_map_value stays None even though the spend amount next to it is now correct. Confirmed directly:

StandardLoggingPayloadSetup.get_model_cost_information(
    base_model="zai/glm-5.3-flash",
    custom_pricing=False,
    custom_llm_provider="openai",
    init_response_obj=None,
)
# main: model_map_value is None
# this PR: model_map_value has the zai pricing row

Reuses the same _base_model_pricing_provider helper #46318 added, applied to this lookup too.

Added a regression test with a registered test-only model under a distinct provider, mirroring the existing tests for this function. Ran the full test_litellm_logging.py and test_cost_calculator.py suites (via uv sync --frozen --all-groups --all-extras): 1232 passed, 1 pre-existing unrelated failure (test_base_model_keeps_deployment_provider_row_that_declares_rates, fails identically on unmodified main, confirmed before and after this change). Lint and format clean on both touched files.

… metadata too

completion_cost() already resolves the correct provider for billing when
base_model points at a priced row under a different provider than the
deployment's transport (e.g. a chatgpt/ subscription deployment priced
via an openai/ or zai/ base_model, fixed in BerriAI#46318). The diagnostic
model_map_information field built in litellm_logging.py never got the
same correction: it calls get_model_info() with the raw transport
provider, which _check_provider_match rejects, so model_map_value stays
None even though spend is now computed correctly. Reuses the same
_base_model_pricing_provider helper for this lookup too.

Fixes BerriAI#47908 (the remaining part after BerriAI#46318)
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@codspeed

codspeed Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 35 untouched benchmarks


Comparing rupeshpoojary9:fix/base-model-cross-provider-cost-logging (f0811a0) with main (72f1ac4)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (dddbaa8) during the generation of this report, so 72f1ac4 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@codecov

codecov Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
litellm/litellm_core_utils/litellm_logging.py 50.00% 3 Missing ⚠️

📢 Thoughts on this report? Let us know!

…r cross-module use

Importing the underscore-prefixed helper from litellm_logging added one
reportPrivateUsage and breached the basedpyright ceiling.

This branch has not been deployed

No deployments
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.

2 participants