BerriAI/litellm · error · HTTPException
Set `'STORE_MODEL_IN_DB='True'` in your env to enable this f
Error message
Set `'STORE_MODEL_IN_DB='True'` in your env to enable this feature.
What it means
Saving cache settings via POST /cache/settings additionally requires the STORE_MODEL_IN_DB feature flag: proxy_server reads it with get_secret_bool("STORE_MODEL_IN_DB", ...) and this endpoint refuses with HTTP 500 when it is not exactly True. The gate exists because settings must round-trip through the database, which is only enabled when the deployment opts into DB-stored config. The odd quoting in the message ('STORE_MODEL_IN_DB='True'') is cosmetic in the source string.
Source
Thrown at litellm/proxy/management_endpoints/cache_settings_endpoints.py:601
This endpoint:
1. Encrypts sensitive fields (passwords, etc.)
2. Saves to LiteLLM_CacheConfig table
3. Reinitializes cache with new settings
"""
from litellm.proxy.proxy_server import (
prisma_client,
proxy_config,
store_model_in_db,
)
if prisma_client is None:
raise HTTPException(
status_code=500,
detail={"error": "Database not connected. Please connect a database."},
)
if store_model_in_db is not True:
raise HTTPException(
status_code=500,
detail={"error": "Set `'STORE_MODEL_IN_DB='True'` in your env to enable this feature."},
)
try:
# Read the stored row first: its decrypted values back any credential the
# caller echoed back redacted, and its key set drives the audit diff.
existing_row: Final = await _cache_config_table(prisma_client).find_unique(where={"id": "cache_config"})
before_settings: dict[str, object] | None = None
saved_settings: dict[str, object] = {}
if existing_row is not None and existing_row.cache_settings:
before_settings = _parse_stored_settings(existing_row.cache_settings)
saved_settings = proxy_config._decrypt_db_variables(variables_dict=before_settings)
action: Final[AUDIT_ACTIONS] = "updated" if existing_row is not None else "created"
# Preserve stored secrets behind any redacted or omitted credential, then
# resolve the url-vs-discrete-fields precedence.
cache_settings: Final = _resolve_cache_url_precedence(_merge_over_saved(request.cache_settings, saved_settings))View on GitHub (pinned to 77b7c6c40c)
Solutions
- Set the env var: export STORE_MODEL_IN_DB="True" (or add it to the container/deployment env)
- Equivalently enable it in the config under general_settings: store_model_in_db: true, then restart the proxy
- Confirm both requirements hold: DATABASE_URL set AND STORE_MODEL_IN_DB=True, then retry POST /cache/settings
Example fix
# before export DATABASE_URL="postgresql://..." litellm # POST /cache/settings -> 500 Set 'STORE_MODEL_IN_DB=True' # after export DATABASE_URL="postgresql://..." export STORE_MODEL_IN_DB="True" litellm # POST /cache/settings -> 200
Defensive patterns
Strategy: validation
Validate before calling
import os
# The flag must be exactly True (string 'True' from env) on the proxy side
flag = os.getenv("STORE_MODEL_IN_DB", "False")
assert flag.lower() == "true", f"STORE_MODEL_IN_DB={flag!r}; set it to True to save cache settings" Type guard
def store_model_in_db_enabled(value: object) -> bool:
return isinstance(value, str) and value.strip().lower() == "true" Try / catch
import httpx
try:
httpx.post(f"{PROXY_URL}/cache/settings", json=settings, headers=hdrs).raise_for_status()
except httpx.HTTPStatusError as e:
if e.response.status_code == 500 and "STORE_MODEL_IN_DB" in e.response.text:
raise RuntimeError("enable STORE_MODEL_IN_DB=True on the proxy, then retry") from e
raise Prevention
- Set STORE_MODEL_IN_DB=True whenever DB-backed settings management is planned
- Beware YAML boolean vs string ('True' vs true) inconsistencies when the flag is read from secrets
When it happens
Trigger: POST /cache/settings on a proxy where DATABASE_URL is set but STORE_MODEL_IN_DB is unset/false; enabling the flag only in config but not env (or vice versa depending on how the deployment reads secrets); forgetting the flag after a redeploy.
Common situations: Standing up the Admin UI cache editor for the first time; migrations of docker-compose files that drop env entries; flag set as string "True" vs boolean in YAML causing get_secret_bool to parse false.
Understand the failure class
Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.
Related errors
- 503
- Database not connected. Please connect a database.
- LLM Router not initialized. Ensure models added to proxy.
- DB not connected. This endpoint needs a database; set DATABA
- Either 'REDIS_URL' or both 'REDIS_HOST' and 'REDIS_PORT' mus
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/dd09f26da9854979.
Report an issue: GitHub.