From 0e8e2a656e3556f25945c17e6120c1d9fdaf3179 Mon Sep 17 00:00:00 2001 From: AlexsanderHamir Date: Fri, 10 Oct 2025 13:22:38 -0700 Subject: [PATCH] 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. --- litellm/types/utils.py | 1 + test_embedding_session_error_debug.py | 42 +++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 test_embedding_session_error_debug.py diff --git a/litellm/types/utils.py b/litellm/types/utils.py index 0da0ba4e93d..7f2d210ef80 100644 --- a/litellm/types/utils.py +++ b/litellm/types/utils.py @@ -2325,6 +2325,7 @@ all_litellm_params = [ "litellm_session_id", "use_litellm_proxy", "prompt_label", + "shared_session", ] + list(StandardCallbackDynamicParams.__annotations__.keys()) diff --git a/test_embedding_session_error_debug.py b/test_embedding_session_error_debug.py new file mode 100644 index 00000000000..68f339f2360 --- /dev/null +++ b/test_embedding_session_error_debug.py @@ -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()) +