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
Litellm dev 02 27 2025 p6 (#8891)
Krish Dholakia8f86959c3298
diff --git a/litellm/llms/sagemaker/completion/handler.py b/litellm/llms/sagemaker/completion/handler.pyindex ae40dd26d9a..4aff5f5d71b 100644--- a/litellm/llms/sagemaker/completion/handler.py+++ b/litellm/llms/sagemaker/completion/handler.py@@ -433,6 +433,10 @@ class SagemakerLLM(BaseAWSLLM):"messages": messages,}prepared_request = await asyncified_prepare_request(**prepared_request_args)+ if model_id is not None: # Fixes https://github.com/BerriAI/litellm/issues/8889+ prepared_request.headers.update(+ {"X-Amzn-SageMaker-Inference-Component": model_id}+ )completion_stream = await self.make_async_call(api_base=prepared_request.url,headers=prepared_request.headers, # type: ignorediff --git a/litellm/proxy/common_utils/http_parsing_utils.py b/litellm/proxy/common_utils/http_parsing_utils.pyindex ce8f1661c1d..5736ee21527 100644--- a/litellm/proxy/common_utils/http_parsing_utils.py+++ b/litellm/proxy/common_utils/http_parsing_utils.py@@ -42,7 +42,26 @@ async def _read_request_body(request: Optional[Request]) -> Dict:if not body:parsed_body = {}else:- parsed_body = orjson.loads(body)+ try:+ parsed_body = orjson.loads(body)+ except orjson.JSONDecodeError:+ # Fall back to the standard json module which is more forgiving+ # First decode bytes to string if needed+ body_str = body.decode("utf-8") if isinstance(body, bytes) else body++ # Replace invalid surrogate pairs+ import re++ # This regex finds incomplete surrogate pairs+ body_str = re.sub(+ r"[\uD800-\uDBFF](?![\uDC00-\uDFFF])", "", body_str+ )+ # This regex finds low surrogates without high surrogates+ body_str = re.sub(+ r"(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]", "", body_str+ )++ parsed_body = json.loads(body_str)# Cache the parsed result_safe_set_request_parsed_body(request=request, parsed_body=parsed_body)diff --git a/litellm/proxy/litellm_pre_call_utils.py b/litellm/proxy/litellm_pre_call_utils.pyindex 29fcddf6a21..c15bbbd4a7d 100644--- a/litellm/proxy/litellm_pre_call_utils.py+++ b/litellm/proxy/litellm_pre_call_utils.py@@ -425,9 +425,9 @@ class LiteLLMProxyRequestSetup:tags = [tag.strip() for tag in _tags]elif isinstance(headers["x-litellm-tags"], list):tags = headers["x-litellm-tags"]- # Check request body for tags- if "tags" in data and isinstance(data["tags"], list):- tags = data["tags"]+ # Check request body for tags+ if "tags" in data and isinstance(data["tags"], list):+ tags = data["tags"]return tags