BerriAI/litellm · warning · HTTPException
Fixed margin amount for {provider} must be non-negative
Error message
Fixed margin amount for {provider} must be non-negative What it means
Validation error (HTTP 400) from PATCH /config/cost_margin_config in the complex dict format: 'fixed_amount' is a number but negative. A margin surcharge cannot reduce cost, so LiteLLM requires fixed_amount >= 0 (0 is allowed, meaning no fixed component).
Source
Thrown at litellm/proxy/management_endpoints/cost_tracking_settings.py:395
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:
fixed_amount = margin_value["fixed_amount"]
if not isinstance(fixed_amount, (int, float)):
raise HTTPException(
status_code=400,
detail=f"Fixed margin amount for {provider} must be a number",
)
if fixed_amount < 0:
raise HTTPException(
status_code=400,
detail=f"Fixed margin amount for {provider} must be non-negative",
)
if not margin_value: # Empty dict
raise HTTPException(
status_code=400,
detail=f"Margin config for {provider} cannot be empty. Must include 'percentage' and/or 'fixed_amount'",
)
else:
raise HTTPException(
status_code=400,
detail=f"Margin for {provider} must be a number (percentage) or dict with 'percentage' and/or 'fixed_amount'",
)
try:
# Load existing config
config: Final = await proxy_config.get_config()
View on GitHub (pinned to 77b7c6c40c)
Solutions
- Use a non-negative fixed_amount; remove the key or set 0 if not needed.
- Model discounts with PATCH /config/cost_discount_config instead, which is the designed mechanism.
- Validate the sign of computed markups in your config pipeline.
Example fix
# before
{"openai": {"fixed_amount": -0.001}}
# after
{"openai": {"fixed_amount": 0.001}} Defensive patterns
Strategy: validation
Validate before calling
for provider, margin in cost_margin_config.items():
if isinstance(margin, dict):
fa = margin.get("fixed_amount")
if fa is not None and fa < 0:
raise ValueError(f"{provider}: fixed_amount must be >= 0; use cost_discount_config for discounts") Prevention
- Margins only add cost; use the discount config endpoint to reduce it.
- Assert non-negative values for every monetary field in your schema.
When it happens
Trigger: Sending {"fixed_amount": -0.001} to try to model a discount; sign errors from spreadsheet exports or arithmetic that produced a negative surcharge.
Common situations: Trying to express provider discounts through the margin API instead of cost_discount_config; copy-paste sign mistakes.
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%)
- Margin percentage for {provider} must be between 0 and 10 (0
- 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/61c19286c2126d0d.
Report an issue: GitHub.