From 7923cb1a641582c592d8524137974efac3e15473 Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Sat, 11 Jan 2025 21:54:51 -0800 Subject: [PATCH] fix _read_request_body (#7706) --- litellm/proxy/common_utils/http_parsing_utils.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/litellm/proxy/common_utils/http_parsing_utils.py b/litellm/proxy/common_utils/http_parsing_utils.py index 1fb0da275ed..63b904602ac 100644 --- a/litellm/proxy/common_utils/http_parsing_utils.py +++ b/litellm/proxy/common_utils/http_parsing_utils.py @@ -1,6 +1,7 @@ import json from typing import Dict, List, Optional +import orjson from fastapi import Request, UploadFile, status from litellm._logging import verbose_proxy_logger @@ -32,13 +33,10 @@ async def _read_request_body(request: Optional[Request]) -> Dict: if not body: return {} - # Decode the body to a string - body_str = body.decode() - # Attempt JSON parsing (safe for untrusted input) - return json.loads(body_str) + return orjson.loads(body) - except json.JSONDecodeError: + except (json.JSONDecodeError, orjson.JSONDecodeError): # Log detailed information for debugging verbose_proxy_logger.exception("Invalid JSON payload received.") return {}