{"record":{"id":"b69d64083dcb517d","repo":"BerriAI/litellm","slug":"margin-config-for-provider-cannot-be-empty-must","errorCode":null,"errorMessage":"Margin config for {provider} cannot be empty. Must include 'percentage' and/or 'fixed_amount'","messagePattern":"Margin config for (.+?) cannot be empty\\. Must include 'percentage' and/or 'fixed_amount'","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"warning","filePath":"litellm/proxy/management_endpoints/cost_tracking_settings.py","lineNumber":400,"sourceCode":"                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\n        # Ensure litellm_settings exists\n        if \"litellm_settings\" not in config:\n            config[\"litellm_settings\"] = {}\n\n        # Update cost_margin_config","sourceCodeStart":382,"sourceCodeEnd":418,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/proxy/management_endpoints/cost_tracking_settings.py#L382-L418","documentation":"Validation error (HTTP 400) from PATCH /config/cost_margin_config: a provider's margin value is a dict but contains neither 'percentage' nor 'fixed_amount' (e.g. {} or {\"foo\": 1}). The dict format exists solely to carry those two optional keys, so an empty/irrelevant dict is rejected with a message telling you which keys are expected.","triggerScenarios":"Sending {\"openai\": {}} to 'reset' a margin (use 0 or omit the provider instead); dicts with typo'd keys like {\"pecentage\": 0.1} that therefore contain neither recognized field.","commonSituations":"Attempting to clear a provider's margin via an empty object; key typos that silently change the dict's effective content; template engines emitting {} for missing values.","solutions":["To zero out a margin, send {\"openai\": 0} or remove the key from the payload.","Ensure dict values contain at least one of 'percentage' or 'fixed_amount', spelled exactly.","Guard your payload builder against emitting empty dicts for optional fields."],"exampleFix":"# before\n{\"openai\": {}}\n\n# after\n{\"openai\": 0}","handlingStrategy":"validation","validationCode":"for provider, margin in cost_margin_config.items():\n    if isinstance(margin, dict) and not ({\"percentage\", \"fixed_amount\"} & set(margin)):\n        if margin == {}:\n            cost_margin_config[provider] = 0  # normalize 'reset' to zero-margin\n        else:\n            raise ValueError(f\"{provider}: dict must contain 'percentage' and/or 'fixed_amount'\")","typeGuard":"def is_nonempty_margin_dict(m: dict) -> bool:\n    return isinstance(m, dict) and bool({\"percentage\", \"fixed_amount\"} & set(m))","tryCatchPattern":null,"preventionTips":["Reset a margin by sending 0 or omitting the provider — never {}.","Spell-check 'percentage' and 'fixed_amount'; typo'd keys make the dict effectively empty."],"tags":["litellm-proxy","validation","cost-tracking","empty-value"],"backgroundTag":"schema-validation-failed","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}