{"record":{"id":"82987ccace73a890","repo":"BerriAI/litellm","slug":"missing-required-redis-configuration-missing-var","errorCode":null,"errorMessage":"Missing required Redis configuration: {missing_var}. Provide {missing_var} or redis_url.","messagePattern":"Missing required Redis configuration: (.+?)\\. Provide (.+?) or redis_url\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/caching/redis_semantic_cache.py","lineNumber":100,"sourceCode":"        self.similarity_threshold = similarity_threshold\n\n        # Convert similarity threshold [0,1] to distance threshold [0,2]\n        # For cosine distance: 0 = most similar, 2 = least similar\n        # While similarity: 1 = most similar, 0 = least similar\n        self.distance_threshold = 1 - similarity_threshold\n        self.embedding_model = embedding_model\n\n        # Set up Redis connection\n        if redis_url is None:\n            try:\n                # Attempt to use provided parameters or fallback to environment variables\n                host = host or os.environ[\"REDIS_HOST\"]\n                port = port or os.environ[\"REDIS_PORT\"]\n                password = password or os.environ[\"REDIS_PASSWORD\"]\n            except KeyError as e:\n                # Raise a more informative exception if any of the required keys are missing\n                missing_var: Final = e.args[0]\n                raise ValueError(\n                    f\"Missing required Redis configuration: {missing_var}. Provide {missing_var} or redis_url.\"\n                ) from e\n\n            redis_url = f\"redis://:{password}@{host}:{port}\"\n\n        print_verbose(f\"Redis semantic-cache redis_url: {redis_url}\")\n\n        # Defer redisvl index construction until first use. redisvl's\n        # CustomTextVectorizer eagerly embeds a probe string at construction;\n        # building lazily ensures that probe runs after llm_router is wired so\n        # per-deployment auth (e.g. Bedrock aws_role_name) is applied.\n        self._index_name = index_name\n        self._redis_url = redis_url\n        self._llmcache = None\n\n    @property\n    def llmcache(self) -> object:\n        if getattr(self, \"_llmcache\", None) is None:","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/caching/redis_semantic_cache.py#L82-L118","documentation":"When no redis_url is given, the Redis semantic cache builds one from host/port/password, falling back to the REDIS_HOST, REDIS_PORT and REDIS_PASSWORD environment variables. If any one of them is missing from both kwargs and the environment, the KeyError is caught and re-raised as a ValueError naming the first missing variable. This is purely a configuration-resolution failure at construction time.","triggerScenarios":"Constructing RedisSemanticCache with neither redis_url nor complete host+port+password, where at least one of REDIS_HOST/REDIS_PORT/REDIS_PASSWORD is unset in the environment. The message tells you exactly which variable was missing first.","commonSituations":"REDIS_PASSWORD unset on a passwordless local Redis (the code still requires the env var); env vars present in dev shell but absent in the container/systemd unit; typo like REDIS_ENDPOINT instead of REDIS_HOST.","solutions":["Simplest: pass redis_url directly, e.g. RedisSemanticCache(redis_url='redis://:password@host:6379', similarity_threshold=0.8)","Or export all three variables: REDIS_HOST, REDIS_PORT, REDIS_PASSWORD (set REDIS_PASSWORD='' only if explicitly provided — the code requires the key to exist)","Check the variable named in the error message and add it to the deployment environment (Docker env, k8s secret, .env actually loaded)"],"exampleFix":"# before\nos.environ['REDIS_HOST'] = 'localhost'  # PORT, PASSWORD missing\ncache = RedisSemanticCache(similarity_threshold=0.8)\n\n# after\ncache = RedisSemanticCache(similarity_threshold=0.8,\n                           redis_url='redis://:mypassword@localhost:6379')","handlingStrategy":"validation","validationCode":"import os\n\ndef resolve_redis_url(cfg: dict) -> str:\n    if cfg.get('redis_url'):\n        return cfg['redis_url']\n    missing = [v for v in ('REDIS_HOST', 'REDIS_PORT', 'REDIS_PASSWORD') if not os.environ.get(v)]\n    if missing or not (cfg.get('host') and cfg.get('port')):\n        raise ValueError(f'Provide redis_url, or host/port/password args, or set {missing}')\n    return f\"redis://:{cfg.get('password') or os.environ['REDIS_PASSWORD']}@{cfg.get('host') or os.environ['REDIS_HOST']}:{cfg.get('port') or os.environ['REDIS_PORT']}\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pass redis_url explicitly instead of relying on three separate env vars","Check env var presence in deployment manifests (k8s envFrom, docker --env-file)"],"tags":["redis","semantic-cache","environment","configuration"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}