Repository navigation
chore(release): backport #53994 to rc/1.112.0 - #54018
Merged
Merged
Conversation
…creates the logging object (#53994) * fix(images): bill the deployment's custom pricing when the proxy pre-creates the logging object Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fix(images): read custom pricing kwargs without an untyped get --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> (cherry picked from commit 6a9bd22)
Contributor
PR overviewNo security issues were found in this pull request. Reviews
|
tin-berri
approved these changes
Nov 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Handwritten 1-3 sentence description
[insert handwritten description here]
Details
TLDR
Problem this solves:
How it solves it:
-x, patch-id identicalUser Flow
Before: an admin sets a custom price on an image deployment, and the proxy bills the catalog price instead
openai/gpt-image-2.5-flarewithoutput_cost_per_image_token: 0.0003, ten times the catalog ratex-litellm-response-cost: 0.005945, the catalog price (no header at all for a model missing from the cost map)After: the same call bills the deployment's price
x-litellm-response-cost: 0.058865, which is 196 image tokens × 0.0003 plus 13 input tokens × 5e-06Affected release
Regression on rc/1.112.0 (not tagged yet), from #52103, which is on this line.
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
uv run pytest tests/unit/<your_test_file>.py -v. Leave the suites (make test-unit-*,make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or moreDelays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
Screenshots / Proof of Fix
Both legs ran against the same proxy process, with 2 workers (PIDs 56117 and 56118 before, 57245 and 57246 after the reload), one dedicated Redis and a UTC Postgres. Before is the rc tip 8fa0abd, and after is this branch at 0c794f4, which
--reloadpicked up. Calls go to the real OpenAI API. Env var names areOPENAI_API_KEY,LITELLM_MASTER_KEY,LITELLM_SALT_KEY,LITELLM_LICENSEandDATABASE_URL, withLITELLM_MODE=PRODUCTIONandLITELLM_LOCAL_MODEL_COST_MAP=True.config.yaml
priced-unmappedturned out to be a misnomer, becausegpt-image-2.6-flareis in this line's cost map. The truly unmapped case is covered by the integration run below, whereopenai/dall-e-3isn't in the cost map.probe.sh (generates a key, calls each deployment once, reads spend)
Before (8fa0abd)
Both priced deployments bill the catalog
output_cost_per_image_tokenof 3e-05 (196 × 3e-05 + 13 × 5e-06 = 0.005945), and the custom 0.0003 is ignored.After (0c794f4)
Both priced deployments now bill 0.0003 per image token (196 × 0.0003 + 13 × 5e-06 = 0.058865, and 824 × 0.0003 + 13 × 5e-06 = 0.247265). The deployment without an override still bills the catalog rate, and key spend is the sum of the three.
Tests on this line
Both legs ran the same commands on the same tree, before and after the pick.
Before at 8fa0abd, the unit file had 70 passed, and the integration run had 2 failed and 33 passed. The two failures were
test_identical_image_generations_each_charge_the_key(assert 0.0 == 0.25, an unmappedopenai/dall-e-3priced throughoutput_cost_per_image) andtest_openai_style_image_deployment_is_untouched(KeyError: 'x-litellm-response-cost'). After at 0c794f4, the unit file had 71 passed, including the new test, and the integration run had 35 passed. That includes the Gemini and Vertex fan-out cases intest_vertex_image_regional_uplift.py.ruff checkandruff format --checkpass onlitellm/images/main.py, andruff check --config .github/linters/ruff-tests.tomlpasses on the test file.Adversarial review
gauntlet-mini ran five review lenses (correctness, dependents, black-box, contract, conventions and tests) against this branch and the rc tip, and none found a regression. In every case it ran, this branch bills the same as an image call that goes through the Router without a pre-made logging object, which is the path that already billed correctly. The cases that bill differently from the rc tip are the ones the fix targets. An unmapped
dall-e-3deployment withoutput_cost_per_image: 0.25goes from no cost to 0.25, an Azure deployment withbase_model: dall-e-3andoutput_cost_per_image: 0.3goes from the catalog 0.132 to 0.3, and a Gemini Imagen deployment withoutput_cost_per_image: 0.5goes from 0.0 to 0.5. Deployments without a price override, chat token prices on image models and the Gemini n=3 fan-out bill the same as before. The new unit test kills 4 mutants of the change. These runs mock the provider at httpx, so the live proof above is still the real-provider evidence, and Azure, Vertex and Bedrock were not run live.It also found four gaps that are on the rc tip and on main alike, so this PR leaves them alone. A per-image price is ignored on a token-billed image model whose response carries usage, a 0.0 price on a token-billed model bills the catalog rate, an unmapped token-priced model returns no cost, and a direct SDK
litellm.image_generation(..., output_cost_per_image=...)call without the Router is still not billed.Type
🐛 Bug Fix