Skip to content

fix(proxy): drop cost-map metadata echoed back on model save - #41944

Merged
ryan-crabbe-berri merged 11 commits into
mainfrom
litellm_lit_5534_cost_map_metadata_echo
Sep 22, 2026
Merged

ryan-crabbe-berri merged 11 commits into
mainfrom
litellm_lit_5534_cost_map_metadata_echo

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

  • Saving a model in the Admin UI edit form stores cost-map metadata the form only displayed
  • Those copies freeze the deployment, later cost map updates never reach it
  • Typing the catalog value back over an override kept the override, because the router had rewritten the live entry

How it solves it:

  • The save path drops fields that still equal the cost-map entry /model/info derived them from (looked up by base_model, else the deployment's decrypted litellm_params.model)
  • The same fields are also compared against the catalog entry for the echoed key as last loaded (remote map or bundled backup, snapshotted before any register_model or router registration touches litellm.model_cost), so a reset reads as an echo even after the router registered a deployment's override under the shared model
  • Edited values differ from both entries and stay real overrides; an override typed back to the catalog value is removed
  • Sits after the earlier pricing-field filter on the same save path

User Flow

Before: an operator changes one field on a deployment in the Admin UI and every cost-map field the form showed is stored as an override

  1. They open http://localhost:4000/ui/?page=models, click a deployment, then Edit; the form shows max tokens, supported params and supports_* flags read from the cost map
  2. They add an access group and click Save; the UI sends PATCH http://localhost:4000/model/{id}/update with the whole form as model_info
  3. GET http://localhost:4000/model/info for that deployment now reports the same values, and the stored deployment carries key, litellm_provider, max_input_tokens, supported_openai_params, supports_* and so on
  4. A later cost map update (a raised context window, a newly supported parameter) never shows up for that deployment because the stale copy now wins
  5. If they lower max_input_tokens to 2048, save, reopen the form and type the original 1047576 back, the deployment keeps a stored max_input_tokens of 1047576 and is frozen at that number forever

After: the same save stores only what the operator set, so cost map updates keep flowing

  1. They open http://localhost:4000/ui/?page=models, click a deployment, then Edit; the form shows the same values
  2. They add an access group and click Save; the UI sends the same PATCH http://localhost:4000/model/{id}/update
  3. The stored deployment carries the access group, the mode set at creation and the bookkeeping fields, none of the cost-map fields
  4. If they had also lowered max_input_tokens in the same form, that one value is stored as an override and the rest still is not
  5. If they reopen the form and type the original 1047576 back, the stored override is removed and the deployment follows the cost map again

Relevant issues

None

Affected release

None (unreleased)

Linear ticket

Resolves LIT-5534

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/test_litellm/<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
  • I have received a Greptile Confidence Score of at least 4/5 before requesting a maintainer review (Greptile reviews automatically once the PR is opened; only comment @greptileai to re-request a review after pushing changes)

Delays in PR merge?

If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).

Taxonomy audit

Run against the current diff (production and test files) using the rules restated in the automation brief plus the H lints; the knowledge note itself was not reachable from this session

  • X1: the echo check uses == against each resolved entry, so 0, False, [] and "" compare as values and are never treated as missing
  • W1: model_dump produces a fresh dict, the filter builds a new mapping, the loaded catalog snapshot is validated through a TypeAdapter into nested MappingProxyType, so neither the caller's updated_patch nor litellm.model_cost is mutated
  • A1/A2: loaded_model_cost_map is re-snapshotted by every cost-map load (startup and the periodic remote refetch, a single attribute rebind so readers see either the old or the new snapshot), the live entry is still read fresh on every save, so nothing stale is served
  • T1-T5: eleven tests, each fails on unfixed code (mutation checks below), none reimplement the filter, monkeypatch restores the one patched lookup
  • F3: add_new_model is excluded on purpose, the Add Model form never sends the cost-map key so the echo cannot occur there
  • D4: a get_model_info lookup failure, an undecryptable stored model, or a key missing from the loaded catalog returns an empty entry, which filters nothing, so a lookup problem can only keep the old behaviour, never drop a value
  • H1-H10: no docs, no new source comments beyond the two helper docstrings matching the neighbouring helpers, no em dashes, X | None style, typed Mapping params, the catalog is validated through a Pydantic TypeAdapter rather than typed Any, line length under 120

Screenshots / Proof of Fix

Shared setup: Postgres plus the proxy started with PYTHONPATH=<checkout> on ~/repro/config.yaml, the Before tree is a worktree at the merge base on port 4011, the After tree is the PR tip on port 4010

model_list:
  - model_name: gpt-4.1-mini
    litellm_params:
      model: openai/gpt-4.1-mini
      api_key: os.environ/OPENAI_API_KEY

