Backtestslitellmrun-20261111-220245#23998

Issue #23998 Merged fix PR #48456 Run 11 Nov 2026 · run-20261111-220245 BerriAI/litellm

[Bug]: Unable to re-edit Model LiteLLM Params on LiteLLM UI

Better

Our patch was judged better than the merged fix.

In this judgment, Patch A = our agent, Patch B = the merged fix.

Both patches make the independent tests pass and both fix the actual mechanism behind the bug: the model PATCH merges submitted litellm_params over the stored blob, so a key deleted from the JSON editor is merely omitted and survives the save. Patch A fixes this with a small, coherent change on both sides: the UI diffs the keys it showed in the editor against the edited JSON and sends an explicit null for each removed key, and update_db_model pops explicitly-nulled undeclared (model_extra) keys from the merged litellm_params/model_info, while refusing to clear secret-looking keys. It adds backend unit tests (removal, omission keeps, secret-looking null ignored, model_info custom key removed but team_id kept) and UI tests that drive the editor and assert the payload and post-save view, plus unit tests for the small helper. Weaknesses: it only handles undeclared keys, so declared runtime defaults shown in the editor (use_litellm_proxy, use_in_pass_through) still cannot be removed, and the comment admits access_groups now becomes null-clearable, slightly relaxing a prior guard. Patch B is a much broader redesign: a new PatchModelRequest schema with litellm_params_to_remove replacing updateDeployment on the PATCH route, a new use_stored_params query flag on /v2/model/info with an extra DB lookup, exclude_unset=True on the stored-params dump (changing what gets written back for every PATCH), frozen request models requiring a rewrite of the team-update path, new PTU/aws_session_tags/strategy-router removal checks, removal of the modelInfoV1Call fallback, a change in editor semantics (form-managed params hidden from the JSON box, altering existing test expectations), a test-file rename, and eslint-suppression edits. It does address the defaults-reappearing aspect more completely and its tests are substantial, but the amount of behaviour touched (API contract, write path for all patches, editor contents) carries materially more regression risk than the issue warrants, and several changes (exclude_unset, dropping the v1 fallback) are hard to validate from the diff alone. Weighing correctness on the reported scenario (both pass), tests (both adequate), scope (A tight, B expansive with added risk) and craft, A is the better fix for this issue.

Four judges ruled on this ticket in parallel, and the verdict comes from counting their votes. Each saw the issue and the two patches, labelled A and B in random order (two of them saw ours as A), with issue links and version numbers removed. Where tests could check the fix, they also saw the results of tests a separate agent wrote for the issue, run on both patches. None was told which patch was ours. The reasoning above is one judge's, shown verbatim.

Solve

20m 30s

Wall-clock time in the container

Full test suite

Not run

The harness did not reach the test stage

Contamination audit

Clean

No sign the agent saw the real fix

Patch size

247vs 695 merged

Changed lines, ours vs merged

Check for existing issues

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

What happened?

Once parameter is added to LiteLLM Params it's can't be removed.

{
"input_cost_per_token": 0.00000125,
"output_cost_per_token": 0.00001,
"api_base": "https://api.openai.com/v1",
"custom_llm_provider": "openai",
"use_in_pass_through": false,
"use_litellm_proxy": false,
"merge_reasoning_content_in_choices": false,
"model": "gpt-5",
"tags": [],
"guardrails": []
}

Steps to Reproduce

  1. Go to Model Management
  2. Click on Model ID
  3. Click on Overview and Edit setting button
  4. Add custom parameter like litellm_image_enabled
  5. Save it

Relevant log output

After refreshing UI the LiteLLM Params section removed parameter re-appears

What part of LiteLLM is this about?

UI Dashboard

What LiteLLM version are you on ?

1.81.16-nightly

Twitter / LinkedIn details

_No response_

The two patches

