Skip to content

chore(release): backport #53994 to rc/1.112.0 - #54018

Merged
yuneng-berri merged 1 commit into
rc/1.112.0from
litellm_backport_rc_1_112_0_53994
Nov 24, 2026
Merged

yuneng-berri merged 1 commit into
rc/1.112.0from
litellm_backport_rc_1_112_0_53994

Conversation

@yuneng-berri

@yuneng-berri yuneng-berri commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Handwritten 1-3 sentence description

[insert handwritten description here]

Details

TLDR

Problem this solves:

How it solves it:

User Flow

Before: an admin sets a custom price on an image deployment, and the proxy bills the catalog price instead

  1. The admin adds a deployment openai/gpt-image-2.5-flare with output_cost_per_image_token: 0.0003, ten times the catalog rate
  2. A developer sends POST http://localhost:4199/v1/images/generations with that model and gets 200
  3. The response carries x-litellm-response-cost: 0.005945, the catalog price (no header at all for a model missing from the cost map)
  4. GET http://localhost:4199/key/info charges the key that same catalog amount

After: the same call bills the deployment's price

  1. The admin adds the same deployment
  2. The developer sends the same POST and gets 200
  3. The response carries x-litellm-response-cost: 0.058865, which is 196 image tokens × 0.0003 plus 13 input tokens × 5e-06
  4. GET http://localhost:4199/key/info charges the key the deployment's price

Affected 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

  • I have added meaningful tests
  • The handful of test files covering my change pass locally, e.g. 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 more
  • My PR passes all required CI/CD checks (e.g., lint, schema.d.ts sync check, etc.)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • Every automated review on my PR's latest commit has finished, and I have addressed or replied to each of its findings before requesting a maintainer review

Delays 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 --reload picked up. Calls go to the real OpenAI API. Env var names are OPENAI_API_KEY, LITELLM_MASTER_KEY, LITELLM_SALT_KEY, LITELLM_LICENSE and DATABASE_URL, with LITELLM_MODE=PRODUCTION and LITELLM_LOCAL_MODEL_COST_MAP=True.

python litellm/proxy/proxy_cli.py --config config.yaml --port 4199 --num_workers 2 --detailed_debug --reload --use_v2_migration_resolver
config.yaml
model_list:
  - model_name: priced-mapped
    litellm_params:
      model: openai/gpt-image-2.5-flare
      api_key: os.environ/OPENAI_API_KEY
      output_cost_per_image_token: 0.0003
  - model_name: priced-unmapped
    litellm_params:
      model: openai/gpt-image-2.6-flare
      api_key: os.environ/OPENAI_API_KEY
      output_cost_per_image_token: 0.0003
  - model_name: catalog-mapped
    litellm_params:
      model: openai/gpt-image-2.5-flare
      api_key: os.environ/OPENAI_API_KEY

router_settings:
  redis_host: 127.0.0.1
  redis_port: 6391

general_settings:
  master_key: os.environ/LITELLM_MASTER_KEY
  coordination_redis:
    host: 127.0.0.1
    port: 6391

priced-unmapped turned out to be a misnomer, because gpt-image-2.6-flare is in this line's cost map. The truly unmapped case is covered by the integration run below, where openai/dall-e-3 isn't in the cost map.

probe.sh (generates a key, calls each deployment once, reads spend)
B=http://127.0.0.1:4199
H="Authorization: Bearer $LITELLM_MASTER_KEY"
KEY=$(curl -s $B/key/generate -H "$H" -H 'content-type: application/json' -d "{\"key_alias\":\"img-$leg\"}" | python3 -c 'import sys,json;print(json.load(sys.stdin)["key"])')
for m in priced-mapped priced-unmapped catalog-mapped; do
  curl -s -D $leg-$m.headers -o $leg-$m.body $B/v1/images/generations -H "Authorization: Bearer $KEY" -H 'content-type: application/json' \
    -d "{\"model\":\"$m\",\"prompt\":\"a red circle on a white background\",\"size\":\"1024x1024\",\"quality\":\"low\"}"
done
curl -s "$B/key/info?key=$KEY" -H "$H"
psql -c "select model_group, spend from \"LiteLLM_SpendLogs\" where metadata->>'user_api_key_alias' = 'img-$leg'"

Before (8fa0abd)

priced-mapped   | 200 | x-litellm-response-cost=0.005945 | output image tokens 196, input 13
priced-unmapped | 200 | x-litellm-response-cost=0.024785 | output image tokens 824, input 13
catalog-mapped  | 200 | x-litellm-response-cost=0.005945 | output image tokens 196, input 13
key spend: 0.036675
spend logs: priced-mapped 0.005945, priced-unmapped 0.024785, catalog-mapped 0.005945

Both priced deployments bill the catalog output_cost_per_image_token of 3e-05 (196 × 3e-05 + 13 × 5e-06 = 0.005945), and the custom 0.0003 is ignored.

After (0c794f4)

priced-mapped   | 200 | x-litellm-response-cost=0.058865 | output image tokens 196, input 13
priced-unmapped | 200 | x-litellm-response-cost=0.247265 | output image tokens 824, input 13
catalog-mapped  | 200 | x-litellm-response-cost=0.005945 | output image tokens 196, input 13
key spend: 0.312075
spend logs: priced-mapped 0.058865, priced-unmapped 0.247265, catalog-mapped 0.005945

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.

python -m pytest tests/unit/images/test_main.py -q
python tests/integration/run.py accounting --workers 2 tests/integration/spend/test_image_generation_key_spend.py tests/integration/spend/test_vertex_image_regional_uplift.py

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 unmapped openai/dall-e-3 priced through output_cost_per_image) and test_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 in test_vertex_image_regional_uplift.py.

ruff check and ruff format --check pass on litellm/images/main.py, and ruff check --config .github/linters/ruff-tests.toml passes 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-3 deployment with output_cost_per_image: 0.25 goes from no cost to 0.25, an Azure deployment with base_model: dall-e-3 and output_cost_per_image: 0.3 goes from the catalog 0.132 to 0.3, and a Gemini Imagen deployment with output_cost_per_image: 0.5 goes 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

…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)
@yuneng-berri
yuneng-berri requested a review from a team November 24, 2026 01:49
@veria-ai

veria-ai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

PR overview

No security issues were found in this pull request.

Reviews

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@yuneng-berri
yuneng-berri merged commit 8f11189 into rc/1.112.0 Nov 24, 2026
66 of 67 checks passed
@yuneng-berri
yuneng-berri deleted the litellm_backport_rc_1_112_0_53994 branch November 24, 2026 02:04
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.

3 participants