The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
test(e2e): cover model update persisting to /model/info (#34017)
Yassin Kortamb9c59c37cc0e
diff --git a/tests/e2e/management/test_management_e2e.py b/tests/e2e/management/test_management_e2e.pyindex 748f7192fb0..e60d074108e 100644--- a/tests/e2e/management/test_management_e2e.py+++ b/tests/e2e/management/test_management_e2e.py@@ -9,6 +9,7 @@ so the traffic-facing read-backs poll to a deadline instead of asserting once.from __future__ import annotations+import mathimport timefrom collections.abc import Callable@@ -22,7 +23,7 @@ from management_client import (ROUTE_NOT_ALLOWED_MARKER,ManagementClient,)-from models import KeyGenerateBody, OrgNewBody, TagListEntry, TagNewBody, TeamNewBody, UserNewBody+from models import KeyGenerateBody, OrgNewBody, TagListEntry, TagNewBody, TeamNewBody, UserNewBody, LiteLLMParamsBody, ModelInfoEntrypytestmark = pytest.mark.e2e@@ -315,6 +316,59 @@ class TestTagRoutes:)+_INITIAL_INPUT_COST = 0.00000111+_UPDATED_INPUT_COST = 0.00000222+++def _model_entry(client: ManagementClient, model_name: str) -> ModelInfoEntry | None:+ return next((entry for entry in client.proxy.model_info() if entry.model_name == model_name), None)+++class TestModelRoutes:+ @pytest.mark.covers("mgmt.model.update.persists")+ def test_update_persists_input_cost_to_model_info(+ self, client: ManagementClient, resources: ResourceManager+ ) -> None:+ model_name = f"e2e-mgmt-model-{unique_marker()}"+ model_id = client.proxy.create_model(+ model_name,+ LiteLLMParamsBody(+ model="gpt-4o-mini",+ mock_response="ok",+ input_cost_per_token=_INITIAL_INPUT_COST,+ ),+ )+ resources.defer(lambda: client.proxy.delete_model(model_id))++ before = _model_entry(client, model_name)+ assert before is not None, f"{model_name} absent from /model/info right after /model/new"+ initial = before.litellm_params.input_cost_per_token+ assert initial is not None and math.isclose(initial, _INITIAL_INPUT_COST, rel_tol=1e-9), (+ f"/model/info reports input_cost_per_token {initial}, registered {_INITIAL_INPUT_COST}"+ )++ client.proxy.update_model(+ model_id,+ LiteLLMParamsBody(model="gpt-4o-mini", input_cost_per_token=_UPDATED_INPUT_COST),+ )++ def updated() -> ModelInfoEntry | None:+ entry = _model_entry(client, model_name)+ if entry is None:+ return None+ cost = entry.litellm_params.input_cost_per_token+ if cost is not None and math.isclose(cost, _UPDATED_INPUT_COST, rel_tol=1e-9):+ return entry+ return None++ _ = _poll(+ client,+ updated,+ f"/model/info never reported input_cost_per_token {_UPDATED_INPUT_COST} for {model_name} "+ "after /model/update",+ )++def _assert_route_forbidden(route: str, outcome: StreamingResponse) -> None:assert outcome.status_code == 403, (f"llm-only key POSTing {route} must be denied exactly 403, got {outcome.status_code}: {outcome.body[:300]}"diff --git a/tests/e2e/models.py b/tests/e2e/models.pyindex b7a95f9714c..b319468f162 100644--- a/tests/e2e/models.py+++ b/tests/e2e/models.py@@ -551,6 +551,17 @@ class ModelNewResponse(BaseModel):model_id: str+class ModelUpdateBody(BaseModel):+ """POST /model/update body: the target deployment (`model_info.id`) plus the+ `litellm_params` to merge over its stored params. The handler overlays only the+ non-null fields, so a body carrying `input_cost_per_token` re-prices the+ deployment while leaving its other params intact."""++ model_config = ConfigDict(protected_namespaces=())+ litellm_params: LiteLLMParamsBody+ model_info: ModelInfoBody++class ModelListEntry(BaseModel):id: strdiff --git a/tests/e2e/proxy_client.py b/tests/e2e/proxy_client.pyindex f1039257193..6c6b948e29c 100644--- a/tests/e2e/proxy_client.py+++ b/tests/e2e/proxy_client.py@@ -54,6 +54,7 @@ from models import (ModelNewBody,ModelNewResponse,ModelsListResponse,+ ModelUpdateBody,OcrBody,OcrResponse,SpendLogRow,@@ -211,6 +212,23 @@ class ProxyClient:f"propagation or STORE_MODEL_IN_DB reload issue){last_error}")+ def update_model(self, model_id: str, litellm_params: LiteLLMParamsBody) -> None:+ """Merge `litellm_params` over the deployment `model_id`'s stored params via+ POST /model/update. The proxy overlays only the non-null fields and clears+ its model cache, so a later /model/info read reflects the change (eventually,+ after the reload)."""+ unwrap(+ self.transport.post(+ "/model/update",+ headers=self.transport.master,+ json=ModelUpdateBody(+ litellm_params=litellm_params,+ model_info=ModelInfoBody(id=model_id),+ ),+ response_type=NoBody,+ )+ )+def delete_model(self, model_id: str) -> None:result = self.transport.post("/model/delete",