The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
refactor(types): annotate key request containers and drop_blank_team_id (#45809)
nate-berri2374b0c39886
diff --git a/litellm/proxy/_types.py b/litellm/proxy/_types.pyindex 7ac8b1f8538..9ee20c22cef 100644--- a/litellm/proxy/_types.py+++ b/litellm/proxy/_types.py@@ -1243,8 +1243,8 @@ class KeyRequestBase(GenerateRequestBase):enable_prompt_caching: bool | None = Nonethrottle_on_budget_exceeded: bool | None = Noneenforced_params: list[str] | None = None- allowed_routes: list | None = []- allowed_passthrough_routes: list | None = None+ allowed_routes: list[Any] | None = []+ allowed_passthrough_routes: list[object] | None = Nonedenied_passthrough_routes: list[str] | None = Noneallowed_vector_store_indexes: list[AllowedVectorStoreIndexItem] | None = Nonerpm_limit_type: Literal["guaranteed_throughput", "best_effort_throughput", "dynamic"] | None = (@@ -1333,13 +1333,17 @@ class GenerateKeyResponse(KeyRequestBase):return values+def _is_mapping(value: object) -> TypeIs[Mapping[object, object]]: # guard-ok: raw before-validator payload+ return isinstance(value, Mapping)++class UpdateKeyRequest(KeyRequestBase):# Note: the defaults of all Params here MUST BE NONE# else they will get overwrittenduration: str | None = Nonespend: float | None = Nonesoft_budget: float | None = None- metadata: dict | None = None+ metadata: dict[Any, Any] | None = Nonetemp_budget_increase: float | None = Nonetemp_budget_expiry: datetime | None = Noneauto_rotate: bool | None = None@@ -1354,7 +1358,7 @@ class UpdateKeyRequest(KeyRequestBase):@model_validator(mode="before")@classmethoddef drop_blank_team_id(cls, values: object) -> object:- if isinstance(values, Mapping) and values.get("team_id") == "":+ if _is_mapping(values) and values.get("team_id") == "":return MappingProxyType({k: v for k, v in values.items() if k != "team_id"})return values@@ -1385,7 +1389,7 @@ class RegenerateKeyRequest(GenerateKeyRequest):new_key: str | None = Noneduration: str | None = Nonespend: float | None = None- metadata: dict | None = None+ metadata: dict[Any, Any] | None = Nonenew_master_key: str | None = Nonegrace_period: str | None = None # Duration to keep old key valid (e.g. "24h", "2d"); None = immediate revoke