BerriAI/litellm · error · ValueError

either key or key_alias must be provided

Error message

either key or key_alias must be provided

What it means

Pydantic model_validator on UpdateKeyRequest rejecting an update that identifies no key: neither key nor key_alias was provided. The budget-validator shown is one of several guards on this model; this specific one fires when the request has payload fields (e.g. spend/metadata changes) but no key identifier to apply them to, making the update a no-op.

Source

Thrown at litellm/proxy/_types.py:1242

    spend: float | None = None
    metadata: dict | None = None
    temp_budget_increase: float | None = None
    temp_budget_expiry: datetime | None = None
    auto_rotate: bool | None = None
    rotation_interval: str | None = None
    organization_id: str | None = None

    @model_validator(mode="after")
    def validate_temp_budget(self) -> "UpdateKeyRequest":
        if self.temp_budget_increase is not None or self.temp_budget_expiry is not None:
            if self.temp_budget_increase is None or self.temp_budget_expiry is None:
                raise ValueError("temp_budget_increase and temp_budget_expiry must be set together")
        return self

    @model_validator(mode="after")
    def validate_key_identifier(self) -> "UpdateKeyRequest":
        if self.key is None and self.key_alias is None:
            raise ValueError("either key or key_alias must be provided")
        return self


class RegenerateKeyRequest(GenerateKeyRequest):
    # This needs to be different from UpdateKeyRequest, because "key" is optional for this
    key: str | None = None
    new_key: str | None = None
    duration: str | None = None
    spend: float | None = None
    metadata: dict | None = None
    new_master_key: str | None = None
    grace_period: str | None = None  # Duration to keep old key valid (e.g. "24h", "2d"); None = immediate revoke


class ResetSpendRequest(LiteLLMPydanticObjectBase):
    reset_to: float

View on GitHub (pinned to 77b7c6c40c)

Solutions

  1. Provide either key or key_alias in the request.

Example fix

key_alias='my-key'
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at litellm/proxy/_types.py:1242 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/4f277275ed8bfe1e. Report an issue: GitHub.