From 13b77ea1b9a92de396538aa13796fe3aee22d84a Mon Sep 17 00:00:00 2001 From: daleselaji-dev <265319989+daleselaji-dev@users.noreply.github.com> Date: Wed, 26 Aug 2026 10:40:02 +0800 Subject: [PATCH] fix(openai): preserve streaming service tier --- .../llms/openai/chat/gpt_transformation.py | 2 ++ .../chat/test_openai_gpt_transformation.py | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/litellm/llms/openai/chat/gpt_transformation.py b/litellm/llms/openai/chat/gpt_transformation.py index 16fd042cb2f..fc2f9324906 100644 --- a/litellm/llms/openai/chat/gpt_transformation.py +++ b/litellm/llms/openai/chat/gpt_transformation.py @@ -807,6 +807,8 @@ class OpenAIChatCompletionStreamingHandler(BaseModelResponseIterator): } if "usage" in chunk and chunk["usage"] is not None: kwargs["usage"] = chunk["usage"] + if "service_tier" in chunk and chunk["service_tier"] is not None: + kwargs["service_tier"] = chunk["service_tier"] return ModelResponseStream(**kwargs) except Exception as e: raise e diff --git a/tests/test_litellm/llms/openai/chat/test_openai_gpt_transformation.py b/tests/test_litellm/llms/openai/chat/test_openai_gpt_transformation.py index f4c38f8f797..4201e0a9713 100644 --- a/tests/test_litellm/llms/openai/chat/test_openai_gpt_transformation.py +++ b/tests/test_litellm/llms/openai/chat/test_openai_gpt_transformation.py @@ -5,7 +5,6 @@ Tests for OpenAI GPT transformation (litellm/llms/openai/chat/gpt_transformation import pytest - import litellm from litellm.litellm_core_utils.prompt_templates.common_utils import TOOL_RESULT_IMAGE_BOUNDARY from litellm.llms.openai.chat.gpt_5_transformation import OpenAIGPT5Config @@ -184,6 +183,24 @@ class TestOpenAIChatCompletionStreamingHandler: assert result.usage.completion_tokens == 350 assert result.usage.total_tokens == 14147 + def test_chunk_parser_preserves_service_tier(self): + """Provider service-tier responses must survive chunk normalization.""" + handler = OpenAIChatCompletionStreamingHandler( + streaming_response=None, sync_stream=True + ) + + result = handler.chunk_parser( + { + "id": "gen-123", + "created": 1234567890, + "model": "xai/grok-4.6", + "choices": [], + "service_tier": "priority", + } + ) + + assert result.service_tier == "priority" + def test_chunk_parser_raises_on_in_body_error_payload(self): """vLLM/sglang return HTTP 200 streams whose body carries the error, e.g. data: {"error": {..., "code": 400}}. chunk_parser must surface it