{"record":{"id":"61c19286c2126d0d","repo":"BerriAI/litellm","slug":"fixed-margin-amount-for-provider-must-be-non-neg","errorCode":null,"errorMessage":"Fixed margin amount for {provider} must be non-negative","messagePattern":"Fixed margin amount for (.+?) must be non-negative","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"warning","filePath":"litellm/proxy/management_endpoints/cost_tracking_settings.py","lineNumber":395,"sourceCode":"                if not isinstance(percentage, (int, float)):\n                    raise HTTPException(\n                        status_code=400,\n                        detail=f\"Margin percentage for {provider} must be a number\",\n                    )\n                if not (0 <= percentage <= 10):\n                    raise HTTPException(\n                        status_code=400,\n                        detail=f\"Margin percentage for {provider} must be between 0 and 10 (0% to 1000%)\",\n                    )\n            if \"fixed_amount\" in margin_value:\n                fixed_amount = margin_value[\"fixed_amount\"]\n                if not isinstance(fixed_amount, (int, float)):\n                    raise HTTPException(\n                        status_code=400,\n                        detail=f\"Fixed margin amount for {provider} must be a number\",\n                    )\n                if fixed_amount < 0:\n                    raise HTTPException(\n                        status_code=400,\n                        detail=f\"Fixed margin amount for {provider} must be non-negative\",\n                    )\n            if not margin_value:  # Empty dict\n                raise HTTPException(\n                    status_code=400,\n                    detail=f\"Margin config for {provider} cannot be empty. Must include 'percentage' and/or 'fixed_amount'\",\n                )\n        else:\n            raise HTTPException(\n                status_code=400,\n                detail=f\"Margin for {provider} must be a number (percentage) or dict with 'percentage' and/or 'fixed_amount'\",\n            )\n\n    try:\n        # Load existing config\n        config: Final = await proxy_config.get_config()\n","sourceCodeStart":377,"sourceCodeEnd":413,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/proxy/management_endpoints/cost_tracking_settings.py#L377-L413","documentation":"Validation error (HTTP 400) from PATCH /config/cost_margin_config in the complex dict format: 'fixed_amount' is a number but negative. A margin surcharge cannot reduce cost, so LiteLLM requires fixed_amount >= 0 (0 is allowed, meaning no fixed component).","triggerScenarios":"Sending {\"fixed_amount\": -0.001} to try to model a discount; sign errors from spreadsheet exports or arithmetic that produced a negative surcharge.","commonSituations":"Trying to express provider discounts through the margin API instead of cost_discount_config; copy-paste sign mistakes.","solutions":["Use a non-negative fixed_amount; remove the key or set 0 if not needed.","Model discounts with PATCH /config/cost_discount_config instead, which is the designed mechanism.","Validate the sign of computed markups in your config pipeline."],"exampleFix":"# before\n{\"openai\": {\"fixed_amount\": -0.001}}\n\n# after\n{\"openai\": {\"fixed_amount\": 0.001}}","handlingStrategy":"validation","validationCode":"for provider, margin in cost_margin_config.items():\n    if isinstance(margin, dict):\n        fa = margin.get(\"fixed_amount\")\n        if fa is not None and fa < 0:\n            raise ValueError(f\"{provider}: fixed_amount must be >= 0; use cost_discount_config for discounts\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Margins only add cost; use the discount config endpoint to reduce it.","Assert non-negative values for every monetary field in your schema."],"tags":["litellm-proxy","validation","range-error","cost-tracking"],"backgroundTag":"value-out-of-range","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}