general_settings:
  master_key: <local master key, redacted>
  store_model_in_db: true

H='Authorization: Bearer <that key>'. Both arms run the same script (~/repro/arm.sh <port> <id> <tree>) with byte-identical payloads; the served tree is identified by grep -c _loaded_catalog_entry litellm/proxy/management_endpoints/model_management_endpoints.py in the tree the proxy imports (MARKER_loaded_catalog_entry ABSENT for Before, PRESENT for After). row is psql "$DATABASE_URL" -Atc "select model_info from \"LiteLLM_ProxyModelTable\" where model_id='$ID'" with the created_/updated_ bookkeeping fields stripped for readability. The db-mini rows were deleted before each arm

Before (6ef7b86)

add the deployment the way the Add Model form does (model_info = mode only)

  1. curl -s localhost:4011/model/new -H "$H" -H 'Content-Type: application/json' -d '{"model_name":"db-mini","litellm_params":{"model":"openai/gpt-4.1-mini","api_key":"os.environ/OPENAI_API_KEY"},"model_info":{"id":"dep-before-6ef7b8","mode":"chat"}}' -o /dev/null -w "HTTP %{http_code}\n"
  2. Observed output:
MARKER_loaded_catalog_entry ABSENT
HTTP 200

/model/info echoes cost-map metadata into model_info (what the UI edit form seeds)

  1. INFO=$(curl -s "localhost:4011/model/info?litellm_model_id=dep-before-6ef7b8" -H "$H" | python3 -c 'import json,sys; print(json.dumps(json.load(sys.stdin)["data"][0]["model_info"]))')
  2. Observed output:
148 keys, key= gpt-4.1-mini max_input_tokens= 1047576

save the untouched echo with access_groups added

  1. P=$(echo "$INFO" | python3 -c 'import json,sys; d=json.load(sys.stdin); d["access_groups"]=["prod"]; print(json.dumps({"model_info":d}))'); curl -s -X PATCH localhost:4011/model/dep-before-6ef7b8/update -H "$H" -H 'Content-Type: application/json' -d "$P" -o /dev/null -w "HTTP %{http_code}\n"; row
  2. Observed output:
HTTP 200
{"access_groups": ["prod"], "access_via_team_ids": [], "blocked": false, "db_model": true, "direct_access": true, "id": "dep-before-6ef7b8", "key": "gpt-4.1-mini", "litellm_provider": "openai", "max_input_tokens": 1047576, "max_output_tokens": 32768, "max_tokens": 32768, "member_auto_router": false, "mode": "chat", "supported_endpoints": ["/v1/chat/completions", "/v1/batch", "/v1/responses"], "supported_openai_params": ["frequency_penalty", "logit_bias", "logprobs", "top_logprobs", "max_tokens", "max_completion_tokens", "modalities", "prediction", "n", "presence_penalty", "seed", "stop", "stream", "stream_options", "temperature", "top_p", "tools", "tool_choice", "function_call", "functions", "max_retries", "extra_headers", "parallel_tool_calls", "audio", "web_search_options", "service_tier", "safety_identifier", "prompt_cache_key", "prompt_cache_retention", "store", "response_format", "reasoning_effort"], "supports_function_calling": true, "supports_native_streaming": true, "supports_parallel_function_calling": true, "supports_pdf_input": true, "supports_prompt_caching": true, "supports_response_schema": true, "supports_system_messages": true, "supports_tool_choice": true, "supports_vision": true, "supports_web_search": true}

edit max_input_tokens to 2048 in the echoed blob

  1. P=$(echo "$INFO" | python3 -c 'import json,sys; d=json.load(sys.stdin); d["access_groups"]=["prod"]; d["max_input_tokens"]=2048; print(json.dumps({"model_info":d}))'); curl -s -X PATCH localhost:4011/model/dep-before-6ef7b8/update -H "$H" -H 'Content-Type: application/json' -d "$P" -o /dev/null -w "HTTP %{http_code}\n"; row
  2. Observed output (the edit lands, but so does every other cost-map field):
HTTP 200
{"access_groups": ["prod"], ..., "id": "dep-before-6ef7b8", "key": "gpt-4.1-mini", "litellm_provider": "openai", "max_input_tokens": 2048, "max_output_tokens": 32768, "max_tokens": 32768, "member_auto_router": false, "mode": "chat", "supported_endpoints": [...], "supported_openai_params": [...], "supports_function_calling": true, ..., "supports_web_search": true}

reload the form and type the catalog value back

  1. INFO2=$(curl -s "localhost:4011/model/info?litellm_model_id=dep-before-6ef7b8" -H "$H" | ...same extraction...); P=$(echo "$INFO2" | python3 -c "import json,sys; d=json.load(sys.stdin); d['max_input_tokens']=1047576; print(json.dumps({'model_info':d}))"); curl -s -X PATCH localhost:4011/model/dep-before-6ef7b8/update -H "$H" -H 'Content-Type: application/json' -d "$P" -o /dev/null -w "reset to 1047576 -> HTTP %{http_code}\n"; row
  2. Observed output (the typed-back value is stored as a frozen override):
