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

Thrown by PATCH /config/cost_discount_config when a Prisma DB is connected but store_model_in_db is not True. Because this endpoint writes model-level settings back into the database-backed config store, LiteLLM gates it behind the explicit STORE_MODEL_IN_DB=True opt-in flag to prevent accidental writes to the DB config. Returns HTTP 500 with the literal message about the env var (note the message's stray quotes: STORE_MODEL_IN_DB=True).

Source

Thrown at litellm/proxy/management_endpoints/cost_tracking_settings.py:207

        "gemini": 0.05,
        "openai": 0.01
    }
    ```
    """
    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": CommonProxyErrors.db_not_connected_error.value},
        )

    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."},
        )

    # Validate that all providers are valid LiteLLM providers
    invalid_providers: Final = []
    for provider in cost_discount_config:
        if provider not in LlmProvidersSet:
            invalid_providers.append(provider)

    if invalid_providers:
        raise HTTPException(
            status_code=400,
            detail={
                "error": f"Invalid provider(s): {', '.join(invalid_providers)}. Must be valid LiteLLM providers. See https://docs.litellm.ai/docs/providers for the full list."
            },
        )

View on GitHub (pinned to 77b7c6c40c)

Solutions

  1. Set STORE_MODEL_IN_DB=True in the proxy environment (export STORE_MODEL_IN_DB=True) or under general_settings in the config, and restart.
  2. Verify with a GET /config/cost_discount_config call that the guard now passes before PATCHing.
  3. Keep managing cost discounts in the YAML litellm_settings if you deliberately do not want DB-stored model settings.

Example fix

# before
export DATABASE_URL=postgresql://...
# STORE_MODEL_IN_DB unset -> 500

# after
export DATABASE_URL=postgresql://...
export STORE_MODEL_IN_DB=True
Defensive patterns

Strategy: validation

Validate before calling

import os
assert os.getenv("STORE_MODEL_IN_DB") == "True", (
    "Set STORE_MODEL_IN_DB=True before using /config/cost_discount_config"
)

Try / catch

try:
    r = requests.patch(f"{PROXY_URL}/config/cost_discount_config", json=payload, headers=HDRS)
    r.raise_for_status()
except requests.HTTPError as e:
    if "STORE_MODEL_IN_DB" in e.response.text:
        raise RuntimeError("Proxy env missing STORE_MODEL_IN_DB=True; restart proxy with it set")
    raise

Prevention

When it happens

Trigger: PATCH /config/cost_discount_config on a proxy that has DATABASE_URL set but where STORE_MODEL_IN_DB was left unset or set to something other than True (e.g. 'true' lowercase in some deployments may work via env parsing, but False/absent does not).

Common situations: Enabling the DB for virtual keys but forgetting this second flag; setting STORE_MODEL_IN_DB in the YAML under the wrong section instead of env/general_settings; running an older config template that predates the flag.

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


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