BerriAI/litellm · error · ValueError
cost_per_ptu_per_hour must be a finite number between 0 and
Error message
cost_per_ptu_per_hour must be a finite number between 0 and {self.MAX_COST_PER_PTU_PER_HOUR} What it means
Model validator _validate_ptu_bounds on ModelInfo: cost_per_ptu_per_hour was supplied but is negative, exceeds MAX_COST_PER_PTU_PER_HOUR, or is non-finite (NaN/inf). Enforced so PTU cost math cannot produce nonsense spend values.
Source
Thrown at litellm/types/router.py:203
# router-wide default.
enable_tag_filtering: bool | None = None
def __init__(self, id: str | int | None = None, **params) -> None:
if id is None:
id = str(uuid.uuid4()) # Generate a UUID if id is None or not provided
elif isinstance(id, int):
id = str(id)
super().__init__(id=id, **params)
@model_validator(mode="after")
def _validate_ptu_bounds(self) -> "ModelInfo":
if self.ptu_count is not None and not 0 < self.ptu_count <= self.MAX_PTU_COUNT:
raise ValueError(f"ptu_count must be a positive integer no greater than {self.MAX_PTU_COUNT}")
if (
self.cost_per_ptu_per_hour is not None
and not 0 <= self.cost_per_ptu_per_hour <= self.MAX_COST_PER_PTU_PER_HOUR
):
raise ValueError(
f"cost_per_ptu_per_hour must be a finite number between 0 and {self.MAX_COST_PER_PTU_PER_HOUR}"
)
start: Final = _as_utc(self.ptu_effective_from)
end: Final = _as_utc(self.ptu_effective_to)
if start is not None and end is not None and end <= start:
raise ValueError("ptu_effective_to must be after ptu_effective_from")
return self
model_config = ConfigDict(extra="allow")
def __contains__(self, key) -> bool:
# Define custom behavior for the 'in' operator
return hasattr(self, key)
def get(self, key, default=None):
# Custom .get() method to access attributes with a default value if the attribute doesn't exist
return getattr(self, key, default)
View on GitHub (pinned to 77b7c6c40c)
Solutions
- Set cost_per_ptu_per_hour to a finite number within [0, {self.MAX_COST_PER_PTU_PER_HOUR}]; avoid NaN/inf.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at litellm/types/router.py:203 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/71b7175f76955da8.
Report an issue: GitHub.