{"record":{"id":"df3a6824c591e96a","repo":"BerriAI/litellm","slug":"fixed-margin-amount-for-provider-must-be-a-numbe","errorCode":null,"errorMessage":"Fixed margin amount for {provider} must be a number","messagePattern":"Fixed margin amount for (.+?) must be a number","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"warning","filePath":"litellm/proxy/management_endpoints/cost_tracking_settings.py","lineNumber":390,"sourceCode":"                )\n        elif isinstance(margin_value, dict):\n            # Complex format: {\"percentage\": 0.08, \"fixed_amount\": 0.0005}\n            if \"percentage\" in margin_value:\n                percentage = margin_value[\"percentage\"]\n                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            )","sourceCodeStart":372,"sourceCodeEnd":408,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/proxy/management_endpoints/cost_tracking_settings.py#L372-L408","documentation":"Validation error (HTTP 400) from PATCH /config/cost_margin_config in the complex dict format: the optional 'fixed_amount' field is present but is not an int/float. fixed_amount is an absolute dollar surcharge added per request, so it must be a bare number.","triggerScenarios":"Sending {\"fixed_amount\": \"0.001\"} (string), null, or a list; template/env-driven values that arrive as strings.","commonSituations":"Currency values pasted as strings from billing configs; JSON built via string templates where every value is quoted.","solutions":["Send fixed_amount as a bare number: {\"fixed_amount\": 0.001}.","Cast with float() when constructing payloads from string sources.","Omit the key if you don't want a fixed component."],"exampleFix":"# before\n{\"openai\": {\"fixed_amount\": \"0.001\"}}\n\n# after\n{\"openai\": {\"fixed_amount\": 0.001}}","handlingStrategy":"type-guard","validationCode":"for provider, margin in cost_margin_config.items():\n    if isinstance(margin, dict) and \"fixed_amount\" in margin:\n        fa = margin[\"fixed_amount\"]\n        if isinstance(fa, str):\n            margin[\"fixed_amount\"] = fa = float(fa)\n        assert isinstance(fa, (int, float)) and not isinstance(fa, bool), f\"{provider}.fixed_amount must be numeric\"","typeGuard":"def is_valid_fixed_amount(m: dict) -> bool:\n    return \"fixed_amount\" not in m or (\n        isinstance(m[\"fixed_amount\"], (int, float))\n        and not isinstance(m[\"fixed_amount\"], bool)\n        and m[\"fixed_amount\"] >= 0\n    )","tryCatchPattern":null,"preventionTips":["Monetary values are bare numbers in USD-per-request units.","Reject stringified currency amounts at the config-source layer."],"tags":["litellm-proxy","validation","type-error","cost-tracking"],"backgroundTag":"type-validation-failed","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}