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
Groq - ensure service tier is OpenAI compatible
Ishaan Jaff1c91e229421b
diff --git a/litellm/llms/groq/chat/transformation.py b/litellm/llms/groq/chat/transformation.pyindex 877d9a6edbd..6bf202c1b4e 100644--- a/litellm/llms/groq/chat/transformation.py+++ b/litellm/llms/groq/chat/transformation.py@@ -1,11 +1,23 @@"""Translate from OpenAI's `/v1/chat/completions` to Groq's `/v1/chat/completions`"""+from typing import (+ TYPE_CHECKING,+ Any,+ Coroutine,+ List,+ Literal,+ Optional,+ Tuple,+ Union,+ cast,+ overload,+)-from typing import Any, Coroutine, List, Literal, Optional, Tuple, Union, overload-+import httpxfrom pydantic import BaseModel+from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObjfrom litellm.secret_managers.main import get_secret_strfrom litellm.types.llms.openai import (AllMessageValues,@@ -13,6 +25,7 @@ from litellm.types.llms.openai import (ChatCompletionToolParam,ChatCompletionToolParamFunctionChunk,)+from litellm.types.utils import ModelResponsefrom ...openai_like.chat.transformation import OpenAILikeChatConfig@@ -192,3 +205,48 @@ class GroqChatConfig(OpenAILikeChatConfig):)return optional_params+++ def transform_response(+ self,+ model: str,+ raw_response: httpx.Response,+ model_response: ModelResponse,+ logging_obj: LiteLLMLoggingObj,+ request_data: dict,+ messages: List[AllMessageValues],+ optional_params: dict,+ litellm_params: dict,+ encoding: Any,+ api_key: Optional[str] = None,+ json_mode: Optional[bool] = None,+ ) -> ModelResponse:+ model_response = super().transform_response(+ model=model,+ raw_response=raw_response,+ model_response=model_response,+ logging_obj=logging_obj,+ request_data=request_data,+ messages=messages,+ optional_params=optional_params,+ litellm_params=litellm_params,+ encoding=encoding,+ api_key=api_key,+ json_mode=json_mode,+ )++ mapped_service_tier: Literal["auto", "default", "flex"] = self._map_groq_service_tier(original_service_tier=getattr(model_response, "service_tier"))+ setattr(model_response, "service_tier", mapped_service_tier)+ return model_response+++ def _map_groq_service_tier(self, original_service_tier: Optional[str]) -> Literal["auto", "default", "flex"]:+ """+ Ensure groq service tier is OpenAI compatible.+ """+ if original_service_tier is None:+ return "auto"+ if original_service_tier not in ["auto", "default", "flex"]:+ return "auto"++ return cast(Literal["auto", "default", "flex"], original_service_tier)\ No newline at end of file