diff --git a/litellm/caching.py b/litellm/caching.py index 5ec625b1b4..921ae1b21a 100644 --- a/litellm/caching.py +++ b/litellm/caching.py @@ -318,6 +318,9 @@ class RedisCache(BaseCache): def flush_cache(self): self.redis_client.flushall() + def flushall(self): + self.redis_client.flushall() + async def disconnect(self): await self.async_redis_conn_pool.disconnect(inuse_connections=True) diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.py index 44aed9fe40..48712a864e 100644 --- a/litellm/proxy/proxy_server.py +++ b/litellm/proxy/proxy_server.py @@ -7753,6 +7753,44 @@ async def cache_ping(): ) +@router.post( + "/cache/flushall", + tags=["caching"], + dependencies=[Depends(user_api_key_auth)], +) +async def cache_flushall(): + """ + A function to flush all items from the cache. (All items will be deleted from the cache with this) + Raises HTTPException if the cache is not initialized or if the cache type does not support flushing. + Returns a dictionary with the status of the operation. + + Usage: + ``` + curl -X POST http://0.0.0.0:4000/cache/flushall -H "Authorization: Bearer sk-1234" + ``` + """ + try: + if litellm.cache is None: + raise HTTPException( + status_code=503, detail="Cache not initialized. litellm.cache is None" + ) + if litellm.cache.type == "redis": + litellm.cache.cache.flushall() + return { + "status": "success", + } + else: + raise HTTPException( + status_code=500, + detail=f"Cache type {litellm.cache.type} does not support flushing", + ) + except Exception as e: + raise HTTPException( + status_code=503, + detail=f"Service Unhealthy ({str(e)})", + ) + + @router.get("/", dependencies=[Depends(user_api_key_auth)]) async def home(request: Request): return "LiteLLM: RUNNING" diff --git a/litellm/tests/test_completion.py b/litellm/tests/test_completion.py index 215bdef16a..6d579acc0f 100644 --- a/litellm/tests/test_completion.py +++ b/litellm/tests/test_completion.py @@ -76,6 +76,8 @@ def test_completion_claude(): print(response["usage"]["completion_tokens"]) # print("new cost tracking") except Exception as e: + if "overloaded_error" in str(e): + pass pytest.fail(f"Error occurred: {e}")