diff --git a/litellm/llms/aiohttp_openai/chat/transformation.py b/litellm/llms/aiohttp_openai/chat/transformation.py index dba7a7405ab..a02e4049901 100644 --- a/litellm/llms/aiohttp_openai/chat/transformation.py +++ b/litellm/llms/aiohttp_openai/chat/transformation.py @@ -86,4 +86,7 @@ class AiohttpOpenAIChatConfig(OpenAILikeChatConfig): model_response.model = _json_response.get("model") model_response.object = _json_response.get("object") model_response.system_fingerprint = _json_response.get("system_fingerprint") + service_tier: Final = _json_response.get("service_tier") + if isinstance(service_tier, str) and service_tier: + setattr(model_response, "service_tier", service_tier) # noqa: B010 # pydantic extra, not a declared field return model_response diff --git a/tests/unit/llms/aiohttp_openai/chat/test_transformation.py b/tests/unit/llms/aiohttp_openai/chat/test_transformation.py index 253f9dbe746..05649b55a60 100644 --- a/tests/unit/llms/aiohttp_openai/chat/test_transformation.py +++ b/tests/unit/llms/aiohttp_openai/chat/test_transformation.py @@ -99,3 +99,38 @@ async def test_transform_response_rejects_choices_that_are_not_a_list_of_objects async def test_transform_response_rejects_a_choice_whose_message_is_not_an_object(): with pytest.raises(ValidationError, match="validation error for Choices"): await _transform({"choices": [{"message": "text"}]}) + + +async def test_transform_response_forwards_service_tier(): + response = await _transform( + { + "id": "chatcmpl-1", + "created": 1700000000, + "model": "gpt-4o", + "object": "chat.completion", + "service_tier": "flex", + "choices": [ + {"index": 0, "finish_reason": "stop", "message": {"role": "assistant", "content": "Hi"}}, + ], + } + ) + + assert response.service_tier == "flex" + + +async def test_transform_response_omits_service_tier_when_absent_or_blank(): + for service_tier in (None, "", 42): + body: dict = { + "id": "chatcmpl-1", + "created": 1700000000, + "model": "gpt-4o", + "object": "chat.completion", + "choices": [ + {"index": 0, "finish_reason": "stop", "message": {"role": "assistant", "content": "Hi"}}, + ], + } + if service_tier is not None: + body["service_tier"] = service_tier + response = await _transform(body) + + assert getattr(response, "service_tier", None) is None