BerriAI/litellm · error · HTTPException

500

500

Error message

Cache type {litellm.cache.type} does not support deleting a key. only `redis` is supported

What it means

POST /cache/delete only implements key deletion for the plain Redis backend (litellm.cache.delete_cache_keys). With any other cache type (local, disk, redis-semantic-cache, dual-cache) it raises HTTPException 500 'Cache type X does not support deleting a key. only `redis` is supported'; the handler's catch-all then re-wraps it into 'Cache Delete Failed(500: Cache type ...)' on the wire.

Source

Thrown at litellm/proxy/caching_routes.py:154

    -H "Authorization: Bearer sk-1234" \
    -d '{"keys": ["key1", "key2"]}'
    ```

    """
    try:
        if litellm.cache is None:
            raise HTTPException(status_code=503, detail="Cache not initialized. litellm.cache is None")

        request_data: Final = await request.json()
        keys: Final = request_data.get("keys", None)

        if litellm.cache.type == "redis":
            await litellm.cache.delete_cache_keys(keys=keys)
            return {
                "status": "success",
            }
        else:
            raise HTTPException(
                status_code=500,
                detail=f"Cache type {litellm.cache.type} does not support deleting a key. only `redis` is supported",
            )
    except Exception as e:
        raise HTTPException(
            status_code=500,
            detail=f"Cache Delete Failed({e})",
        )


def _get_redis_client_info(cache_instance) -> tuple[list, int]:
    """
    Helper function to safely get Redis client list information.

    Returns:
        tuple: (client_list, num_clients) where num_clients is -1 if CLIENT LIST is unavailable
    """
    try:

View on GitHub (pinned to 77b7c6c40c)

Solutions

  1. Switch cache_settings.type to 'redis' if API-based key deletion is required.
  2. Otherwise delete entries directly on the real backend (semantic-cache entries live in Redis - delete by key pattern; local cache clears on restart).

Example fix

# before
litellm_settings:
  cache_settings:
    type: redis-semantic-cache   # /cache/delete rejects non-redis
# after
litellm_settings:
  cache_settings:
    type: redis
Defensive patterns

Strategy: type-guard

Validate before calling

import httpx

def cache_type_supports_delete(base_url: str, api_key: str) -> bool:
    r = httpx.get(f'{base_url}/cache/ping', headers={'Authorization': f'Bearer {api_key}'})
    if r.status_code != 200:
        return False
    return r.json().get('cache_type') == 'redis'

Type guard

def supports_cache_key_deletion(cache_type: str) -> bool:
    return cache_type == 'redis'

Try / catch

r = httpx.post(f'{base}/cache/delete', headers=auth, json={'keys': keys})
if r.status_code == 500 and 'does not support deleting a key' in r.text:
    purge_backend_directly()  # non-redis cache - bypass the endpoint

Prevention

When it happens

Trigger: POST /cache/delete on a proxy whose cache_settings.type is anything except 'redis' - e.g. redis-semantic-cache, local, disk, dual-cache.

Common situations: Semantic-caching deployments trying to purge specific entries; local dev running the default in-memory cache; backend switched without updating cleanup jobs.

Related errors


AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18). Data as JSON: /api/errors/5f7e08bd0dd50602. Report an issue: GitHub.