Fix: Add shared_session to all_litellm_params to prevent JSON serialization error

The shared_session parameter (aiohttp.ClientSession) was being passed through
to provider API calls, causing "Object of type ClientSession is not JSON
serializable" errors during embedding requests.

Added shared_session to the all_litellm_params list so it's properly filtered
out as a LiteLLM-internal parameter and not passed to the provider's API.
This commit is contained in:
AlexsanderHamir 2025-10-10 13:22:38 -07:00
parent 858cfa750f
commit 0e8e2a656e
2 changed files with 43 additions and 0 deletions

View file

@ -2325,6 +2325,7 @@ all_litellm_params = [
"litellm_session_id",
"use_litellm_proxy",
"prompt_label",
"shared_session",
] + list(StandardCallbackDynamicParams.__annotations__.keys())

View file

@ -0,0 +1,42 @@
"""
Test script to reproduce and debug the ClientSession JSON serialization error
"""
import asyncio
import aiohttp
import litellm
import traceback
# Enable debug mode
litellm._turn_on_debug()
async def test_embedding_with_shared_session():
"""Test that reproduces the ClientSession serialization error"""
async with aiohttp.ClientSession() as session:
print(f"Created ClientSession: {session}")
try:
response = await litellm.aembedding(
model="openai/text-embedding-ada-002",
input=["test input"],
api_key="invalid_key",
api_base="https://httpstat.us/500", # This will return 500 error
shared_session=session # This is the problematic parameter
)
print(f"Response: {response}")
except Exception as e:
print(f"\n❌ Error occurred: {type(e).__name__}")
print(f"Error message: {str(e)}")
print("\nFull traceback:")
traceback.print_exc()
# Check if this is the ClientSession serialization error
if "ClientSession" in str(e) and "JSON serializable" in str(e):
print("\n✅ Successfully reproduced the ClientSession serialization error!")
return True
return False
if __name__ == "__main__":
asyncio.run(test_embedding_with_shared_session())