served after edit: max_input_tokens= 2048
reset to 1047576 -> HTTP 200
{"access_groups": ["prod"], ..., "id": "dep-before-6ef7b8", "key": "gpt-4.1-mini", "litellm_provider": "openai", "max_input_tokens": 1047576, "max_output_tokens": 32768, "max_tokens": 32768, "member_auto_router": false, "mode": "chat", "supported_endpoints": [...], "supported_openai_params": [...], "supports_function_calling": true, ..., "supports_web_search": true}

the deployment still serves a real request

  1. curl -s localhost:4011/v1/chat/completions -H "$H" -H 'Content-Type: application/json' -d '{"model":"db-mini","messages":[{"role":"user","content":"Say ok"}],"max_tokens":5}'
  2. Observed output (model, content, total_tokens):
db-mini Ok 10

After (0141ea4; head f8c28e2 adds only a main merge and an equivalent contextlib.suppress swap for the BLE001 budget)

add the deployment the way the Add Model form does (model_info = mode only)

  1. curl -s localhost:4010/model/new -H "$H" -H 'Content-Type: application/json' -d '{"model_name":"db-mini","litellm_params":{"model":"openai/gpt-4.1-mini","api_key":"os.environ/OPENAI_API_KEY"},"model_info":{"id":"dep-after-v4","mode":"chat"}}' -o /dev/null -w "HTTP %{http_code}\n"
  2. Observed output:
MARKER_loaded_catalog_entry PRESENT
HTTP 200

/model/info echoes cost-map metadata into model_info (what the UI edit form seeds)

  1. INFO=$(curl -s "localhost:4010/model/info?litellm_model_id=dep-after-v4" -H "$H" | python3 -c 'import json,sys; print(json.dumps(json.load(sys.stdin)["data"][0]["model_info"]))')
  2. Observed output:
148 keys, key= gpt-4.1-mini max_input_tokens= 1047576

save the untouched echo with access_groups added

  1. P=$(echo "$INFO" | python3 -c 'import json,sys; d=json.load(sys.stdin); d["access_groups"]=["prod"]; print(json.dumps({"model_info":d}))'); curl -s -X PATCH localhost:4010/model/dep-after-v4/update -H "$H" -H 'Content-Type: application/json' -d "$P" -o /dev/null -w "HTTP %{http_code}\n"; row
  2. Observed output:
HTTP 200
{"access_groups": ["prod"], "access_via_team_ids": [], "blocked": false, "db_model": true, "direct_access": true, "id": "dep-after-v4", "member_auto_router": false, "mode": "chat"}

edit max_input_tokens to 2048 in the echoed blob

  1. P=$(echo "$INFO" | python3 -c 'import json,sys; d=json.load(sys.stdin); d["access_groups"]=["prod"]; d["max_input_tokens"]=2048; print(json.dumps({"model_info":d}))'); curl -s -X PATCH localhost:4010/model/dep-after-v4/update -H "$H" -H 'Content-Type: application/json' -d "$P" -o /dev/null -w "HTTP %{http_code}\n"; row
  2. Observed output (only the edited field is stored):
HTTP 200
{"access_groups": ["prod"], "access_via_team_ids": [], "blocked": false, "db_model": true, "direct_access": true, "id": "dep-after-v4", "max_input_tokens": 2048, "member_auto_router": false, "mode": "chat"}

reload the form and type the catalog value back

  1. INFO2=$(curl -s "localhost:4010/model/info?litellm_model_id=dep-after-v4" -H "$H" | ...same extraction...); P=$(echo "$INFO2" | python3 -c "import json,sys; d=json.load(sys.stdin); d['max_input_tokens']=1047576; print(json.dumps({'model_info':d}))"); curl -s -X PATCH localhost:4010/model/dep-after-v4/update -H "$H" -H 'Content-Type: application/json' -d "$P" -o /dev/null -w "reset to 1047576 -> HTTP %{http_code}\n"; row
  2. Observed output (the override is removed even though the router had registered 2048 under openai/gpt-4.1-mini in this process):
served after edit: max_input_tokens= 2048
reset to 1047576 -> HTTP 200
{"access_groups": ["prod"], "access_via_team_ids": [], "blocked": false, "db_model": true, "direct_access": true, "id": "dep-after-v4", "member_auto_router": false, "mode": "chat"}

