{"record":{"id":"a9e966f9369b6cd2","repo":"BerriAI/litellm","slug":"set-store-model-in-db-true-in-your-env-to-ena-a9e966","errorCode":null,"errorMessage":"Set `'STORE_MODEL_IN_DB='True'` in your env to enable this feature.","messagePattern":"Set `'STORE_MODEL_IN_DB='True'` in your env to enable this feature\\.","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"litellm/proxy/management_endpoints/cost_tracking_settings.py","lineNumber":207,"sourceCode":"        \"gemini\": 0.05,\n        \"openai\": 0.01\n    }\n    ```\n    \"\"\"\n    from litellm.proxy.proxy_server import (\n        prisma_client,\n        proxy_config,\n        store_model_in_db,\n    )\n\n    if prisma_client is None:\n        raise HTTPException(\n            status_code=500,\n            detail={\"error\": CommonProxyErrors.db_not_connected_error.value},\n        )\n\n    if store_model_in_db is not True:\n        raise HTTPException(\n            status_code=500,\n            detail={\"error\": \"Set `'STORE_MODEL_IN_DB='True'` in your env to enable this feature.\"},\n        )\n\n    # Validate that all providers are valid LiteLLM providers\n    invalid_providers: Final = []\n    for provider in cost_discount_config:\n        if provider not in LlmProvidersSet:\n            invalid_providers.append(provider)\n\n    if invalid_providers:\n        raise HTTPException(\n            status_code=400,\n            detail={\n                \"error\": f\"Invalid provider(s): {', '.join(invalid_providers)}. Must be valid LiteLLM providers. See https://docs.litellm.ai/docs/providers for the full list.\"\n            },\n        )\n","sourceCodeStart":189,"sourceCodeEnd":225,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/proxy/management_endpoints/cost_tracking_settings.py#L189-L225","documentation":"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).","triggerScenarios":"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).","commonSituations":"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.","solutions":["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.","Verify with a GET /config/cost_discount_config call that the guard now passes before PATCHing.","Keep managing cost discounts in the YAML litellm_settings if you deliberately do not want DB-stored model settings."],"exampleFix":"# before\nexport DATABASE_URL=postgresql://...\n# STORE_MODEL_IN_DB unset -> 500\n\n# after\nexport DATABASE_URL=postgresql://...\nexport STORE_MODEL_IN_DB=True","handlingStrategy":"validation","validationCode":"import os\nassert os.getenv(\"STORE_MODEL_IN_DB\") == \"True\", (\n    \"Set STORE_MODEL_IN_DB=True before using /config/cost_discount_config\"\n)","typeGuard":null,"tryCatchPattern":"try:\n    r = requests.patch(f\"{PROXY_URL}/config/cost_discount_config\", json=payload, headers=HDRS)\n    r.raise_for_status()\nexcept requests.HTTPError as e:\n    if \"STORE_MODEL_IN_DB\" in e.response.text:\n        raise RuntimeError(\"Proxy env missing STORE_MODEL_IN_DB=True; restart proxy with it set\")\n    raise","preventionTips":["Pair DATABASE_URL with STORE_MODEL_IN_DB=True in the same deployment manifest.","Add a startup assertion in deploy scripts for both env vars.","Remember the flag is checked as the literal True — document it exactly."],"tags":["litellm-proxy","env-var","cost-tracking","config"],"backgroundTag":"missing-env-var","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}