BerriAI/litellm · warning · HTTPException
Discount for {provider} must be between 0 and 1 (0% to 100%)
Error message
Discount for {provider} must be between 0 and 1 (0% to 100%) What it means
Validation error (HTTP 400) from PATCH /config/cost_discount_config: each discount must satisfy 0 <= discount <= 1, where 1 means a 100% discount. Values outside that range (negative, or > 1 like 10 meaning '10%') are rejected.
Source
Thrown at litellm/proxy/management_endpoints/cost_tracking_settings.py:231
invalid_providers: Final = []
for provider in cost_discount_config:
if 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. See https://docs.litellm.ai/docs/providers for the full list."
},
)
# Validate discount values are between 0 and 1
for provider, discount in cost_discount_config.items():
if not isinstance(discount, (int, float)):
raise HTTPException(status_code=400, detail=f"Discount for {provider} must be a number")
if not (0 <= discount <= 1):
raise HTTPException(
status_code=400,
detail=f"Discount for {provider} must be between 0 and 1 (0% to 100%)",
)
try:
# Load existing config
config: Final = await proxy_config.get_config()
# Ensure litellm_settings exists
if "litellm_settings" not in config:
config["litellm_settings"] = {}
# Update cost_discount_config
config["litellm_settings"]["cost_discount_config"] = cost_discount_config
# Save the updated config to DB
await proxy_config.save_config(new_config=config)
View on GitHub (pinned to 77b7c6c40c)
Solutions
- Convert percentages to decimals: 10% -> 0.10, 50% -> 0.5.
- Ensure the value is >= 0 and <= 1.
- Double-check upstream config tooling doesn't multiply/divide by 100.
Example fix
# before
{"openai": 10} # 400 must be between 0 and 1
# after
{"openai": 0.10} Defensive patterns
Strategy: validation
Validate before calling
for provider, discount in cost_discount_config.items():
if not (0 <= discount <= 1):
raise ValueError(
f"{provider}: discount {discount} outside [0,1]; express 10% as 0.10"
) Prevention
- Standardize on decimal fractions (0.10 = 10%) across all cost config tooling.
- Add unit checks on generated configs asserting 0 <= v <= 1.
- Document the unit next to every discount field in your internal schemas.
When it happens
Trigger: Sending whole-percent values (10 for 10%) instead of the decimal fraction 0.10; sending a negative discount; sending 1.5 thinking it means 150% off.
Common situations: Misreading the units — the API uses fractional multipliers, not percent; porting configs from systems that express percent as integers.
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
- Margin percentage for {provider} must be between 0 and 10 (0
- 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/8fe28e43c3f9f4c9.
Report an issue: GitHub.