BerriAI/litellm · warning · HTTPException
Margin percentage for {provider} must be between 0 and 10 (0
Error message
Margin percentage for {provider} must be between 0 and 10 (0% to 1000%) What it means
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.
Source
Thrown at litellm/proxy/management_endpoints/cost_tracking_settings.py:369
invalid_providers: Final = []
for provider in cost_margin_config:
if provider != "global" and provider not in LlmProvidersSet:
invalid_providers.append(provider)
if invalid_providers:
raise HTTPException(
status_code=400,
detail={
"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."
},
)
# Validate margin values
for provider, margin_value in cost_margin_config.items():
if isinstance(margin_value, (int, float)):
# Simple percentage format: {"openai": 0.10}
if not (0 <= margin_value <= 10): # Allow up to 1000% margin
raise HTTPException(
status_code=400,
detail=f"Margin percentage for {provider} must be between 0 and 10 (0% to 1000%)",
)
elif isinstance(margin_value, dict):
# Complex format: {"percentage": 0.08, "fixed_amount": 0.0005}
if "percentage" in margin_value:
percentage = margin_value["percentage"]
if not isinstance(percentage, (int, float)):
raise HTTPException(
status_code=400,
detail=f"Margin percentage for {provider} must be a number",
)
if not (0 <= percentage <= 10):
raise HTTPException(
status_code=400,
detail=f"Margin percentage for {provider} must be between 0 and 10 (0% to 1000%)",
)
if "fixed_amount" in margin_value:View on GitHub (pinned to 77b7c6c40c)
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.
Example fix
# before
{"openai": 8} # 400 must be between 0 and 10
# after
{"openai": 0.08} Defensive patterns
Strategy: validation
Validate before calling
for provider, margin in cost_margin_config.items():
if isinstance(margin, (int, float)) and not (0 <= margin <= 10):
raise ValueError(f"{provider}: margin {margin} outside [0,10]; 8% is 0.08") Prevention
- Margins are decimal fractions with a 10.0 (1000%) ceiling.
- Separate percentage margins from absolute surcharges in your config schema to avoid unit mixing.
When it happens
Trigger: Sending 8.0 meaning '8% margin' (should be 0.08); sending a negative margin to model a loss; sending >10 for extreme markups.
Common situations: 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.
Understand the failure class
Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.
Related errors
- Discount for {provider} must be between 0 and 1 (0% to 100%)
- Fixed margin amount for {provider} must be non-negative
- Invalid provider(s): {', '.join(invalid_providers)}. Must be
- Discount for {provider} must be a number
- Invalid provider(s): {', '.join(invalid_providers)}. Must be
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/0a35d5c8234d9189.
Report an issue: GitHub.