the deployment still serves a real request

  1. curl -s localhost:4010/v1/chat/completions -H "$H" -H 'Content-Type: application/json' -d '{"model":"db-mini","messages":[{"role":"user","content":"Say ok"}],"max_tokens":5}'
  2. Observed output (model, content, total_tokens):
db-mini Ok 10

Regression tests, run with LITELLM_LOCAL_MODEL_COST_MAP=True uv run --no-sync pytest tests/test_litellm/proxy/management_endpoints/test_model_management_endpoints.py -q: 272 passed. Mutation checks: removing the k not in echoed_fields filter fails the echo tests, removing the cost-map key gate fails the no-key test, removing the equality check fails the edited-value test, removing the reset loop fails the reset test, looking the entry up by key instead of the deployment model fails 3 tests, skipping decryption fails the encrypted-model test, dropping the loaded catalog argument fails test_reset_is_recognised_after_the_router_registered_the_override and test_reset_to_a_remote_catalog_value_that_differs_from_the_bundled_one, replacing the snapshot call with pass fails test_loaded_catalog_snapshot_follows_the_fetched_map_and_ignores_later_registrations in tests/test_litellm/litellm_core_utils/test_get_model_cost_map.py (34 passed). make check passes

Type

🐛 Bug Fix

Caveats (if any)

Low

  • A value equal to a sibling deployment's registered override is still treated as an echo (the live entry is one of the two comparison sources); the served value is unchanged because the router already serves the registered value
  • The catalog snapshot is whatever load ran last; a key absent from it falls back to the live entry alone, which is the previous behaviour
  • The Add Model form is out of scope: it never sends key, so no echo happens there
  • The filter runs on /model/{id}/update (both the admin and the team-model paths share update_db_model). The legacy /model/update never writes incoming model_info, so it has nothing to filter
  • The regression tests for the router-registered and remote-catalog cases monkeypatch litellm.get_model_info for the duration of the test, since the live lookup is a module function rather than an injected dependency; the loaded catalog is injected into update_db_model as a callable instead

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR

Link to Devin session: https://app.devin.ai/sessions/a4ca2e0396d94fe9a24d7805d503de96
Open in Devin Desktop: https://app.devin.ai/desktop/session/a4ca2e0396d94fe9a24d7805d503de96?variant=devin

Filter unchanged cost-map fields from model-info save echoes while preserving edited overrides.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@devin-ai-integration
devin-ai-integration Bot requested review from a team and tin-berri September 19, 2026 09:14
@codspeed

codspeed Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing litellm_lit_5534_cost_map_metadata_echo (f8c28e2) with main (79d6e23)

Open in CodSpeed

@greptile-apps

greptile-apps Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

The PR appears safe to merge; no actionable regression or outstanding previous finding remains.

Summary

This PR prevents metadata supplied by /model/info from becoming frozen deployment overrides when the Admin UI saves a model.

  • Snapshots the last-loaded bundled or remote cost catalog independently of router registrations.
  • Removes unchanged echoed cost-map fields while preserving genuine edits.
  • Recognizes resets to catalog values and deletes stale stored overrides.
  • Adds regression coverage for remote catalogs, encrypted model names, base-model lookup, edited values, and reset behavior.
  • The latest revision replaces a broad try/except Exception with behaviorally equivalent contextlib.suppress(Exception).

Reviews (7) · Last reviewed commit: "fix(proxy): use contextlib.suppress for ..."

Comment thread litellm/types/utils.py Resolved
@codecov

codecov Bot commented Sep 19, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.72727% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...management_endpoints/model_management_endpoints.py 96.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

ryan-crabbe-berri and others added 3 commits September 19, 2026 09:29
…he cost-map value

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
… lookup

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

@greptileai

@tin-berri tin-berri 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.

Approving. Filters out model_info fields the Admin UI echoes back unchanged from /model/info, so a plain save no longer persists cost-map display values as operator overrides. Using the presence of the cost-map key as the echo signal, plus per-field equality against the resolved entry, means an edited value still counts as a real override. base_model and encrypted-model lookup paths are covered in tests.

ryan-crabbe-berri and others added 2 commits September 20, 2026 08:52
…n after router registration

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

@greptileai

… the bundled backup

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

@greptileai

…apping[str, object]

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

@greptileai

…f patching the class

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

@greptileai

…_map_metadata_echo

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

# Conflicts:
#	litellm/proxy/management_endpoints/model_management_endpoints.py
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

@greptileai merged main into head 099a8f6 (import-order conflict only); verdict for 0141ea4 remains an ancestor.

@greptile-apps

greptile-apps Bot commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

The main merge only resolves an import-order conflict. The reviewed PR changes remain an ancestor, so the previous 5/5 confidence score and no-actionable-findings verdict still stand.

…under BLE001 budget

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

@greptileai new head f8c28e2: swapped the blind except for contextlib.suppress after main used up the BLE001 budget.

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