Skip to content

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]

fix(llm_caching_handler.py): handle no current event loop error

Krrish Dholakiab8d1166e0ca2
diff --git a/litellm/caching/llm_caching_handler.py b/litellm/caching/llm_caching_handler.py
index e6fbee15bc0..429634b7b1f 100644
--- a/litellm/caching/llm_caching_handler.py
+++ b/litellm/caching/llm_caching_handler.py
@@ -14,9 +14,12 @@ class LLMClientCache(InMemoryCache):
Add the event loop to the cache key, to prevent event loop closed errors.
If none, use the key as is.
"""
- event_loop = asyncio.get_event_loop()
- stringified_event_loop = str(id(event_loop))
- return f"{key}-{stringified_event_loop}"
+ try:
+ event_loop = asyncio.get_event_loop()
+ stringified_event_loop = str(id(event_loop))
+ return f"{key}-{stringified_event_loop}"
+ except Exception: # handle no current event loop
+ return key
def set_cache(self, key, value, **kwargs):
key = self.update_cache_key_with_event_loop(key)