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
Match the client-name check to the name the proxy actually stamps
mateo-berri080149334771
diff --git a/litellm/proxy/common_request_processing.py b/litellm/proxy/common_request_processing.pyindex 1c6237f1c56..e7983ba3c9b 100644--- a/litellm/proxy/common_request_processing.py+++ b/litellm/proxy/common_request_processing.py@@ -303,12 +303,15 @@ def _assembled_model_is_the_name_the_client_asked_for(request_data: dict, assemb"""Report whether the assembled model is the public name the proxy stamps onto chunks.That stamp is what leaves an unpriced alias on the partial response, so the deployment's- own model has to go back on before the row is costed.+ own model has to go back on before the row is costed. Pre-call processing rewrites+ `request_data["model"]` for aliasing and routing, so the client's own name wins when it+ is there, in the same order the proxy picks the name it stamps."""- return assembled_model in (- request_data.get("_litellm_client_requested_model"),- request_data.get("model"),+ client_requested_model: Final = request_data.get("_litellm_client_requested_model")+ stamped_model: Final = (+ client_requested_model if isinstance(client_requested_model, str) else request_data.get("model"))+ return isinstance(stamped_model, str) and assembled_model == stamped_modelasync def _bill_partial_streamed_spend_on_disconnect(request_data: dict, response: object) -> bool:diff --git a/tests/test_litellm/proxy/test_common_request_processing.py b/tests/test_litellm/proxy/test_common_request_processing.pyindex 9e1fe5f8dac..9dd76b4eb88 100644--- a/tests/test_litellm/proxy/test_common_request_processing.py+++ b/tests/test_litellm/proxy/test_common_request_processing.py@@ -5592,6 +5592,31 @@ class TestStreamingClientDisconnectBilling:standard_logging_object = event["kwargs"]["standard_logging_object"]assert standard_logging_object["response_cost"] > 0.0+ @pytest.mark.asyncio+ async def test_disconnect_billing_keeps_the_routed_model_when_request_data_model_was_rewritten(self):+ """+ Pre-call processing rewrites request_data["model"] for aliasing and routing, so the+ routed model on the later chunks can end up matching it. Only the name the client+ sent says whether the proxy restamped this stream.+ """++ def restamp_like_azure_model_router(response):+ response.chunks[0].model = "azure-model-router"+ for chunk in response.chunks[1:]:+ chunk.model = "gpt-4.1-nano-2025-04-14"++ event = await self._bill_and_collect_success_event(+ restamp_like_azure_model_router,+ request_data={+ "model": "gpt-4.1-nano-2025-04-14",+ "_litellm_client_requested_model": "azure-model-router",+ },+ )++ assert event["response_obj"].model == "gpt-4.1-nano-2025-04-14"+ standard_logging_object = event["kwargs"]["standard_logging_object"]+ assert standard_logging_object["response_cost"] > 0.0+@pytest.mark.asyncioasync def test_disconnect_billing_backfills_missing_cache_fields(self):event = await self._bill_and_collect_success_event()