diff --git a/litellm/proxy/_types.py b/litellm/proxy/_types.py index 973503d0a5..f6fd1a4b86 100644 --- a/litellm/proxy/_types.py +++ b/litellm/proxy/_types.py @@ -610,6 +610,8 @@ class GenerateKeyResponse(KeyRequestBase): token_id: Optional[str] = None litellm_budget_table: Optional[Any] = None token: Optional[str] = None + created_by: Optional[str] = None + updated_by: Optional[str] = None @model_validator(mode="before") @classmethod @@ -1387,7 +1389,9 @@ class LiteLLM_VerificationToken(LiteLLMPydanticObjectBase): litellm_budget_table: Optional[dict] = None org_id: Optional[str] = None # org id for a given key created_at: Optional[datetime] = None + created_by: Optional[str] = None updated_at: Optional[datetime] = None + updated_by: Optional[str] = None model_config = ConfigDict(protected_namespaces=()) diff --git a/litellm/proxy/management_endpoints/key_management_endpoints.py b/litellm/proxy/management_endpoints/key_management_endpoints.py index 0352a81cd5..1d9d790282 100644 --- a/litellm/proxy/management_endpoints/key_management_endpoints.py +++ b/litellm/proxy/management_endpoints/key_management_endpoints.py @@ -518,6 +518,10 @@ async def generate_key_fn( # noqa: PLR0915 if "budget_duration" in data_json: data_json["key_budget_duration"] = data_json.pop("budget_duration", None) + if user_api_key_dict.user_id is not None: + data_json["created_by"] = user_api_key_dict.user_id + data_json["updated_by"] = user_api_key_dict.user_id + # Set tags on the new key if "tags" in data_json: from litellm.proxy.proxy_server import premium_user @@ -1122,6 +1126,8 @@ async def generate_key_helper_fn( # noqa: PLR0915 organization_id: Optional[str] = None, table_name: Optional[Literal["key", "user"]] = None, send_invite_email: Optional[bool] = None, + created_by: Optional[str] = None, + updated_by: Optional[str] = None, ): from litellm.proxy.proxy_server import ( litellm_proxy_budget_name, @@ -1225,6 +1231,8 @@ async def generate_key_helper_fn( # noqa: PLR0915 "model_max_budget": model_max_budget_json, "budget_id": budget_id, "blocked": blocked, + "created_by": created_by, + "updated_by": updated_by, } if ( diff --git a/litellm/proxy/schema.prisma b/litellm/proxy/schema.prisma index a09ef97009..fedbb271da 100644 --- a/litellm/proxy/schema.prisma +++ b/litellm/proxy/schema.prisma @@ -161,7 +161,9 @@ model LiteLLM_VerificationToken { budget_id String? organization_id String? created_at DateTime? @default(now()) @map("created_at") + created_by String? updated_at DateTime? @default(now()) @updatedAt @map("updated_at") + updated_by String? litellm_budget_table LiteLLM_BudgetTable? @relation(fields: [budget_id], references: [budget_id]) litellm_organization_table LiteLLM_OrganizationTable? @relation(fields: [organization_id], references: [organization_id]) } diff --git a/schema.prisma b/schema.prisma index a09ef97009..fedbb271da 100644 --- a/schema.prisma +++ b/schema.prisma @@ -161,7 +161,9 @@ model LiteLLM_VerificationToken { budget_id String? organization_id String? created_at DateTime? @default(now()) @map("created_at") + created_by String? updated_at DateTime? @default(now()) @updatedAt @map("updated_at") + updated_by String? litellm_budget_table LiteLLM_BudgetTable? @relation(fields: [budget_id], references: [budget_id]) litellm_organization_table LiteLLM_OrganizationTable? @relation(fields: [organization_id], references: [organization_id]) } diff --git a/ui/litellm-dashboard/src/components/all_keys_table.tsx b/ui/litellm-dashboard/src/components/all_keys_table.tsx index b92294223a..008ac1c878 100644 --- a/ui/litellm-dashboard/src/components/all_keys_table.tsx +++ b/ui/litellm-dashboard/src/components/all_keys_table.tsx @@ -224,13 +224,21 @@ export function AllKeysTable({ }, }, { - header: "Created", + header: "Created At", accessorKey: "created_at", cell: (info) => { const value = info.getValue(); return value ? new Date(value as string).toLocaleDateString() : "-"; }, }, + { + header: "Created By", + accessorKey: "created_by", + cell: (info) => { + const value = info.getValue(); + return value ? value : "Unknown"; + }, + }, { header: "Expires", accessorKey: "expires",