{"record":{"id":"0a35d5c8234d9189","repo":"BerriAI/litellm","slug":"margin-percentage-for-provider-must-be-between-0","errorCode":null,"errorMessage":"Margin percentage for {provider} must be between 0 and 10 (0% to 1000%)","messagePattern":"Margin percentage for (.+?) must be between 0 and 10 \\(0% to 1000%\\)","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"warning","filePath":"litellm/proxy/management_endpoints/cost_tracking_settings.py","lineNumber":369,"sourceCode":"    invalid_providers: Final = []\n    for provider in cost_margin_config:\n        if provider != \"global\" and 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 or 'global'. See https://docs.litellm.ai/docs/providers for the full list.\"\n            },\n        )\n\n    # Validate margin values\n    for provider, margin_value in cost_margin_config.items():\n        if isinstance(margin_value, (int, float)):\n            # Simple percentage format: {\"openai\": 0.10}\n            if not (0 <= margin_value <= 10):  # Allow up to 1000% margin\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        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:","sourceCodeStart":351,"sourceCodeEnd":387,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/proxy/management_endpoints/cost_tracking_settings.py#L351-L387","documentation":"Validation error (HTTP 400) from PATCH /config/cost_margin_config when a margin value uses the simple numeric format ({\"openai\": 0.10}) but the number falls outside 0..10. LiteLLM expresses margin as a decimal fraction of cost, so 10 means a 1000% margin — the documented hard ceiling; negatives are also rejected.","triggerScenarios":"Sending 8.0 meaning '8% margin' (should be 0.08); sending a negative margin to model a loss; sending >10 for extreme markups.","commonSituations":"Percent-vs-decimal unit confusion, same class of mistake as discounts but with the wider 0..10 range; porting margin tables from billing systems that use whole percentages.","solutions":["Express margins as decimal fractions: 8% -> 0.08, 100% -> 1.0.","Keep the value within 0..10 inclusive.","If you need a per-request surcharge rather than a percentage, use the dict format with fixed_amount."],"exampleFix":"# before\n{\"openai\": 8}   # 400 must be between 0 and 10\n\n# after\n{\"openai\": 0.08}","handlingStrategy":"validation","validationCode":"for provider, margin in cost_margin_config.items():\n    if isinstance(margin, (int, float)) and not (0 <= margin <= 10):\n        raise ValueError(f\"{provider}: margin {margin} outside [0,10]; 8% is 0.08\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Margins are decimal fractions with a 10.0 (1000%) ceiling.","Separate percentage margins from absolute surcharges in your config schema to avoid unit mixing."],"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"}