litellm - ✅(Solved) Fix RedisSemanticCache init failure should degrade gracefully instead of crashing proxy [1 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
BerriAI/litellm#25962Fetched 2026-04-18 05:52:49
View on GitHub
Comments
0
Participants
1
Timeline
2
Reactions
0
Participants
Timeline (top)
cross-referenced ×1labeled ×1

When redis-semantic cache is configured and the embedding model returns an error on startup (e.g. 429 rate limit, spend cap exhaustion, network failure), LiteLLM raises an unhandled ValueError and exits entirely: File "litellm/caching/redis_semantic_cache.py", line 110, in init cache_vectorizer = CustomTextVectorizer(self._get_embedding) File "redisvl/utils/vectorize/text/custom.py", line 146, in _validate_sync_callables raise ValueError(f"Invalid embedding method: {e}") ValueError: Invalid embedding method: litellm.RateLimitError: GeminiException - 429 ERROR: Application startup failed. Exiting.

Error Message

def _init_cache(self, cache_params): try: litellm.cache = Cache(**cache_params) except Exception as e: verbose_proxy_logger.warning( f"Cache init failed ({e}) — starting without cache" ) litellm.cache = None

Root Cause

When redis-semantic cache is configured and the embedding model returns an error on startup (e.g. 429 rate limit, spend cap exhaustion, network failure), LiteLLM raises an unhandled ValueError and exits entirely: File "litellm/caching/redis_semantic_cache.py", line 110, in init cache_vectorizer = CustomTextVectorizer(self._get_embedding) File "redisvl/utils/vectorize/text/custom.py", line 146, in _validate_sync_callables raise ValueError(f"Invalid embedding method: {e}") ValueError: Invalid embedding method: litellm.RateLimitError: GeminiException - 429 ERROR: Application startup failed. Exiting.

Fix Action

Fixed

PR fix notes

PR #25964: fix: degrade gracefully when RedisSemanticCache init fails instead of crashing proxy

Description (problem / solution / changelog)

Closes #25962.

Problem

When redis-semantic cache is configured and the embedding model is unavailable at startup (rate limit, spend cap, network error), CustomTextVectorizer.__init__ calls the embedding function to validate it. If that call fails with a ValueError, the exception propagates all the way up through _init_cache and crashes the proxy entirely.

Users see:

ValueError: Invalid embedding method: ...

and the proxy never starts, even though the rest of the configuration is valid.

Fix

Two-layer fix:

1. litellm/caching/redis_semantic_cache.py

Wrap the CustomTextVectorizer call in a try/except and re-raise as RuntimeError with a clear, actionable message. This makes the failure explicit and easy to diagnose regardless of which layer catches it.

2. litellm/proxy/proxy_server.py

Wrap self._init_cache() in a try/except. On failure, log a warning with the error and set litellm.cache = None. The proxy starts normally without caching rather than dying.

This follows the same pattern already used for the semantic tool filter initialization in the same file.

Behavior after the fix

  • Proxy starts successfully even when the embedding model is unreachable at startup
  • A clear warning is logged: Cache initialisation failed - proxy will start without caching. Error: ...
  • Caching is disabled for the session; all other proxy features work normally
  • Operators can fix the embedding model config and restart to re-enable caching

Changed files

  • litellm/caching/redis_semantic_cache.py (modified, +15/-2)
  • litellm/proxy/proxy_server.py (modified, +16/-6)
  • tests/local_testing/test_redis_semantic_cache_unit.py (added, +113/-0)

Code Example

def _init_cache(self, cache_params):
    try:
        litellm.cache = Cache(**cache_params)
    except Exception as e:
        verbose_proxy_logger.warning(
            f"Cache init failed ({e}) — starting without cache"
        )
        litellm.cache = None
RAW_BUFFERClick to expand / collapse

Description

When redis-semantic cache is configured and the embedding model returns an error on startup (e.g. 429 rate limit, spend cap exhaustion, network failure), LiteLLM raises an unhandled ValueError and exits entirely: File "litellm/caching/redis_semantic_cache.py", line 110, in init cache_vectorizer = CustomTextVectorizer(self._get_embedding) File "redisvl/utils/vectorize/text/custom.py", line 146, in _validate_sync_callables raise ValueError(f"Invalid embedding method: {e}") ValueError: Invalid embedding method: litellm.RateLimitError: GeminiException - 429 ERROR: Application startup failed. Exiting.

Expected behavior

LiteLLM should catch this error, log a warning, disable the cache, and continue starting normally. Model requests should be unaffected.

Suggested fix location: litellm/proxy/proxy_server.py _init_cache() method:

def _init_cache(self, cache_params):
    try:
        litellm.cache = Cache(**cache_params)
    except Exception as e:
        verbose_proxy_logger.warning(
            f"Cache init failed ({e}) — starting without cache"
        )
        litellm.cache = None

Environment

  • LiteLLM version: (check docker exec beo-litellm litellm --version)
  • Cache type: redis-semantic
  • Embedding model: gemini/gemini-embedding-001
  • Trigger: Gemini API spend cap exceeded during startup validation

Impact

Any temporary API quota or cap event makes the proxy unbootable until the issue is manually resolved, causing full downstream outage.

extent analysis

TL;DR

Catch and handle the ValueError exception in the _init_ method of redis_semantic_cache.py to prevent LiteLLM from exiting when the embedding model returns an error.

Guidance

  • Modify the _init_ method in redis_semantic_cache.py to catch and handle the ValueError exception, logging a warning and disabling the cache if necessary.
  • Verify that the litellm/proxy/proxy_server.py _init_cache() method is correctly handling cache initialization exceptions and logging warnings.
  • Consider adding a retry mechanism for cache initialization to handle temporary errors.
  • Review the error handling in CustomTextVectorizer to ensure it is properly propagating exceptions.

Example

try:
    cache_vectorizer = CustomTextVectorizer(self._get_embedding)
except ValueError as e:
    verbose_proxy_logger.warning(f"Cache vectorizer init failed ({e}) — disabling cache")
    # Disable cache and continue startup

Notes

The provided fix location suggests modifying the _init_cache() method in litellm/proxy/proxy_server.py, but the actual issue seems to be in the _init_ method of redis_semantic_cache.py. Ensure that the correct method is being modified.

Recommendation

Apply workaround: Modify the _init_ method in redis_semantic_cache.py to catch and handle the ValueError exception, as this will allow LiteLLM to continue starting up even if the cache initialization fails.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

LiteLLM should catch this error, log a warning, disable the cache, and continue starting normally. Model requests should be unaffected.

Suggested fix location: litellm/proxy/proxy_server.py _init_cache() method:

def _init_cache(self, cache_params):
    try:
        litellm.cache = Cache(**cache_params)
    except Exception as e:
        verbose_proxy_logger.warning(
            f"Cache init failed ({e}) — starting without cache"
        )
        litellm.cache = None

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

litellm - ✅(Solved) Fix RedisSemanticCache init failure should degrade gracefully instead of crashing proxy [1 pull requests, 1 participants]