{"record":{"id":"121bd5c0f13fa85a","repo":"BerriAI/litellm","slug":"failed-to-update-cost-discount-config-e","errorCode":null,"errorMessage":"Failed to update cost discount config: {e}","messagePattern":"Failed to update cost discount config: (.+?)","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"litellm/proxy/management_endpoints/cost_tracking_settings.py","lineNumber":262,"sourceCode":"        # Update cost_discount_config\n        config[\"litellm_settings\"][\"cost_discount_config\"] = cost_discount_config\n\n        # Save the updated config to DB\n        await proxy_config.save_config(new_config=config)\n\n        # Update in-memory litellm.cost_discount_config\n        litellm.cost_discount_config = cost_discount_config\n\n        verbose_proxy_logger.info(\"Updated cost_discount_config: %s\", cost_discount_config)\n\n        return {\n            \"message\": \"Cost discount configuration updated successfully\",\n            \"status\": \"success\",\n            \"values\": cost_discount_config,\n        }\n    except Exception as e:\n        verbose_proxy_logger.error(\"Error updating cost discount config: %s\", e)\n        raise HTTPException(\n            status_code=500,\n            detail={\"error\": f\"Failed to update cost discount config: {e}\"},\n        )\n\n\n@router.get(\n    \"/config/cost_margin_config\",\n    tags=[\"Cost Tracking\"],\n    dependencies=[Depends(user_api_key_auth)],\n)\nasync def get_cost_margin_config(\n    user_api_key_dict: UserAPIKeyAuth = Depends(user_api_key_auth),\n):\n    \"\"\"\n    Get current cost margin configuration.\n\n    Returns the cost_margin_config from litellm_settings.\n    \"\"\"","sourceCodeStart":244,"sourceCodeEnd":280,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/proxy/management_endpoints/cost_tracking_settings.py#L244-L280","documentation":"Catch-all HTTP 500 from PATCH /config/cost_discount_config: after all validation passed, the endpoint loads the config via proxy_config.get_config(), mutates litellm_settings, saves back to the DB, and updates litellm.cost_discount_config in memory; if any of those steps raises, the exception is logged ('Error updating cost discount config') and re-raised wrapped in this message with the original error text.","triggerScenarios":"Prisma errors while writing the config row (DB restarted mid-request, connection dropped, permissions); malformed existing config in DB causing serialization/merge failures; transient failures in proxy_config.save_config.","commonSituations":"Database connectivity blips during the write; a previously corrupted config JSON in the config table; concurrent config mutations racing each other.","solutions":["Read the appended original exception ({e}) in the response and the verbose_proxy_logger line — it names the real cause.","If it is a DB error, verify PostgreSQL health/connectivity and retry the PATCH.","Inspect the stored config row (config table / GET /config/list) for corruption and repair it before re-applying.","Retry once after the transient condition clears; the update is not applied if the exception occurred before save."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    r = requests.patch(f\"{PROXY_URL}/config/cost_discount_config\", json=payload, headers=HDRS, timeout=15)\n    r.raise_for_status()\nexcept requests.HTTPError as e:\n    detail = e.response.json().get(\"detail\", {}).get(\"error\", \"\")\n    if e.response.status_code == 500 and \"Failed to update cost discount config\" in detail:\n        log.error(\"proxy-side failure: %s\", detail)  # detail embeds the root cause\n        verify_state_with_get()  # confirm old config still active, then decide retry\n    else:\n        raise","preventionTips":["Treat the 500 detail's embedded exception as the diagnosis — parse and log it.","Confirm DB health before retrying; the failure is usually persistence-side.","Fetch GET /config/cost_discount_config after any 500 to know the actual applied state."],"tags":["litellm-proxy","database","cost-tracking","internal-error"],"backgroundTag":"config-update-failed","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}