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
[Bug] Fix: Vertex Mistral not working for streaming (#13952)
Ishaan Jaff6ce1d8297049
diff --git a/litellm/llms/openai_like/chat/handler.py b/litellm/llms/openai_like/chat/handler.pyindex ae0a3cc3551..821fc9b7f15 100644--- a/litellm/llms/openai_like/chat/handler.py+++ b/litellm/llms/openai_like/chat/handler.py@@ -49,15 +49,8 @@ async def make_call(model_response = ModelResponse(**response.json())completion_stream = MockResponseIterator(model_response=model_response)else:- # Use aiter_text with explicit UTF-8 encoding to avoid ASCII encoding errors- async def utf8_aiter_lines():- async for line in response.aiter_text(encoding='utf-8'):- for line_part in line.splitlines(keepends=True):- if line_part.strip():- yield line_part.rstrip('\r\n')-completion_stream = ModelResponseIterator(- streaming_response=utf8_aiter_lines(), sync_stream=False+ streaming_response=response.aiter_lines(), sync_stream=False)# LOGGINGlogging_obj.post_call(@@ -100,15 +93,8 @@ def make_sync_call(model_response = ModelResponse(**response.json())completion_stream = MockResponseIterator(model_response=model_response)else:- # Use iter_text with explicit UTF-8 encoding to avoid ASCII encoding errors- def utf8_iter_lines():- for line in response.iter_text(encoding='utf-8'):- for line_part in line.splitlines(keepends=True):- if line_part.strip():- yield line_part.rstrip('\r\n')-completion_stream = ModelResponseIterator(- streaming_response=utf8_iter_lines(), sync_stream=True+ streaming_response=response.iter_lines(), sync_stream=True)# LOGGINGdiff --git a/tests/local_testing/test_amazing_vertex_completion.py b/tests/local_testing/test_amazing_vertex_completion.pyindex b846763737a..b908eabd0cf 100644--- a/tests/local_testing/test_amazing_vertex_completion.py+++ b/tests/local_testing/test_amazing_vertex_completion.py@@ -910,6 +910,7 @@ async def test_partner_models_httpx(model, region, sync_mode):[("vertex_ai/meta/llama-4-scout-17b-16e-instruct-maas", "us-east5"),("vertex_ai/qwen/qwen3-coder-480b-a35b-instruct-maas", "us-south1"),+ ("vertex_ai/mistral-large-2411", "us-central1"), # critical - we had this issue: https://github.com/BerriAI/litellm/issues/13888],)@pytest.mark.parametrize(@@ -920,7 +921,7 @@ async def test_partner_models_httpx(model, region, sync_mode):@pytest.mark.flaky(retries=3, delay=1)async def test_partner_models_httpx_streaming(model, region, sync_mode):try:- #load_vertex_ai_credentials()+ load_vertex_ai_credentials()litellm._turn_on_debug()messages = [@@ -955,8 +956,6 @@ async def test_partner_models_httpx_streaming(model, region, sync_mode):print(f"response: {response}")except litellm.RateLimitError as e:pass- except litellm.InternalServerError as e:- passexcept Exception as e:if "429 Quota exceeded" in str(e):passdiff --git a/tests/test_litellm/test_groq_streaming_encoding.py b/tests/test_litellm/test_groq_streaming_encoding.pyindex cb1d69a4a10..e22e5ff6a0d 100644--- a/tests/test_litellm/test_groq_streaming_encoding.py+++ b/tests/test_litellm/test_groq_streaming_encoding.py@@ -5,11 +5,14 @@ This test verifies that the OpenAI-like handler correctly handlesUTF-8 encoded content in streaming responses, specifically fixingthe ASCII encoding error described in issue #12660."""-import pytestimport asyncio-from unittest.mock import Mock, AsyncMock+from unittest.mock import AsyncMock, Mock++import pytest+from litellm.llms.openai_like.chat.handler import make_call, make_sync_call+class MockResponse:"""Mock httpx response for testing UTF-8 handling."""@@ -25,6 +28,14 @@ class MockResponse:"""Mock aiter_text that yields content with the specified encoding."""yield self.test_content+ def iter_lines(self):+ """Mock iter_lines method for synchronous streaming."""+ yield self.test_content++ async def aiter_lines(self):+ """Mock aiter_lines method for asynchronous streaming."""+ yield self.test_content+def json(self):return {"choices": [{"delta": {"content": "test"}}]}