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]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
Litellm fix multi instance checks on teams (#11137)
Krish Dholakiaa78d121ef40e
diff --git a/litellm/caching/in_memory_cache.py b/litellm/caching/in_memory_cache.pyindex 8329e4be544..e9c3f7ba44b 100644--- a/litellm/caching/in_memory_cache.py+++ b/litellm/caching/in_memory_cache.py@@ -106,6 +106,18 @@ class InMemoryCache(BaseCache):# One of the most common causes of memory leaks in Python is the retention of objects that are no longer being used.# This can occur when an object is referenced by another object, but the reference is never removed.+ def allow_ttl_override(self, key: str) -> bool:+ """+ Check if ttl is set for a key+ """+ ttl_time = self.ttl_dict.get(key)+ if ttl_time is None: # if ttl is not set, allow override+ return True+ elif float(ttl_time) < time.time(): # if ttl is expired, allow override+ return True+ else:+ return False+def set_cache(self, key, value, **kwargs):if len(self.cache_dict) >= self.max_size_in_memory:# only evict when cache is full@@ -114,7 +126,7 @@ class InMemoryCache(BaseCache):returnself.cache_dict[key] = value- if self.ttl_dict.get(key) is None: # if ttl is not set, set it to default ttl+ if self.allow_ttl_override(key): # if ttl is not set, set it to default ttlif "ttl" in kwargs and kwargs["ttl"] is not None:self.ttl_dict[key] = time.time() + kwargs["ttl"]else:diff --git a/litellm/proxy/_experimental/out/onboarding.html b/litellm/proxy/_experimental/out/onboarding.htmldeleted file mode 100644index 6e8b9f72774..00000000000--- a/litellm/proxy/_experimental/out/onboarding.html+++ /dev/null@@ -1 +0,0 @@-<!DOCTYPE html><html id="__next_error__"><head><meta charSet="utf-8"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="preload" as="script" fetchPriority="low" href="/ui/_next/static/chunks/webpack-75a5453f51d60261.js"/><script src="/ui/_next/static/chunks/fd9d1056-205af899b895cbac.js" async=""></script><script src="/ui/_next/static/chunks/117-1c5bfc45bfc4237d.js" async=""></script><script src="/ui/_next/static/chunks/main-app-475d6efe4080647d.js" async=""></script><title>LiteLLM Dashboard</title><meta name="description" content="LiteLLM Proxy Admin UI"/><link rel="icon" href="/ui/favicon.ico" type="image/x-icon" sizes="16x16"/><meta name="next-size-adjust"/><script src="/ui/_next/static/chunks/polyfills-42372ed130431b0a.js" noModule=""></script></head><body><script src="/ui/_next/static/chunks/webpack-75a5453f51d60261.js" async=""></script><script>(self.__next_f=self.__next_f||[]).push([0]);self.__next_f.push([2,null])</script><script>self.__next_f.push([1,"1:HL[\"/ui/_next/static/media/a34f9d1faa5f3315-s.p.woff2\",\"font\",{\"crossOrigin\":\"\",\"type\":\"font/woff2\"}]\n2:HL[\"/ui/_next/static/css/86f6cc749f6b8493.css\",\"style\"]\n3:HL[\"/ui/_next/static/css/63ea99feee8ef7db.css\",\"style\"]\n"])</script><script>self.__next_f.push([1,"4:I[12846,[],\"\"]\n6:I[19107,[],\"ClientPageRoot\"]\n7:I[12011,[\"665\",\"static/chunks/3014691f-b7b79b78e27792f3.js\",\"402\",\"static/chunks/402-ba983153c902cb17.js\",\"899\",\"static/chunks/899-ebef5c8ffc176e86.js\",\"250\",\"static/chunks/250-b34a5fd44bf9b45f.js\",\"461\",\"static/chunks/app/onboarding/page-8c2f1d7b29a0b5ff.js\"],\"default\",1]\n8:I[4707,[],\"\"]\n9:I[36423,[],\"\"]\nb:I[61060,[],\"\"]\nc:[]\n"])</script><script>self.__next_f.push([1,"0:[\"$\",\"$L4\",null,{\"buildId\":\"AUMac1vqK9A5ZBV8VXWZ7\",\"assetPrefix\":\"/ui\",\"urlParts\":[\"\",\"onboarding\"],\"initialTree\":[\"\",{\"children\":[\"onboarding\",{\"children\":[\"__PAGE__\",{}]}]},\"$undefined\",\"$undefined\",true],\"initialSeedData\":[\"\",{\"children\":[\"onboarding\",{\"children\":[\"__PAGE__\",{},[[\"$L5\",[\"$\",\"$L6\",null,{\"props\":{\"params\":{},\"searchParams\":{}},\"Component\":\"$7\"}],null],null],null]},[null,[\"$\",\"$L8\",null,{\"parallelRouterKey\":\"children\",\"segmentPath\":[\"children\",\"onboarding\",\"children\"],\"error\":\"$undefined\",\"errorStyles\":\"$undefined\",\"errorScripts\":\"$undefined\",\"template\":[\"$\",\"$L9\",null,{}],\"templateStyles\":\"$undefined\",\"templateScripts\":\"$undefined\",\"notFound\":\"$undefined\",\"notFoundStyles\":\"$undefined\"}]],null]},[[[[\"$\",\"link\",\"0\",{\"rel\":\"stylesheet\",\"href\":\"/ui/_next/static/css/86f6cc749f6b8493.css\",\"precedence\":\"next\",\"crossOrigin\":\"$undefined\"}],[\"$\",\"link\",\"1\",{\"rel\":\"stylesheet\",\"href\":\"/ui/_next/static/css/63ea99feee8ef7db.css\",\"precedence\":\"next\",\"crossOrigin\":\"$undefined\"}]],[\"$\",\"html\",null,{\"lang\":\"en\",\"children\":[\"$\",\"body\",null,{\"className\":\"__className_cf7686\",\"children\":[\"$\",\"$L8\",null,{\"parallelRouterKey\":\"children\",\"segmentPath\":[\"children\"],\"error\":\"$undefined\",\"errorStyles\":\"$undefined\",\"errorScripts\":\"$undefined\",\"template\":[\"$\",\"$L9\",null,{}],\"templateStyles\":\"$undefined\",\"templateScripts\":\"$undefined\",\"notFound\":[[\"$\",\"title\",null,{\"children\":\"404: This page could not be found.\"}],[\"$\",\"div\",null,{\"style\":{\"fontFamily\":\"system-ui,\\\"Segoe UI\\\",Roboto,Helvetica,Arial,sans-serif,\\\"Apple Color Emoji\\\",\\\"Segoe UI Emoji\\\"\",\"height\":\"100vh\",\"textAlign\":\"center\",\"display\":\"flex\",\"flexDirection\":\"column\",\"alignItems\":\"center\",\"justifyContent\":\"center\"},\"children\":[\"$\",\"div\",null,{\"children\":[[\"$\",\"style\",null,{\"dangerouslySetInnerHTML\":{\"__html\":\"body{color:#000;background:#fff;margin:0}.next-error-h1{border-right:1px solid rgba(0,0,0,.3)}@media (prefers-color-scheme:dark){body{color:#fff;background:#000}.next-error-h1{border-right:1px solid rgba(255,255,255,.3)}}\"}}],[\"$\",\"h1\",null,{\"className\":\"next-error-h1\",\"style\":{\"display\":\"inline-block\",\"margin\":\"0 20px 0 0\",\"padding\":\"0 23px 0 0\",\"fontSize\":24,\"fontWeight\":500,\"verticalAlign\":\"top\",\"lineHeight\":\"49px\"},\"children\":\"404\"}],[\"$\",\"div\",null,{\"style\":{\"display\":\"inline-block\"},\"children\":[\"$\",\"h2\",null,{\"style\":{\"fontSize\":14,\"fontWeight\":400,\"lineHeight\":\"49px\",\"margin\":0},\"children\":\"This page could not be found.\"}]}]]}]}]],\"notFoundStyles\":[]}]}]}]],null],null],\"couldBeIntercepted\":false,\"initialHead\":[null,\"$La\"],\"globalErrorComponent\":\"$b\",\"missingSlots\":\"$Wc\"}]\n"])</script><script>self.__next_f.push([1,"a:[[\"$\",\"meta\",\"0\",{\"name\":\"viewport\",\"content\":\"width=device-width, initial-scale=1\"}],[\"$\",\"meta\",\"1\",{\"charSet\":\"utf-8\"}],[\"$\",\"title\",\"2\",{\"children\":\"LiteLLM Dashboard\"}],[\"$\",\"meta\",\"3\",{\"name\":\"description\",\"content\":\"LiteLLM Proxy Admin UI\"}],[\"$\",\"link\",\"4\",{\"rel\":\"icon\",\"href\":\"/ui/favicon.ico\",\"type\":\"image/x-icon\",\"sizes\":\"16x16\"}],[\"$\",\"meta\",\"5\",{\"name\":\"next-size-adjust\"}]]\n5:null\n"])</script></body></html>\ No newline at end of filediff --git a/litellm/proxy/_new_secret_config.yaml b/litellm/proxy/_new_secret_config.yamlindex 3c4ecc2ce73..e85ddfdc2be 100644--- a/litellm/proxy/_new_secret_config.yaml+++ b/litellm/proxy/_new_secret_config.yaml@@ -1,9 +1,10 @@model_list:- - model_name: azure/any+ - model_name: fake-openai-endpointlitellm_params:model: openai/fakeapi_key: fake-keyapi_base: https://exampleopenaiendpoint-production.up.railway.app/+litellm_settings:cache: true\ No newline at end of filediff --git a/litellm/proxy/auth/auth_checks.py b/litellm/proxy/auth/auth_checks.pyindex 8653e40c7a5..50212471450 100644--- a/litellm/proxy/auth/auth_checks.py+++ b/litellm/proxy/auth/auth_checks.py@@ -756,7 +756,9 @@ async def _cache_management_object(user_api_key_cache: DualCache,proxy_logging_obj: Optional[ProxyLogging],):- await user_api_key_cache.async_set_cache(key=key, value=value)+ await user_api_key_cache.async_set_cache(+ key=key, value=value, ttl=DEFAULT_MANAGEMENT_OBJECT_IN_MEMORY_CACHE_TTL+ )async def _cache_team_object(@@ -870,7 +872,6 @@ async def _get_team_object_from_user_api_key_cache(proxy_logging_obj=proxy_logging_obj,)- # save to db access time# save to db access time_update_last_db_access_time(key=db_access_time_key,diff --git a/tests/litellm/caching/test_in_memory_cache.py b/tests/litellm/caching/test_in_memory_cache.pyindex 0dc029d1459..72f264b8b7d 100644--- a/tests/litellm/caching/test_in_memory_cache.py+++ b/tests/litellm/caching/test_in_memory_cache.py@@ -69,3 +69,22 @@ def test_in_memory_cache_ttl():cached_obj = in_memory_cache.get_cache(key="new-fake-key")new_ttl_time = in_memory_cache.ttl_dict.get("new-fake-key")assert new_ttl_time is None+++def test_in_memory_cache_ttl_allow_override():+ """+ Check that+ - if ttl is not set, it will be set to default ttl+ - if object expires, the ttl is also removed+ """+ in_memory_cache = InMemoryCache()+ ## On object expiration, but no get_cache, the override should be allowed+ in_memory_cache.set_cache(key="new-fake-key", value="new-fake-value", ttl=1)+ initial_ttl_time = in_memory_cache.ttl_dict["new-fake-key"]+ assert initial_ttl_time is not None+ time.sleep(1)++ in_memory_cache.set_cache(key="new-fake-key", value="new-fake-value-2", ttl=1)+ new_ttl_time = in_memory_cache.ttl_dict["new-fake-key"]+ assert new_ttl_time is not None+ assert new_ttl_time != initial_ttl_time