Our patch+228 −19
litellm/proxy/management_endpoints/model_management_endpoints.pyindex 11f616a5e1..839233df9d 100644@@ -41,7 +41,7 @@ from litellm.litellm_core_utils.ptu_pricing import (     parsed_ptu_shares,     ptu_config_error, )-from litellm.litellm_core_utils.sensitive_data_masker import redact_credentials_in_payload+from litellm.litellm_core_utils.sensitive_data_masker import SensitiveDataMasker, redact_credentials_in_payload from litellm.proxy._types import (     BlockModelRequest,     CommonProxyErrors,@@ -493,6 +493,21 @@ def _dump_without_none(model: BaseModel) -> Mapping[str, object]:     return model.model_dump(exclude_none=True)  +_CLEARABLE_EXTRA_KEY_MASKER: Final = SensitiveDataMasker()+++def _null_cleared_extra_keys(model: BaseModel) -> frozenset[str]:+    """Custom (undeclared) keys the patch explicitly set to null, e.g. a key the user+    deleted from the dashboard's JSON editor. Declared fields keep their own clear+    rules, and secret-looking keys are never cleared so a patch cannot strip a stored+    credential and fall back to the proxy's environment credentials."""+    return frozenset(+        key+        for key, value in (model.model_extra or {}).items()+        if value is None and not _CLEARABLE_EXTRA_KEY_MASKER.is_sensitive_key(key)+    )++ def _decrypted_litellm_params(litellm_params: GenericLiteLLMParams) -> Mapping[str, object]:     dumped: Final = _dump_without_none(litellm_params)     return MappingProxyType(@@ -1117,11 +1132,12 @@ def update_db_model(     # Honor explicit-null clears LAST, after both merges, so a model_info blob a client     # passes through cannot silently undo a litellm_params clear via .update().     #-    # Restricted to SPECIAL_MODEL_INFO_PARAMS (input/output cost per token/character-    # and cache read/write costs) so this path cannot be used to null out privileged-    # model_info fields like team_id or access groups. SPECIAL_MODEL_INFO_PARAMS are-    # mirrored between litellm_params and model_info by Deployment.__init__, so the-    # clear propagates to both blobs.+    # Declared fields are restricted to SPECIAL_MODEL_INFO_PARAMS (input/output cost+    # per token/character and cache read/write costs) so this path cannot be used to+    # null out privileged declared model_info fields like team_id.+    # SPECIAL_MODEL_INFO_PARAMS are mirrored between litellm_params and model_info by+    # Deployment.__init__, so the clear propagates to both blobs. Undeclared custom+    # keys (including access_groups) are cleared via _null_cleared_extra_keys.     if updated_patch.litellm_params:         for field in updated_patch.litellm_params.model_fields_set:             if getattr(updated_patch.litellm_params, field) is None and field in NULL_CLEARABLE_LITELLM_PARAMS:@@ -1136,7 +1152,11 @@ def update_db_model(                 and getattr(updated_patch.litellm_params, field) is None             ):                 merged_litellm_params.pop(field, None)+        for field in _null_cleared_extra_keys(updated_patch.litellm_params):+            merged_litellm_params.pop(field, None)     if updated_patch.model_info:+        for field in _null_cleared_extra_keys(updated_patch.model_info):+            merged_model_info.pop(field, None)         for field in updated_patch.model_info.model_fields_set:             if field in SPECIAL_MODEL_INFO_PARAMS and getattr(updated_patch.model_info, field) is None:                 merged_model_info.pop(field, None)tests/unit/proxy/management_endpoints/test_model_management_endpoints.pyindex a718426eea..56026251c7 100644@@ -4865,6 +4865,63 @@ class TestUpdateDBModelClearCredentialName:         assert params["tpm"] == 100  +class TestUpdateDBModelClearCustomParams:+    """A key the user deletes from the dashboard's JSON editors arrives as an explicit null."""++    @staticmethod+    def _db_model() -> Deployment:+        return Deployment(+            model_name="gpt-5",+            litellm_params=LiteLLM_Params(+                model="gpt-5",+                api_base="https://api.openai.com/v1",+                api_key="sk-real",+                litellm_image_enabled=True,+                custom_secret_token="stored-secret",+            ),+            model_info=ModelInfo(id="dep-custom-1", team_id="team-keep", owner_note="remove me"),+        )++    @staticmethod+    def _update(payload: dict[str, object]) -> tuple[dict[str, object], dict[str, object]]:+        from litellm.proxy.management_endpoints.model_management_endpoints import update_db_model++        with patch(+            "litellm.proxy.management_endpoints.model_management_endpoints.encrypt_value_helper",+            side_effect=lambda value, **kwargs: value,+        ):+            result: Final = update_db_model(+                db_model=TestUpdateDBModelClearCustomParams._db_model(),+                updated_patch=updateDeployment.model_validate(payload),+            )+        return json.loads(result["litellm_params"]), json.loads(result["model_info"])++    def test_null_custom_litellm_param_is_removed_from_stored_params(self):+        params, _ = self._update({"litellm_params": {"model": "gpt-5", "litellm_image_enabled": None}})++        stored: Final = self._db_model().litellm_params.model_dump(exclude_none=True)+        assert stored["litellm_image_enabled"] is True+        assert params == {k: v for k, v in stored.items() if k != "litellm_image_enabled"}, params++    def test_omitted_custom_litellm_param_is_kept(self):+        params, _ = self._update({"litellm_params": {"model": "gpt-5", "tpm": 10}})++        assert params["litellm_image_enabled"] is True, params+        assert params["tpm"] == 10, params++    def test_null_on_secret_looking_custom_param_does_not_clear_it(self):+        params, _ = self._update({"litellm_params": {"custom_secret_token": None, "api_key": None}})++        assert params["custom_secret_token"] == "stored-secret", params+        assert params["api_key"] == "sk-real", params++    def test_null_custom_model_info_key_is_removed_and_team_id_kept(self):+        _, info = self._update({"model_info": {"id": "dep-custom-1", "owner_note": None, "team_id": None}})++        assert "owner_note" not in info, info+        assert info["team_id"] == "team-keep", info++ class TestPatchModelCredentialName:     @staticmethod     async def _patch_model(ui/litellm-dashboard/src/components/ModelInfoEditForm.tsxindex 70fe23202b..904e6d68b7 100644@@ -195,6 +195,16 @@ const perMillionTokens = (...rates: (number | null | undefined)[]): number | nul   return rate == null ? null : rate * 1_000_000; }; +// The params shown in the "LiteLLM Params" JSON editor.+export const editableLitellmParams = (+  litellmParams: Record<string, unknown> | null | undefined,+): Record<string, unknown> =>+  Object.fromEntries(+    Object.entries(litellmParams || {}).filter(+      ([key, value]) => key !== "litellm_credential_name" && !isMaskedSecret(value),+    ),+  );+ export const toModelEditFormValues = (localModelData: any, isWildcardModel: boolean): ModelEditFormValues => ({   model_name: localModelData.model_name,   litellm_model_name: localModelData.litellm_model_name,@@ -245,15 +255,7 @@ export const toModelEditFormValues = (localModelData: any, isWildcardModel: bool   // antd never mounted this field for a non-wildcard model, so the key must be absent, not null.   ...(isWildcardModel ? { health_check_model: localModelData.model_info?.health_check_model } : {}),   litellm_credential_name: localModelData.litellm_params?.litellm_credential_name ?? null,-  litellm_extra_params: JSON.stringify(-    Object.fromEntries(-      Object.entries(localModelData.litellm_params || {}).filter(-        ([key, value]) => key !== "litellm_credential_name" && !isMaskedSecret(value),-      ),-    ),-    null,-    2,-  ),+  litellm_extra_params: JSON.stringify(editableLitellmParams(localModelData.litellm_params), null, 2),   team_id: localModelData.model_info?.team_id ?? undefined, }); ui/litellm-dashboard/src/components/model_info_view.test.tsxindex 2e85fab5b7..2f16e57137 100644@@ -1977,6 +1977,61 @@ describe("ModelInfoView", () => {       expect(payload.litellm_params.drop_params).toBe(true);     }); +    it("removes a custom param deleted from the LiteLLM Params JSON", async () => {+      const customParamModel = {+        ...defaultModelData,+        litellm_params: { ...defaultModelData.litellm_params, litellm_image_enabled: true },+      };+      mockUseModelsInfo.mockReturnValue({ data: { data: [customParamModel] }, isLoading: false, error: null });+      mockModelInfoV1Call.mockResolvedValue({ data: [customParamModel] });+      const user = userEvent.setup();+      await enterEditMode(user);++      const extraParams = screen+        .getAllByRole("textbox")+        .find(+          (input) =>+            input.tagName === "TEXTAREA" && (input as HTMLTextAreaElement).value.includes('"litellm_image_enabled"'),+        ) as HTMLTextAreaElement;+      await user.clear(extraParams);+      await user.paste(+        '{"model":"gpt-4","api_base":"https://api.openai.com/v1","custom_llm_provider":"openai"}',+      );++      const payload = await save(user);++      expect(payload.litellm_params).toHaveProperty("litellm_image_enabled", null);+      expect(payload.litellm_params.model).toBe("gpt-4");+      expect(await screen.findByRole("button", { name: /edit settings/i })).toBeInTheDocument();+      expect(screen.queryByText(/litellm_image_enabled/)).not.toBeInTheDocument();+    });++    it("removes a key deleted from the Model Info JSON", async () => {+      const customInfoModel = {+        ...defaultModelData,+        model_info: { ...defaultModelData.model_info, deployment_notes: "legacy" },+      };+      mockUseModelsInfo.mockReturnValue({ data: { data: [customInfoModel] }, isLoading: false, error: null });+      mockModelInfoV1Call.mockResolvedValue({ data: [customInfoModel] });+      const user = userEvent.setup();+      await enterEditMode(user);++      const modelInfo = screen.getByPlaceholderText('{"gpt-4": 100, "claude-v1": 200}');+      await user.clear(modelInfo);+      await user.paste(+        '{"id":"123","created_by":"123","created_at":"2024-01-01T00:00:00Z","input_cost_per_token":0.00003,"output_cost_per_token":0.00006}',+      );++      const payload = await save(user);++      expect(payload.model_info).toHaveProperty("deployment_notes", null);+      // db_model is a non-optional boolean server-side; a null would fail the PATCH with a 422.+      expect(payload.model_info).not.toHaveProperty("db_model");+      expect(payload.model_info.id).toBe("123");+      expect(await screen.findByRole("button", { name: /edit settings/i })).toBeInTheDocument();+      expect(screen.queryByText(/deployment_notes/)).not.toBeInTheDocument();+    });+     it("sends the credential picked in the selector", async () => {       mockCredentialListCall.mockResolvedValue({         credentials: [ui/litellm-dashboard/src/components/model_info_view.tsxindex 74c1e49859..e7f5c33d91 100644@@ -13,6 +13,7 @@ import { ArrowLeft, CheckIcon, CopyIcon, Info } from "lucide-react"; import { useEffect, useMemo, useState } from "react"; import { copyToClipboard as utilCopyToClipboard } from "../utils/dataUtils"; import { stripMaskedSecrets } from "../utils/maskedSecretUtils";+import { removedJsonKeys, withoutKeys } from "../utils/jsonEditPatch"; import { truncateString } from "../utils/textUtils"; import AutoRouterConnectionTest from "./add_model/auto_router_connection_test"; import { buildSavedJevConnectionTestRequest } from "./add_model/build_auto_router_routing_test_request";@@ -46,12 +47,19 @@ import { import { Logo } from "@/components/molecules/logo/Logo"; import { ModelPricingSummary } from "@/components/molecules/models/ModelPricingSummary"; import UpdateModelCredentialsModal from "./update_model_credentials_modal";-import ModelInfoEditForm, { type ModelEditSubmitValues, type TouchedPricingField } from "./ModelInfoEditForm";+import ModelInfoEditForm, {+  editableLitellmParams,+  type ModelEditSubmitValues,+  type TouchedPricingField,+} from "./ModelInfoEditForm"; import { Tag } from "./tag_management/types"; import { getDisplayModelName } from "./view_model/model_name_display"; import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog"; import KubernetesPodsCard from "./model_info/KubernetesPodsCard"; +// ModelInfo declares these as non-optional booleans, so a null for them fails the PATCH with a 422.+const NON_NULLABLE_MODEL_INFO_KEYS: readonly string[] = ["db_model", "member_auto_router"];+ interface ModelInfoViewProps {   modelId: string;   onClose: () => void;@@ -280,8 +288,13 @@ export default function ModelInfoView({         setIsSaving(false);         return;       }+      const removedExtraParams =+        values.litellm_extra_params === undefined+          ? []+          : removedJsonKeys(editableLitellmParams(localModelData?.litellm_params), parsedExtraParams);        let updatedLitellmParams: Record<string, any> = {+        ...Object.fromEntries(removedExtraParams.map((key) => [key, null])),         ...parsedExtraParams,         model: values.litellm_model_name,         api_base: values.api_base,@@ -347,8 +360,20 @@ export default function ModelInfoView({        // Parse the model_info from the form values       let updatedModelInfo;+      let removedModelInfoKeys: string[] = [];       try {-        updatedModelInfo = values.model_info ? JSON.parse(values.model_info) : modelData?.model_info;+        if (values.model_info) {+          const parsedModelInfo = JSON.parse(values.model_info);+          removedModelInfoKeys = removedJsonKeys(modelData?.model_info, parsedModelInfo).filter(+            (key) => !NON_NULLABLE_MODEL_INFO_KEYS.includes(key),+          );+          updatedModelInfo = {+            ...Object.fromEntries(removedModelInfoKeys.map((key) => [key, null])),+            ...parsedModelInfo,+          };+        } else {+          updatedModelInfo = modelData?.model_info;+        }         // Update access_groups from the form         if (values.model_access_group) {           updatedModelInfo = {@@ -375,7 +400,19 @@ export default function ModelInfoView({       // without this strip a masked value would be re-encrypted over the real secret.       // Credential rotation has its own dedicated path (UpdateModelCredentialsModal).       const safeLitellmParams = stripMaskedSecrets(updatedLitellmParams);-      const { litellm_credential_name: _sentCredential, ...localLitellmParams } = safeLitellmParams;+      const { litellm_credential_name: _sentCredential, ...sentLitellmParams } = safeLitellmParams;+      // Keys removed in the JSON editors are gone after the save, not stored as null.+      const localLitellmParams = withoutKeys(+        sentLitellmParams,+        removedExtraParams.filter((key) => sentLitellmParams[key] === null),+      );+      const sentModelInfo: Record<string, unknown> | undefined = updatedModelInfo;+      const localModelInfo =+        sentModelInfo &&+        withoutKeys(+          sentModelInfo,+          removedModelInfoKeys.filter((key) => sentModelInfo[key] === null),+        );        const updateData = {         model_name: values.model_name,@@ -393,7 +430,7 @@ export default function ModelInfoView({           selectedCredentialName === null             ? localLitellmParams             : { ...localLitellmParams, litellm_credential_name: selectedCredentialName },-        model_info: updatedModelInfo,+        model_info: localModelInfo,       };        setLocalModelData(updatedModelData);ui/litellm-dashboard/src/utils/jsonEditPatch.test.tsnew file mode 100644index 0000000000..9413bcc8e3@@ -0,0 +1,27 @@+import { describe, expect, it } from "vitest";++import { removedJsonKeys, withoutKeys } from "./jsonEditPatch";++describe("removedJsonKeys", () => {+  it("returns the shown keys that are missing from the edited JSON", () => {+    expect(+      removedJsonKeys({ model: "gpt-5", litellm_image_enabled: true, tpm: 10 }, { model: "gpt-5", tpm: 20 }),+    ).toEqual(["litellm_image_enabled"]);+  });++  it("keeps a key the user set to null in the edited JSON", () => {+    expect(removedJsonKeys({ model: "gpt-5", tpm: 10 }, { model: "gpt-5", tpm: null })).toEqual([]);+  });++  it("returns nothing when nothing was shown", () => {+    expect(removedJsonKeys(undefined, { model: "gpt-5" })).toEqual([]);+  });+});++describe("withoutKeys", () => {+  it("drops only the listed keys", () => {+    expect(withoutKeys({ model: "gpt-5", litellm_image_enabled: null, tpm: null }, ["litellm_image_enabled"])).toEqual(+      { model: "gpt-5", tpm: null },+    );+  });+});ui/litellm-dashboard/src/utils/jsonEditPatch.tsnew file mode 100644index 0000000000..38a2c89fa4@@ -0,0 +1,11 @@+// The model PATCH endpoint merges the submitted params into the stored ones, so a key+// the user deletes from a JSON editor would simply be omitted and survive the save.+// Callers send an explicit null for each key returned here, which the backend treats+// as "remove this key".+export const removedJsonKeys = (+  shown: Record<string, unknown> | null | undefined,+  edited: Record<string, unknown>,+): string[] => Object.keys(shown ?? {}).filter((key) => !Object.prototype.hasOwnProperty.call(edited, key));++export const withoutKeys = (params: Record<string, unknown>, keys: readonly string[]): Record<string, unknown> =>+  Object.fromEntries(Object.entries(params).filter(([key]) => !keys.includes(key))); 
Merged fix · PR #48456+571 −124
litellm/proxy/agent_endpoints/model_list_helpers.pyindex 4a88644bae5..447b4f52aaf 100644@@ -51,7 +51,7 @@ async def append_agents_to_model_group( async def append_agents_to_model_info(     models: list[dict],     user_api_key_dict: UserAPIKeyAuth,-) -> list[dict]:+) -> list[dict[str, object]]:     """     Append A2A agents to model info list for UI display. litellm/proxy/management_endpoints/model_management_endpoints.pyindex 11f616a5e18..e625ea6f9f2 100644@@ -145,6 +145,7 @@ from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.llms.bedrock import AwsSessionTag from litellm.types.proxy.management_endpoints.model_management_endpoints import (     AutoRouterClassifierDefaultPromptResponse,+    PatchModelRequest,     UpdateUsefulLinksRequest, ) from litellm.types.router import (@@ -160,6 +161,7 @@ from litellm.types.utils import (     OIDC_SECRET_REFERENCE_PREFIX,     echoed_cost_map_fields,     echoed_cost_map_pricing_fields,+    is_server_derived_pricing_key,     without_server_derived_pricing, ) from litellm.utils import get_utc_datetime@@ -995,6 +997,7 @@ def _ptu_zeroed_pricing( def _ptu_pricing_delta(     *,     stored_model_info: Mapping[str, object],+    stored_litellm_params: Mapping[str, object],     model_info: Mapping[str, object],     litellm_params: Mapping[str, object],     patch: updateDeployment,@@ -1014,6 +1017,24 @@ def _ptu_pricing_delta(     supplied: Final = patch.litellm_params.model_dump(exclude_none=True) if patch.litellm_params else _EMPTY_MODEL_INFO     zeroed: Final = _ptu_zeroed_pricing(model_info=model_info, litellm_params=litellm_params, supplied=supplied)     if zeroed:+        retains_ptu: Final = all(stored_model_info.get(field) is not None for field in _PTU_PRICED_PAIR)+        protected_pricing: Final = frozenset(+            field+            for field in _CUSTOM_PRICING_FIELDS+            if retains_ptu+            and (stored_litellm_params.get(field) is not None or stored_model_info.get(field) is not None)+        ).union(zeroed)+        removed_ptu_pricing: Final = tuple(+            field for field in _param_keys_to_remove(patch) if field in protected_pricing+        )+        if removed_ptu_pricing:+            raise HTTPException(+                status_code=400,+                detail=(+                    f"PTU billing requires {', '.join(removed_ptu_pricing)}, so these pricing parameters cannot be removed. "+                    "Keep them when enabling PTU, or clear ptu_count and cost_per_ptu_per_hour together to disable it."+                ),+            )         return zeroed, frozenset()     was_ptu: Final = any(stored_model_info.get(field) is not None for field in _PTU_PRICED_PAIR)     if not was_ptu or not _explicitly_cleared_ptu_fields(patch.model_info) & _PTU_PRICED_PAIR:@@ -1069,6 +1090,10 @@ def _loaded_catalog_entry(     return loaded_catalog().get(catalog_key, MappingProxyType({}))  +def _param_keys_to_remove(patch: updateDeployment) -> tuple[str, ...]:+    return patch.litellm_params_to_remove if isinstance(patch, PatchModelRequest) else ()++ def update_db_model(     db_model: Deployment,     updated_patch: updateDeployment,@@ -1077,7 +1102,8 @@ def update_db_model(     if updated_patch.model_info is not None:         _raise_if_ptu_cost_attribution_disabled(updated_patch.model_info.model_dump(exclude_none=True))     merged_model_name: Final = updated_patch.model_name or db_model.model_name-    merged_litellm_params: Final = db_model.litellm_params.model_dump(exclude_none=True)+    stored_litellm_params: Final = db_model.litellm_params.model_dump(exclude_none=True, exclude_unset=True)+    merged_litellm_params: Final = dict(stored_litellm_params)     stored_model_info: Final = _dump_without_none(db_model.model_info)     echoed_pricing: Final = echoed_cost_map_pricing_fields(stored_model_info)     merged_model_info: Final[dict[str, object]] = {@@ -1093,7 +1119,7 @@ def update_db_model(                 if k == "complexity_router_config"                 else encrypt_value_helper(v)             )-            for k, v in updated_patch.litellm_params.model_dump(exclude_none=True).items()+            for k, v in updated_patch.litellm_params.model_dump(exclude_none=True, exclude_unset=True).items()         }          merged_litellm_params.update(encrypted_params)@@ -1144,11 +1170,17 @@ def update_db_model(         for field in _explicitly_cleared_ptu_fields(updated_patch.model_info):             merged_model_info.pop(field, None) +    for field in _param_keys_to_remove(updated_patch):+        merged_litellm_params.pop(field, None)+        if is_server_derived_pricing_key(field):+            merged_model_info.pop(field, None)+     _validate_ptu_model_info(merged_model_info)     ptu_pricing, ptu_released = _ptu_pricing_delta(         stored_model_info=db_model.model_info.model_dump(exclude_none=True)         if db_model.model_info         else _EMPTY_MODEL_INFO,+        stored_litellm_params=stored_litellm_params,         model_info=merged_model_info,         litellm_params=merged_litellm_params,         patch=updated_patch,@@ -1255,7 +1287,7 @@ async def get_kubernetes_pods( ) async def patch_model(     model_id: str,  # Get model_id from path parameter-    patch_data: updateDeployment,  # Create a specific schema for PATCH operations+    patch_data: PatchModelRequest,     user_api_key_dict: UserAPIKeyAuth = Depends(user_api_key_auth), ):     """@@ -1319,18 +1351,34 @@ async def patch_model(                 param=None,             ) +        removals: Final = _param_keys_to_remove(patch_data)+        incoming_params: Final = (+            updateLiteLLMParams.model_validate(+                {+                    **(patch_data.litellm_params.model_dump(exclude_unset=True) if patch_data.litellm_params else {}),+                    **dict.fromkeys(removals),+                }+            )+            if removals+            else patch_data.litellm_params+        )+        remaining_params: Final = db_model.litellm_params.model_copy(update=dict.fromkeys(removals))         write_authorization: Final = await ModelManagementAuthChecks.can_user_make_model_call(             model_params=db_model,             user_api_key_dict=user_api_key_dict,             prisma_client=prisma_client,             premium_user=premium_user,-            incoming_params=submitted_litellm_params(patch_data.litellm_params),+            incoming_params=submitted_litellm_params(incoming_params),             member_operation="update",             incoming_model_params=patch_data,         )         member_write: Final = write_authorization if isinstance(write_authorization, MemberAutoRouterWrite) else None-        member_marker: Final = _member_auto_router_marker_for_update(-            incoming_params=patch_data.litellm_params, existing=db_model, member_write=member_write+        member_marker: Final = (+            False+            if db_model.model_info.member_auto_router and STRATEGY_ROUTER_PARAM_FIELDS.intersection(removals)+            else _member_auto_router_marker_for_update(+                incoming_params=incoming_params, existing=db_model, member_write=member_write+            )         )         marker_info: Final = (             ModelInfo(id=db_model.model_info.id)@@ -1367,27 +1415,26 @@ async def patch_model(             )          ModelManagementAuthChecks.can_user_attach_credential(-            litellm_params=patch_data.litellm_params,+            litellm_params=incoming_params,             user_api_key_dict=user_api_key_dict,             existing_litellm_params=db_model.litellm_params,             null_detaches=True,         )-        await _raise_on_invalid_credential_name(patch_data.litellm_params, db_model.litellm_params, prisma_client)+        await _raise_on_invalid_credential_name(incoming_params, db_model.litellm_params, prisma_client)          ModelManagementAuthChecks.can_user_set_aws_session_tags(-            litellm_params=patch_data.litellm_params,+            litellm_params=incoming_params,             user_api_key_dict=user_api_key_dict,             existing_litellm_params=db_model.litellm_params,+            null_detaches="aws_session_tags" in removals,         )          _raise_on_strategy_router_write_violation(-            incoming_params=patch_data.litellm_params,-            existing_params=db_model.litellm_params,+            incoming_params=incoming_params,+            existing_params=remaining_params,         ) -        effective_params: Final = _effective_complexity_router_params(-            patch_data.litellm_params, db_model.litellm_params-        )+        effective_params: Final = _effective_complexity_router_params(incoming_params, remaining_params)         requested_model_name: Final = patch_data.model_name         stored_model_name: str | None = None @@ -1818,20 +1865,20 @@ async def _update_team_model_in_db(         db_model=db_model,     ) -    # Ensure model_info exists and set team_public_model_name-    if patch_data.model_info is None:-        from litellm.types.router import ModelInfo--        patch_data.model_info = ModelInfo()-    patch_data.model_info.team_public_model_name = public_model_name-     # Check if team assignment is new or changed     db_team_id: Final = db_model.model_info.team_id if db_model.model_info else None     is_new_team_assignment: Final = db_team_id != patch_team_id      # Team rows keep their internal UUID-based model_name; the public name lives in model_info-    patch_data.model_name = f"model_name_{patch_team_id}_{uuid.uuid4()}" if is_new_team_assignment else None-    row: Final = await write_row(update_db_model(db_model=db_model, updated_patch=patch_data))+    team_patch: Final = patch_data.model_copy(+        update={+            "model_name": f"model_name_{patch_team_id}_{uuid.uuid4()}" if is_new_team_assignment else None,+            "model_info": (patch_data.model_info or ModelInfo()).model_copy(+                update={"team_public_model_name": public_model_name}+            ),+        }+    )+    row: Final = await write_row(update_db_model(db_model=db_model, updated_patch=team_patch))      if is_new_team_assignment:         await _setup_new_team_model_assignment(@@ -2228,14 +2275,16 @@ class ModelManagementAuthChecks:         litellm_params: GenericLiteLLMParams | None,         user_api_key_dict: UserAPIKeyAuth,         existing_litellm_params: GenericLiteLLMParams | None = None,+        *,+        null_detaches: bool = False,     ) -> Literal[True]:-        if litellm_params is None or litellm_params.aws_session_tags is None:+        if litellm_params is None or (litellm_params.aws_session_tags is None and not null_detaches):             return True         if user_api_key_dict.user_role == LitellmUserRoles.PROXY_ADMIN:             return True         existing_tags: Final = existing_litellm_params.aws_session_tags if existing_litellm_params is not None else None         if existing_tags is not None and _canonical_session_tags(existing_tags) == _canonical_session_tags(-            litellm_params.aws_session_tags+            litellm_params.aws_session_tags or ()         ):             return True         raise ProxyException(litellm/proxy/proxy_server.pyindex 129cd7e1589..ca0f8892b9d 100644@@ -16760,6 +16760,35 @@ async def _find_model_by_id(     return all_models, search_total_count  +async def _models_with_stored_param_keys(+    models: Sequence[Mapping[str, object]], model_id: str, prisma_client: PrismaClient+) -> Sequence[Mapping[str, object]]:+    visible_model: Final = next(+        (model for model in models if _with_get(model.get("model_info", {})).get("id") == model_id), None+    )+    if visible_model is None:+        return models+    stored: Final = await ModelRepository(WriterPinnedClient(prisma_client.db)).table.find_unique(+        where={"model_id": model_id}+    )+    if stored is None:+        return models+    raw_params: Final = _UNTYPED_VALUE.validate_python(stored.litellm_params)+    stored_params: Final = (+        _LITELLM_PARAMS_COPY.validate_json(raw_params)+        if isinstance(raw_params, str)+        else _LITELLM_PARAMS_COPY.validate_python(raw_params)+    )+    visible_params: Final = _LITELLM_PARAMS_COPY.validate_python(visible_model.get("litellm_params", {}))+    editor_model: Final = MappingProxyType(+        {+            **visible_model,+            "litellm_params": {key: value for key, value in visible_params.items() if key in stored_params},+        }+    )+    return tuple(editor_model if model is visible_model else model for model in models)++ @router.get(     "/v2/model/info",     tags=["model management"],@@ -16777,6 +16806,10 @@ async def model_info_v2(     size: int = Query(50, description="Page size", ge=1),     search: str | None = fastapi.Query(None, description="Search model names (case-insensitive partial match)"),     modelId: str | None = fastapi.Query(None, description="Search for a specific model by its unique ID"),+    use_stored_params: bool = fastapi.Query(+        False,+        description="With modelId, omit runtime-only litellm_params defaults from a DB-stored model's editor view.",+    ),     teamId: str | None = fastapi.Query(         None,         description="Filter models by team ID. Returns models with direct_access=True or teamId in access_via_team_ids",@@ -16828,6 +16861,7 @@ async def model_info_v2(         page / size: Pagination controls (defaults: page=1, size=50).         search: Case-insensitive partial match on model name or team public name.         modelId: Return a single deployment by LiteLLM model id.+        use_stored_params: With modelId, return only persisted litellm_params keys, retaining normal redaction.         teamId: Filter to models with direct access or team membership for this team id.         sortBy / sortOrder: Sort by model_name, created_at, updated_at, costs, or status.         blocked: Filter by routing status (false = active, true = paused).@@ -16864,6 +16898,9 @@ async def model_info_v2(     """     global llm_model_list, general_settings, user_config_file_path, proxy_config, llm_router +    if use_stored_params is True and not isinstance(modelId, str):+        raise HTTPException(status_code=400, detail="use_stored_params requires modelId")+     # Return empty data array when no models are configured (graceful handling for fresh installs)     if llm_router is None or not llm_router.model_list:         return {@@ -16999,6 +17036,14 @@ async def model_info_v2(     # Translate `model_name` to the public name for team-scoped rows.     all_models = [_translate_model_name_for_response(m) for m in all_models] +    if use_stored_params is True and isinstance(modelId, str):+        return _paginate_models_response(+            all_models=await _models_with_stored_param_keys(all_models, modelId, prisma_client),+            page=page,+            size=size,+            total_count=search_total_count,+            search=search,+        )     return _paginate_models_response(         all_models=all_models,         page=page,@@ -17512,7 +17557,7 @@ def _filter_v1_model_info_deployments(     return [model for model in all_models if _deployment_matches_allowed_model_names(model, allowed_model_names)]  -def _translate_model_name_for_response(model: dict) -> dict:+def _translate_model_name_for_response(model: dict) -> dict[str, object]:     """For team-scoped DB rows, replace `model_name` with the public name     in `model_info.team_public_model_name` before returning. The DB column     and the in-memory router index keep the internal mangled namelitellm/types/proxy/management_endpoints/model_management_endpoints.pyindex c012f872280..f032bb20c2a 100644@@ -1,11 +1,37 @@ from collections.abc import Mapping from datetime import datetime+from typing import Annotated, Final -from pydantic import ConfigDict, Field+from pydantic import ConfigDict, Field, model_validator  from litellm.types.llms.base import LiteLLMBaseModel -from ...router import ModelGroupInfo+from ...router import ModelGroupInfo, updateDeployment+++class PatchModelRequest(updateDeployment):+    litellm_params_to_remove: tuple[Annotated[str, Field(min_length=1)], ...] = Field(+        default=(),+        description=(+            "Top-level litellm_params keys to delete. Omitted parameters remain unchanged. "+            "The required model key and keys also supplied in litellm_params cannot be removed. "+            "Removing an absent key or repeating a key is a no-op."+        ),+    )++    model_config = ConfigDict(frozen=True, protected_namespaces=())++    @model_validator(mode="after")+    def validate_param_removals(self) -> "PatchModelRequest":+        removals: Final = frozenset(self.litellm_params_to_remove)+        if "model" in removals:+            raise ValueError("The required litellm_params.model cannot be removed")+        conflicts: Final[frozenset[str]] = (+            removals.intersection(self.litellm_params.model_fields_set) if self.litellm_params else frozenset()+        )+        if conflicts:+            raise ValueError(f"Cannot set and remove the same litellm_params keys: {', '.join(sorted(conflicts))}")+        return self   class ModelGroupInfoProxy(ModelGroupInfo):tests/unit/proxy/management_endpoints/test_model_management_endpoints.pyindex a718426eea6..9ff2a6de9dd 100644@@ -3672,6 +3672,23 @@ class TestUpdateDBModelKeepsLegacyDropParams:         assert decrypt_value_helper(value=stored["drop_params"], key="drop_params") == "true"  +@pytest.mark.parametrize(+    "payload",+    [+        {"litellm_params_to_remove": ["model"]},+        {"litellm_params_to_remove": ["temperature"], "litellm_params": {"temperature": 0}},+        {"litellm_params_to_remove": ["temperature"], "litellm_params": {"temperature": None}},+    ],+)+def test_model_param_removal_rejects_required_and_conflicting_fields(payload: Mapping[str, object]) -> None:+    from pydantic import ValidationError++    from litellm.types.proxy.management_endpoints.model_management_endpoints import PatchModelRequest++    with pytest.raises(ValidationError):+        PatchModelRequest.model_validate(payload)++ def _build_db_model_with_pricing():     """Wildcard deployment with custom pricing in litellm_params; Deployment.__init__     mirrors SPECIAL_MODEL_INFO_PARAMS into model_info, so both blobs hold the rate."""@@ -7843,6 +7860,55 @@ class TestTeamMemberAutoRouterWrites:             "jev_classifier_config" if legacy else "opensource_classifier_config": classifier,         } +    @pytest.mark.asyncio+    @pytest.mark.parametrize(+        "stored_params,removed,denied_param",+        [+            ({"litellm_credential_name": "stored-credential"}, "litellm_credential_name", "litellm_credential_name"),+            ({"aws_session_tags": [{"Key": "scope", "Value": "restricted"}]}, "aws_session_tags", "aws_session_tags"),+            ({"api_key": "oidc/file//var/run/token", "api_base": "https://provider.test"}, "api_base", "api_key"),+            ({"anthropic_issuer_url": "https://issuer.test"}, "anthropic_issuer_url", "anthropic_issuer_url"),+        ],+    )+    async def test_team_admin_cannot_remove_admin_owned_model_params(+        self, stored_params: Mapping[str, object], removed: str, denied_param: str+    ) -> None:+        from litellm.types.proxy.management_endpoints.model_management_endpoints import PatchModelRequest++        row: Final = self._row().model_copy(+            update={"litellm_params": {"model": "openai/test-model", **stored_params}}+        )+        team: Final = self._team().model_copy(update={"members_with_roles": [Member(user_id="owner", role="admin")]})+        database: Final = self._database(team, row)+        database.db.litellm_credentialstable.find_unique = AsyncMock(return_value=None)+        actor: Final = UserAPIKeyAuth(user_id="owner", user_role=LitellmUserRoles.INTERNAL_USER)++        with self._environment(database, row), pytest.raises(ProxyException) as denied:+            await patch_model(row.model_id, PatchModelRequest(litellm_params_to_remove=(removed,)), actor)++        assert denied.value.code == "403"+        assert denied.value.param == denied_param+        database.db.litellm_proxymodeltable.update.assert_not_awaited()++    @pytest.mark.asyncio+    async def test_param_removal_cannot_leave_a_strategy_router_without_required_configuration(self) -> None:+        from litellm.types.proxy.management_endpoints.model_management_endpoints import PatchModelRequest++        row: Final = self._row()+        database: Final = self._database(self._team(), row)+        actor: Final = UserAPIKeyAuth(user_id="admin", user_role=LitellmUserRoles.PROXY_ADMIN)++        with self._environment(database, row), pytest.raises(ProxyException) as denied:+            await patch_model(+                row.model_id,+                PatchModelRequest(litellm_params_to_remove=("complexity_router_config", "complexity_router_default_model")),+                actor,+            )++        assert denied.value.code == "400"+        assert "requires" in denied.value.message+        database.db.litellm_proxymodeltable.update.assert_not_awaited()+     @pytest.mark.asyncio     @pytest.mark.parametrize("team_id", [None, "member-team"])     @pytest.mark.parametrize(tests/unit/proxy/management_endpoints/test_ptu_model_settings.pyindex a319797a618..efb84ee8f3a 100644@@ -40,6 +40,7 @@ from litellm.proxy.management_endpoints.model_management_endpoints import ( from litellm.proxy.spend_tracking.ptu_feature_flag import PTU_COST_ATTRIBUTION_ENV_VAR from litellm.repositories.chunked_in import IN_LIST_CHUNK_SIZE from litellm.router import Router+from litellm.types.proxy.management_endpoints.model_management_endpoints import PatchModelRequest from litellm.types.router import (     SPECIAL_MODEL_INFO_PARAMS,     Deployment,@@ -1205,6 +1206,80 @@ class TestPtuDeploymentsAreNotBilledPerToken:         for blob in ("model_info", "litellm_params"):             assert json.loads(written[blob])["input_cost_per_token"] == 0, blob +    @pytest.mark.parametrize("field,activating", [+        ("input_cost_per_token", False), ("cache_read_input_token_cost", False),+        ("input_cost_per_second", False), ("tiered_pricing", False), ("search_context_cost_per_query", False),+        ("input_cost_per_token", True), ("cache_read_input_token_cost", True),+        ("tiered_pricing", True), ("search_context_cost_per_query", True),+    ])+    def test_removing_ptu_managed_pricing_is_rejected(self, field: str, activating: bool) -> None:+        original: Final = _deployment_without_ptu() if activating else _deployment_with_stored_ptu()+        configured: Final = original.model_copy(update={+            "litellm_params": original.litellm_params.model_copy(update={"input_cost_per_second": 0.0}),+        })+        with pytest.raises(HTTPException) as exc:+            update_db_model(+                db_model=configured if activating else _ptu_priced_deployment(configured),+                updated_patch=PatchModelRequest(+                    litellm_params_to_remove=(field,),+                    model_info=_deployment_with_stored_ptu().model_info if activating else None,+                ),+            )+        assert exc.value.status_code == 400+        assert field in exc.value.detail+        assert "ptu_count and cost_per_ptu_per_hour" in exc.value.detail++    @pytest.mark.parametrize("mode,field", [+        ("extra", "temperature"), ("disabled", "input_cost_per_token"),+        ("disabled", "input_cost_per_second"), ("cleared", "input_cost_per_token"),+        ("cleared", "input_cost_per_second"), ("activating", "input_cost_per_second"),+        ("ordinary", "input_cost_per_second"),+        ("ordinary", "input_cost_per_token_above_123k_tokens"),+        ("ordinary", "regional_endpoint_uplift_multiplier"),+    ])+    def test_allowed_ptu_removals_stay_absent_after_another_save(+        self, monkeypatch: pytest.MonkeyPatch, mode: str, field: str+    ) -> None:+        original: Final = (+            _deployment_without_ptu() if mode in ("activating", "ordinary")+            else _ptu_priced_deployment(_deployment_with_stored_ptu())+        )+        rate: Final = 0.5 if mode in ("activating", "ordinary") else 0.0+        price_field: Final = field if mode == "ordinary" else "input_cost_per_second"+        configured: Final = original.model_copy(update={+            "litellm_params": original.litellm_params.model_copy(update={+                "temperature": 0.4, price_field: rate,+            }),+            "model_info": original.model_info.model_copy(update={price_field: rate}),+        })+        if mode == "disabled":+            monkeypatch.delenv(PTU_COST_ATTRIBUTION_ENV_VAR)+        incoming_info: Final = (+            ModelInfo(ptu_count=None, cost_per_ptu_per_hour=None) if mode == "cleared"+            else _deployment_with_stored_ptu().model_info if mode == "activating" else ModelInfo()+        )+        patch: Final = PatchModelRequest(+            litellm_params_to_remove=(field,),+            model_info=incoming_info.model_copy(update={price_field: rate}),+        )+        written: Final = update_db_model(db_model=configured, updated_patch=patch)+        assert json.loads(written["model_info"]).get("ptu_count") == (+            None if mode in ("cleared", "ordinary") else 15+        )+        reloaded: Final = Deployment.model_validate({+            "model_name": written["model_name"], "litellm_params": json.loads(written["litellm_params"]),+            "model_info": json.loads(written["model_info"]),+        })+        saved_again: Final = update_db_model(+            db_model=reloaded, updated_patch=updateDeployment(+                model_name="renamed", model_info=ModelInfo.model_validate({price_field: rate}),+            )+        )+        retried: Final = update_db_model(db_model=reloaded, updated_patch=patch)+        for result in (written, saved_again, retried):+            assert field not in json.loads(result["litellm_params"])+            assert field not in json.loads(result["model_info"])+     def test_a_patch_pricing_a_ptu_deployment_is_refused(self):         with pytest.raises(HTTPException) as exc:             update_db_model(tests/unit/proxy/proxy_server/test_routes_model_info.pyindex 2c0e0944edb..9993361d930 100644@@ -11,6 +11,7 @@ from __future__ import annotations  import asyncio import copy+import json from collections.abc import Callable from contextlib import AbstractContextManager from typing import Final@@ -24,6 +25,7 @@ import litellm from litellm.caching.llm_caching_handler import LLMClientCache from litellm.llms.custom_httpx.http_handler import AsyncHTTPHandler from litellm.proxy import proxy_server+from litellm.proxy._types import LiteLLM_ProxyModelTable from litellm.utils import _invalidate_model_cost_lowercase_map  from .conftest import normalize  # type: ignore[import-not-found]@@ -206,6 +208,80 @@ def test_v2_model_info_invalid_page_returns_422(client, auth_as, empty_router):     assert "detail" in response.json()  +@pytest.mark.parametrize("encoded", [False, True])+def test_deleted_model_params_stay_absent_after_reload_and_another_save(+    client: TestClient,+    auth_as: Callable[[], AbstractContextManager[object]],+    monkeypatch: pytest.MonkeyPatch,+    mock_prisma: MagicMock,+    encoded: bool,+) -> None:+    from litellm.proxy.management_endpoints.model_management_endpoints import update_db_model+    from litellm.types.proxy.management_endpoints.model_management_endpoints import PatchModelRequest+    from litellm.types.router import Deployment, LiteLLM_Params, ModelInfo, updateDeployment, updateLiteLLMParams++    configured: Final = {+        "model": "openai/test-model", "api_key": "synthetic-runtime-secret",+        "use_litellm_proxy": True, "use_in_pass_through": True, "use_chat_completions_api": False,+        "litellm_image_enabled": True, "timeout": 30, "input_cost_per_token": 0.003,+        "team_id": "param-only-team", "temperature": 0, "metadata": {},+    }+    original: Final = Deployment(+        model_name="editor-model", litellm_params=LiteLLM_Params.model_validate(configured),+        model_info=ModelInfo(id="editor-model", team_id="owner-team", access_groups=["retained-group"]),+    )+    removals: Final = ("litellm_image_enabled", "use_litellm_proxy", "input_cost_per_token", "team_id")+    deleted: Final = update_db_model(+        db_model=original,+        updated_patch=PatchModelRequest(+            litellm_params=updateLiteLLMParams(max_retries=0), litellm_params_to_remove=removals,+            model_info=ModelInfo(id="editor-model", input_cost_per_token=0.003),+        ),+    )+    saved_params: Final = json.loads(deleted["litellm_params"])+    saved_info: Final = json.loads(deleted["model_info"])+    assert saved_params == {**{key: value for key, value in configured.items() if key not in removals}, "max_retries": 0}+    assert "input_cost_per_token" not in saved_info+    assert saved_info["team_id"] == "owner-team"+    assert saved_info["access_groups"] == ["retained-group"]+    reloaded: Final = Deployment.model_validate(+        {"model_name": original.model_name, "litellm_params": saved_params, "model_info": saved_info}+    )+    router: Final = litellm.Router(model_list=[{+        "model_name": "editor-model", "litellm_params": saved_params,+        "model_info": {"id": "editor-model", "db_model": True},+    }])+    stored_params: Final = {**saved_params, "api_key": "synthetic-stored-secret"}+    mock_prisma.db.litellm_proxymodeltable.find_unique.return_value = LiteLLM_ProxyModelTable(+        model_id="editor-model", model_name="editor-model",+        litellm_params=json.dumps(stored_params) if encoded else stored_params,+        model_info={"id": "editor-model"},+    )+    monkeypatch.setattr(proxy_server, "llm_router", router)+    monkeypatch.setattr(proxy_server, "prisma_client", mock_prisma)++    with auth_as():+        normal: Final = client.get("/v2/model/info", params={"modelId": "editor-model"})+        editor: Final = client.get("/v2/model/info", params={"modelId": "editor-model", "use_stored_params": "true"})++    assert normal.status_code == editor.status_code == 200, editor.text+    normal_params: Final = normal.json()["data"][0]["litellm_params"]+    assert "use_litellm_proxy" in normal_params+    assert editor.json()["data"][0]["litellm_params"] == {+        key: value for key, value in normal_params.items() if key in saved_params+    }+    assert editor.json()["data"][0]["litellm_params"]["use_chat_completions_api"] is False+    assert "synthetic-runtime-secret" not in editor.text+    assert "synthetic-stored-secret" not in editor.text+    assert "use_litellm_proxy" in router.model_list[0]["litellm_params"]++    saved_again: Final = update_db_model(+        db_model=reloaded, updated_patch=updateDeployment(litellm_params=updateLiteLLMParams(rpm=10, timeout=None))+    )+    persisted: Final = json.loads(saved_again["litellm_params"])+    assert persisted == {**saved_params, "rpm": 10}++ def test_v2_model_info_in_openapi_schema():     """``GET /v2/model/info`` is published in the proxy OpenAPI/Swagger spec."""     from litellm.proxy.proxy_server import get_openapi_schemaui/litellm-dashboard/eslint-suppressions.jsonindex 724c49eb3b3..c8231b90bfd 100644@@ -1737,7 +1737,7 @@       "count": 1     },     "prefer-const": {-      "count": 5+      "count": 3     },     "react-hooks/set-state-in-effect": {       "count": 1ui/litellm-dashboard/src/app/(dashboard)/hooks/models/useModels.test.tsindex e9df939f220..76db710f5ba 100644@@ -125,10 +125,42 @@ describe("useModelsInfo", () => {       undefined,       false,       undefined,+      {},     );     expect(modelInfoCall).toHaveBeenCalledTimes(1);   }); +  it("keeps saved model parameters separate from hydrated parameters in the query cache", async () => {+    vi.mocked(modelInfoCall).mockImplementation(async (...args) => ({+      ...mockPaginatedModelInfoResponse,+      data: [{ litellm_params: args[15]?.useStoredParams ? {} : { litellm_image_enabled: false } }],+    }));+    const { result } = renderHook(+      () => ({+        hydrated: useModelsInfo(1, 50, undefined, "model-1"),+        stored: useModelsInfo(+          1,+          50,+          undefined,+          "model-1",+          undefined,+          undefined,+          undefined,+          false,+          undefined,+          undefined,+          false,+          undefined,+          { useStoredParams: true },+        ),+      }),+      { wrapper },+    );+    await waitFor(() => expect(result.current.stored.isSuccess && result.current.hydrated.isSuccess).toBe(true));+    expect(result.current.stored.data?.data[0].litellm_params).toEqual({});+    expect(result.current.hydrated.data?.data[0].litellm_params).toEqual({ litellm_image_enabled: false });+  });+   it("should use custom page and size parameters", async () => {     (modelInfoCall as any).mockResolvedValue(mockPaginatedModelInfoResponse); @@ -156,6 +188,7 @@ describe("useModelsInfo", () => {       undefined,       false,       undefined,+      {},     );   }); ui/litellm-dashboard/src/app/(dashboard)/hooks/models/useModels.tsindex 744db87ad11..f9304bab0d2 100644@@ -45,6 +45,7 @@ export const useModelsInfo = (   accessGroup?: string,   wildcardOnly: boolean = false,   blocked?: boolean,+  options: { useStoredParams?: boolean } = {}, ) => {   const { accessToken, userId, userRole } = useAuthorized();   return useQuery<PaginatedModelInfoResponse>({@@ -57,6 +58,7 @@ export const useModelsInfo = (         ...(search && { search }),         ...(modelName && { modelName }),         ...(modelId && { modelId }),+        useStoredParams: Boolean(options.useStoredParams),         ...(teamId && { teamId }),         ...(sortBy && { sortBy }),         ...(sortOrder && { sortOrder }),@@ -86,6 +88,7 @@ export const useModelsInfo = (         accessGroup,         wildcardOnly,         blocked,+        options,       ),     enabled: Boolean(accessToken && userId && userRole),   });ui/litellm-dashboard/src/components/ModelInfoEditForm.tsxindex 70fe23202bf..085334567ed 100644@@ -34,7 +34,7 @@ import type { Tag } from "./tag_management/types"; import { ModelTeamSelect } from "./view_model/ModelTeamSelect"; import VectorStoreSelector from "./vector_store_management/VectorStoreSelector"; import { formatPtuUtcDisplay, utcIsoToPickerValue } from "../utils/ptuDatetime";-import { isMaskedSecret } from "../utils/maskedSecretUtils";+import { editableModelExtraParams, parseModelExtraParams } from "../utils/modelEditParams"; import {   MAX_COST_PER_PTU_PER_HOUR,   MAX_PTU_COUNT,@@ -127,22 +127,13 @@ const modelEditShape = {  type ModelEditFieldName = keyof typeof modelEditShape; -const isJson = (value: string): boolean => {-  try {-    JSON.parse(value);-    return true;-  } catch {-    return false;-  }-};- const buildSchema = (ptuEnabled: boolean, isFieldTouched: (field: TouchedPricingField) => boolean) =>   z.object(modelEditShape).superRefine((values, ctx) => {     const reject = (path: ModelEditFieldName, message: string) =>       ctx.addIssue({ code: "custom", path: [path], message }); -    if (values.litellm_extra_params && !isJson(values.litellm_extra_params)) {-      reject("litellm_extra_params", "Please enter valid JSON");+    if (parseModelExtraParams(values.litellm_extra_params) === null) {+      reject("litellm_extra_params", "Please enter a valid JSON object");     }      // antd validates only mounted fields, and the PTU block does not render when the flag is off.@@ -245,15 +236,7 @@ export const toModelEditFormValues = (localModelData: any, isWildcardModel: bool   // antd never mounted this field for a non-wildcard model, so the key must be absent, not null.   ...(isWildcardModel ? { health_check_model: localModelData.model_info?.health_check_model } : {}),   litellm_credential_name: localModelData.litellm_params?.litellm_credential_name ?? null,-  litellm_extra_params: JSON.stringify(-    Object.fromEntries(-      Object.entries(localModelData.litellm_params || {}).filter(-        ([key, value]) => key !== "litellm_credential_name" && !isMaskedSecret(value),-      ),-    ),-    null,-    2,-  ),+  litellm_extra_params: JSON.stringify(editableModelExtraParams(localModelData.litellm_params ?? {}), null, 2),   team_id: localModelData.model_info?.team_id ?? undefined, }); @@ -775,7 +758,7 @@ const ModelInfoEditForm: React.FC<ModelInfoEditFormProps> = ({               <FieldLabel>                 LiteLLM Params                 <DocsHint-                  text="Optional litellm params used for making a litellm.completion() call. Some params are automatically added by LiteLLM."+                  text="Additional parameters for model requests. Settings with dedicated fields above are edited there. Remove a key here to delete its saved value."                   href="https://docs.litellm.ai/docs/completion/input"                 />               </FieldLabel>@@ -784,9 +767,10 @@ const ModelInfoEditForm: React.FC<ModelInfoEditFormProps> = ({                   {({ value, ...control }) => (                     <Textarea                       {...control}+                      aria-label="LiteLLM Params"                       value={(value as string) ?? ""}                       rows={4}-                      placeholder={'{\n  "rpm": 100,\n  "timeout": 0,\n  "stream_timeout": 0\n}'}+                      placeholder={'{\n  "drop_params": true\n}'}                     />                   )}                 </FormField>ui/litellm-dashboard/src/components/model_info_view.integration.test.tsxsimilarity index 95%rename from ui/litellm-dashboard/src/components/model_info_view.test.tsxrename to ui/litellm-dashboard/src/components/model_info_view.integration.test.tsxindex 2e85fab5b76..f93e01eb583 100644@@ -751,16 +751,7 @@ describe("ModelInfoView", () => {      await user.click(screen.getByRole("button", { name: /edit settings/i })); -    const litellmParamsInput = screen-      .getAllByRole("textbox")-      .find(-        (input) =>-          input.tagName === "TEXTAREA" && (input as HTMLTextAreaElement).value.includes('"custom_llm_provider"'),-      );-    expect(litellmParamsInput).toBeDefined();-    if (!litellmParamsInput) {-      return;-    }+    const litellmParamsInput = screen.getByRole("textbox", { name: "LiteLLM Params" });     expect((litellmParamsInput as HTMLTextAreaElement).value).not.toContain("litellm_credential_name");     await user.clear(litellmParamsInput);     await user.paste(`{"litellm_credential_name":"from-json","timeout":42}`);@@ -776,6 +767,61 @@ describe("ModelInfoView", () => {     expect(updatePayload.litellm_params.litellm_credential_name).not.toBe("from-json");   }); +  it("removes JSON params without losing hidden settings and keeps them absent after reload and another save", async () => {+    const storedModel = {+      ...defaultModelData,+      litellm_params: {+        ...defaultModelData.litellm_params,+        api_key: "sk-****secret",+        input_cost_per_token: 0.00001,+        litellm_image_enabled: true,+      },+    };+    const retained = { drop_params: false, temperature: 0, allowed_openai_params: [] };+    mockUseModelsInfo.mockReturnValue({ data: { data: [storedModel] }, isLoading: false });+    const user = userEvent.setup();+    const { unmount } = render(<ModelInfoView {...DEFAULT_ADMIN_PROPS} />, { wrapper });+    await user.click(await screen.findByRole("button", { name: /edit settings/i }));+    fireEvent.change(screen.getByRole("textbox", { name: "LiteLLM Params" }), {+      target: { value: JSON.stringify(retained) },+    });+    await user.click(screen.getByRole("button", { name: /save changes/i }));+    await waitFor(() => expect(mockModelPatchUpdateCall).toHaveBeenCalledOnce());++    const payload = mockModelPatchUpdateCall.mock.calls[0][1];+    expect(payload.litellm_params_to_remove).toEqual(["litellm_image_enabled"]);+    expect(payload.litellm_params).toMatchObject(retained);+    expect(payload.litellm_params).not.toHaveProperty("api_key");+    const saved = DEFAULT_ADMIN_PROPS.onModelUpdate.mock.calls[0][0];+    expect(saved.litellm_params).toMatchObject({ api_key: "sk-****secret", input_cost_per_token: 0.00001 });+    expect(saved.litellm_params).not.toHaveProperty("litellm_image_enabled");++    unmount();+    mockUseModelsInfo.mockReturnValue({ data: { data: [saved] }, isLoading: false });+    render(<ModelInfoView {...DEFAULT_ADMIN_PROPS} />, { wrapper });+    await user.click(await screen.findByRole("button", { name: /edit settings/i }));+    expect(JSON.parse((screen.getByRole("textbox", { name: "LiteLLM Params" }) as HTMLTextAreaElement).value)).toEqual(+      retained,+    );+    await user.click(screen.getByRole("button", { name: /save changes/i }));+    await waitFor(() => expect(mockModelPatchUpdateCall).toHaveBeenCalledTimes(2));+    expect(mockModelPatchUpdateCall.mock.calls[1][1].litellm_params).not.toHaveProperty("litellm_image_enabled");+    expect(mockModelPatchUpdateCall.mock.calls[1][1]).not.toHaveProperty("litellm_params_to_remove");+  });++  it("resets form values when the selected model changes without unmounting the detail view", async () => {+    const { rerender } = render(<ModelInfoView {...DEFAULT_ADMIN_PROPS} />, { wrapper });+    fireEvent.click(await screen.findByRole("button", { name: /edit settings/i }));+    const otherModel = {+      ...defaultModelData,+      litellm_params: { model: "openai/other-model" },+      model_info: { ...defaultModelData.model_info, id: "456" },+    };+    mockUseModelsInfo.mockReturnValue({ data: { data: [otherModel] }, isLoading: false });+    rerender(<ModelInfoView {...DEFAULT_ADMIN_PROPS} modelId="456" />);+    expect(screen.getByPlaceholderText("Enter LiteLLM model name")).toHaveValue("openai/other-model");+  });+   it("should not include vector_store_ids in update payload when model has none", async () => {     // Regression: editing a model without vector stores used to inject     // vector_store_ids: [] into litellm_params, which then propagated to@@ -1090,25 +1136,20 @@ describe("ModelInfoView", () => {     });   }); -  it("blocks the save when the LiteLLM Params box does not hold valid JSON", async () => {+  it.each(["{not json", "null", "[]", '"value"'])("rejects non-object params %s", async (value) => {     const user = userEvent.setup();     render(<ModelInfoView {...DEFAULT_ADMIN_PROPS} />, { wrapper });      expect(await screen.findByRole("button", { name: /edit settings/i })).toBeInTheDocument();     await user.click(screen.getByRole("button", { name: /edit settings/i })); -    const extraParams = screen-      .getAllByRole("textbox")-      .find(-        (input) =>-          input.tagName === "TEXTAREA" && (input as HTMLTextAreaElement).value.includes('"custom_llm_provider"'),-      ) as HTMLTextAreaElement;+    const extraParams = screen.getByRole("textbox", { name: "LiteLLM Params" });     await user.clear(extraParams);-    await user.paste("{not json");+    await user.paste(value);      await user.click(screen.getByRole("button", { name: /save changes/i })); -    expect(await screen.findByText("Please enter valid JSON")).toBeInTheDocument();+    expect(await screen.findByText("Please enter a valid JSON object")).toBeInTheDocument();     expect(mockModelPatchUpdateCall).not.toHaveBeenCalled();   }); @@ -1830,7 +1871,10 @@ describe("ModelInfoView", () => {         const payload = await save(user);          expect(payload.litellm_params.cache_creation_input_token_cost_above_1hr).toBeNull();-        expect(payload.litellm_params.cache_creation_input_token_cost).toBe(0.00000375);+        expect(payload.litellm_params).not.toHaveProperty("cache_creation_input_token_cost");+        expect(DEFAULT_ADMIN_PROPS.onModelUpdate.mock.calls[0][0].litellm_params.cache_creation_input_token_cost).toBe(+          0.00000375,+        );       });     }); @@ -1963,12 +2007,7 @@ describe("ModelInfoView", () => {       const user = userEvent.setup();       await enterEditMode(user); -      const extraParams = screen-        .getAllByRole("textbox")-        .find(-          (input) =>-            input.tagName === "TEXTAREA" && (input as HTMLTextAreaElement).value.includes('"custom_llm_provider"'),-        ) as HTMLTextAreaElement;+      const extraParams = screen.getByRole("textbox", { name: "LiteLLM Params" });       await user.clear(extraParams);       await user.paste('{"drop_params":true}'); ui/litellm-dashboard/src/components/model_info_view.tsxindex 74c1e498594..f1ff4534941 100644@@ -13,6 +13,7 @@ import { ArrowLeft, CheckIcon, CopyIcon, Info } from "lucide-react"; import { useEffect, useMemo, useState } from "react"; import { copyToClipboard as utilCopyToClipboard } from "../utils/dataUtils"; import { stripMaskedSecrets } from "../utils/maskedSecretUtils";+import { editableModelExtraParams, parseModelExtraParams } from "../utils/modelEditParams"; import { truncateString } from "../utils/textUtils"; import AutoRouterConnectionTest from "./add_model/auto_router_connection_test"; import { buildSavedJevConnectionTestRequest } from "./add_model/build_auto_router_routing_test_request";@@ -38,7 +39,6 @@ import {   credentialListCall,   getGuardrailsList,   modelDeleteCall,-  modelInfoV1Call,   modelPatchUpdateCall,   tagListCall,   testConnectionRequest,@@ -93,7 +93,21 @@ export default function ModelInfoView({   const [credentialsList, setCredentialsList] = useState<CredentialItem[]>([]);    // Fetch model data using hook-  const { data: rawModelDataResponse, isLoading: isLoadingModel } = useModelsInfo(1, 50, undefined, modelId);+  const { data: rawModelDataResponse, isLoading: isLoadingModel } = useModelsInfo(+    1,+    50,+    undefined,+    modelId,+    undefined,+    undefined,+    undefined,+    false,+    undefined,+    undefined,+    false,+    undefined,+    { useStoredParams: true },+  );   const { data: modelCostMapData } = useModelCostMap();   const { data: modelHubData } = useModelHub();   const { data: teams } = useTeams();@@ -150,10 +164,11 @@ export default function ModelInfoView({   const usingExistingCredential =     modelData?.litellm_params?.litellm_credential_name != null &&     modelData?.litellm_params?.litellm_credential_name != undefined;+  const hasChangedModelId = localModelData?.model_info?.id !== modelData?.model_info?.id;    // Initialize localModelData from modelData when available   useEffect(() => {-    if (modelData && !localModelData) {+    if (modelData && (!localModelData || hasChangedModelId)) {       let processedModelData = modelData;       if (!processedModelData.litellm_model_name) {         processedModelData = {@@ -168,11 +183,9 @@ export default function ModelInfoView({       setLocalModelData(processedModelData);        // Check if cache control is enabled-      if (processedModelData?.litellm_params?.cache_control_injection_points) {-        setShowCacheControl(true);-      }+      setShowCacheControl(Boolean(processedModelData?.litellm_params?.cache_control_injection_points));     }-  }, [modelData, localModelData]);+  }, [modelData, localModelData, hasChangedModelId]);    useEffect(() => {     const getExistingCredential = async () => {@@ -186,30 +199,6 @@ export default function ModelInfoView({       });     }; -    const getModelInfo = async () => {-      if (!accessToken) return;-      // Only fetch if we don't have modelData yet-      if (modelData) return;-      let modelInfoResponse = await modelInfoV1Call(accessToken, modelId);-      let specificModelData = modelInfoResponse.data[0];-      if (specificModelData && !specificModelData.litellm_model_name) {-        specificModelData = {-          ...specificModelData,-          litellm_model_name:-            specificModelData?.litellm_params?.litellm_model_name ??-            specificModelData?.litellm_params?.model ??-            specificModelData?.model_info?.key ??-            null,-        };-      }-      setLocalModelData(specificModelData);--      // Check if cache control is enabled-      if (specificModelData?.litellm_params?.cache_control_injection_points) {-        setShowCacheControl(true);-      }-    };-     const fetchGuardrails = async () => {       if (!accessToken) return;       try {@@ -242,7 +231,6 @@ export default function ModelInfoView({     };      getExistingCredential();-    getModelInfo();     fetchGuardrails();     fetchTags();     fetchCredentials();@@ -270,19 +258,14 @@ export default function ModelInfoView({       if (!accessToken) return;       setIsSaving(true); -      // Parse LiteLLM extra params from JSON text area-      let parsedExtraParams: Record<string, any> = {};-      try {-        parsedExtraParams = values.litellm_extra_params ? JSON.parse(values.litellm_extra_params) : {};-        delete parsedExtraParams.litellm_credential_name;-      } catch (e) {-        toast.fromError("Invalid JSON in LiteLLM Params");-        setIsSaving(false);+      const parsedExtraParams = parseModelExtraParams(values.litellm_extra_params);+      if (parsedExtraParams === null) {+        toast.fromError("LiteLLM Params must be a valid JSON object");         return;       } -      let updatedLitellmParams: Record<string, any> = {-        ...parsedExtraParams,+      const updatedLitellmParams: Record<string, unknown> = {+        ...editableModelExtraParams(parsedExtraParams),         model: values.litellm_model_name,         api_base: values.api_base,         custom_llm_provider: values.custom_llm_provider,@@ -370,16 +353,24 @@ export default function ModelInfoView({         return;       } +      const paramsToRemove = Object.keys(editableModelExtraParams(localModelData?.litellm_params ?? {})).filter(+        (key) => !Object.prototype.hasOwnProperty.call(parsedExtraParams, key),+      );       // Final guard: never PATCH a redacted secret. The /model/info snapshot that-      // seeds this form masks secrets, and any save re-sends the whole params blob;+      // seeds this form masks secrets;       // without this strip a masked value would be re-encrypted over the real secret.       // Credential rotation has its own dedicated path (UpdateModelCredentialsModal).       const safeLitellmParams = stripMaskedSecrets(updatedLitellmParams);-      const { litellm_credential_name: _sentCredential, ...localLitellmParams } = safeLitellmParams;+      const localLitellmParams = Object.fromEntries(+        Object.entries({ ...localModelData?.litellm_params, ...safeLitellmParams }).filter(+          ([key]) => key !== "litellm_credential_name" && !paramsToRemove.includes(key),+        ),+      );        const updateData = {         model_name: values.model_name,         litellm_params: safeLitellmParams,+        ...(paramsToRemove.length > 0 && { litellm_params_to_remove: paramsToRemove }),         model_info: updatedModelInfo,       }; @@ -712,6 +703,7 @@ export default function ModelInfoView({               </div>               {localModelData ? (                 <ModelInfoEditForm+                  key={localModelData.model_info?.id}                   localModelData={localModelData}                   modelData={modelData}                   teamAlias={aliasForTeam(localModelData.model_info?.team_id)}ui/litellm-dashboard/src/components/networking.tsxindex 9aade717566..38d150f1d63 100644@@ -1605,6 +1605,7 @@ export const modelInfoCall = async (   accessGroup?: string,   wildcardOnly?: boolean,   blocked?: boolean,+  options: { useStoredParams?: boolean } = {}, ) => {   /**    * Get all models on proxy@@ -1624,6 +1625,9 @@ export const modelInfoCall = async (     if (modelId && modelId.trim()) {       params.append("modelId", modelId.trim());     }+    if (options.useStoredParams) {+      params.append("use_stored_params", "true");+    }     if (teamId && teamId.trim()) {       params.append("teamId", teamId.trim());     }ui/litellm-dashboard/src/lib/http/schema.d.tsindex ababe4507b8..0fc0d86b479 100644@@ -23728,6 +23728,7 @@ export interface paths {          *         page / size: Pagination controls (defaults: page=1, size=50).          *         search: Case-insensitive partial match on model name or team public name.          *         modelId: Return a single deployment by LiteLLM model id.+         *         use_stored_params: With modelId, return only persisted litellm_params keys, retaining normal redaction.          *         teamId: Filter to models with direct access or team membership for this team id.          *         sortBy / sortOrder: Sort by model_name, created_at, updated_at, costs, or status.          *         blocked: Filter by routing status (false = active, true = paused).@@ -40521,6 +40522,21 @@ export interface components {             guardrail_name?: string | null;             litellm_params?: components["schemas"]["BaseLitellmParams"] | null;         };+        /** PatchModelRequest */+        PatchModelRequest: {+            /** Blocked */+            blocked?: boolean | null;+            litellm_params?: components["schemas"]["updateLiteLLMParams"] | null;+            /**+             * Litellm Params To Remove+             * @description Top-level litellm_params keys to delete. Omitted parameters remain unchanged. The required model key and keys also supplied in litellm_params cannot be removed. Removing an absent key or repeating a key is a no-op.+             * @default []+             */+            litellm_params_to_remove: string[];+            model_info?: components["schemas"]["litellm__types__router__ModelInfo"] | null;+            /** Model Name */+            model_name?: string | null;+        };         /** PatchPromptRequest */         PatchPromptRequest: {             litellm_params?: components["schemas"]["PromptLiteLLMParams"] | null;@@ -65690,7 +65706,7 @@ export interface operations {         };         requestBody: {             content: {-                "application/json": components["schemas"]["updateDeployment"];+                "application/json": components["schemas"]["PatchModelRequest"];             };         };         responses: {@@ -84037,6 +84053,8 @@ export interface operations {                 search?: string | null;                 /** @description Search for a specific model by its unique ID */                 modelId?: string | null;+                /** @description With modelId, omit runtime-only litellm_params defaults from a DB-stored model's editor view. */+                use_stored_params?: boolean;                 /** @description Filter models by team ID. Returns models with direct_access=True or teamId in access_via_team_ids */                 teamId?: string | null;                 /** @description Field to sort by. Options: model_name, created_at, updated_at, costs, status */ui/litellm-dashboard/src/utils/modelEditParams.tsnew file mode 100644index 00000000000..72acb84bbc3@@ -0,0 +1,37 @@+import { isMaskedSecret } from "./maskedSecretUtils";++const FORM_PARAMS = new Set([+  "api_base",+  "custom_llm_provider",+  "organization",+  "tpm",+  "rpm",+  "max_retries",+  "timeout",+  "stream_timeout",+  "model",+  "input_cost_per_token",+  "output_cost_per_token",+  "cache_read_input_token_cost",+  "cache_creation_input_token_cost",+  "cache_creation_input_token_cost_above_1hr",+  "litellm_credential_name",+  "cache_control_injection_points",+  "vector_store_ids",+  "guardrails",+  "tags",+]);++export const editableModelExtraParams = (params: Record<string, unknown>): Record<string, unknown> =>+  Object.fromEntries(Object.entries(params).filter(([key, value]) => !FORM_PARAMS.has(key) && !isMaskedSecret(value)));++export const parseModelExtraParams = (value: string | undefined): Record<string, unknown> | null => {+  try {+    const parsed: unknown = JSON.parse(value?.trim() || "{}");+    return parsed !== null && typeof parsed === "object" && !Array.isArray(parsed)+      ? (parsed as Record<string, unknown>)+      : null;+  } catch {+    return null;+  }+};