File tree Expand file tree Collapse file tree 1 file changed +31
-3
lines changed
litellm/llms/custom_httpx Expand file tree Collapse file tree 1 file changed +31
-3
lines changed Original file line number Diff line number Diff line change @@ -301,17 +301,45 @@ async def post(
301301 if timeout is None :
302302 timeout = self .timeout
303303
304+ # ============================================================================
305+ # MEMORY LEAK FIX — Prevent httpx DeprecationWarning
306+ # ============================================================================
307+ # Problem:
308+ # httpx shows a DeprecationWarning when you pass bytes/str to `data=`.
309+ # It wants you to use `content=` instead.
310+ #
311+ # Impact:
312+ # The warning leaks memory. Preventing the warning fixes the leak.
313+ #
314+ # Fix:
315+ # Move bytes/str from `data=` to `content=` before calling build_request.
316+ # Keep dicts in `data=` (that's still correct).
317+ # ============================================================================
318+
319+ request_data = None
320+ request_content = content
321+
322+ # Route data parameter to the correct httpx parameter based on type
323+ if data is not None :
324+ if isinstance (data , (bytes , str )):
325+ # Bytes/strings belong in content= (only if not already provided)
326+ if content is None :
327+ request_content = data
328+ else :
329+ # dict/Mapping stays in data= parameter
330+ request_data = data
331+
304332 req = self .client .build_request (
305333 "POST" ,
306334 url ,
307- data = data , # type: ignore
335+ data = request_data ,
308336 json = json ,
309337 params = params ,
310338 headers = headers ,
311339 timeout = timeout ,
312340 files = files ,
313- content = content ,
314- )
341+ content = request_content ,
342+ )
315343 response = await self .client .send (req , stream = stream )
316344 response .raise_for_status ()
317345 return response
You can’t perform that action at this time.
0 commit comments