litellm/litellm/models/end_user.py
Yusuf Efe c9ce9a733d
fix(proxy): allow model instances in LiteLLM_EndUserTable validation (#41677)
* fix(proxy): allow model instances in LiteLLM_EndUserTable validation

* fix(proxy): preserve property-backed attributes when coercing spend

* refactor(proxy): default null end-user spend with a field validator

* fix(proxy): drop model-wide from_attributes from the end-user table

* test(proxy): unskip the /customer/block integration contracts

---------

Co-authored-by: mateo-berri <277851410+mateo-berri@users.noreply.github.com>
2026-10-15 10:57:26 -07:00

35 lines
1.1 KiB
Python

"""
End-user table model.
Canonical definition for ``litellm_endusertable``. Re-exported from
``litellm.proxy._types`` for backwards compatibility.
"""
from typing import Literal
from pydantic import ConfigDict, Field, field_validator
from litellm.models.budget import LiteLLM_BudgetTable
from litellm.models.object_permission import LiteLLM_ObjectPermissionTable
from litellm.types.llms.base import LiteLLMPydanticObjectBase
class LiteLLM_EndUserTable(LiteLLMPydanticObjectBase):
user_id: str
blocked: bool
alias: str | None = None
spend: float = 0.0
allowed_model_region: Literal["eu", "us"] | None = None
default_model: str | None = None
models: list[str] = Field(default_factory=list)
budget_id: str | None = None
litellm_budget_table: LiteLLM_BudgetTable | None = None
object_permission_id: str | None = None
object_permission: LiteLLM_ObjectPermissionTable | None = None
@field_validator("spend", mode="before")
@classmethod
def default_null_spend_to_zero(cls, spend: object) -> object:
return 0.0 if spend is None else spend
model_config = ConfigDict(protected_namespaces=())