mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-26 03:04:13 +00:00
feat(internal_user_endpoints.py): expose /user/delete
endpoint
This commit is contained in:
parent
cf52d3fa00
commit
622a99ad5d
3 changed files with 50 additions and 10 deletions
|
@ -670,6 +670,10 @@ class UpdateUserRequest(GenerateRequestBase):
|
||||||
return values
|
return values
|
||||||
|
|
||||||
|
|
||||||
|
class DeleteUserRequest(LiteLLMBase):
|
||||||
|
user_ids: List[str] # required
|
||||||
|
|
||||||
|
|
||||||
class NewCustomerRequest(LiteLLMBase):
|
class NewCustomerRequest(LiteLLMBase):
|
||||||
"""
|
"""
|
||||||
Create a new customer, allocate a budget to them
|
Create a new customer, allocate a budget to them
|
||||||
|
|
|
@ -9,25 +9,26 @@ These are members of a Team on LiteLLM
|
||||||
/user/delete
|
/user/delete
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import asyncio
|
||||||
import copy
|
import copy
|
||||||
import json
|
import json
|
||||||
import uuid
|
|
||||||
import re
|
import re
|
||||||
import traceback
|
|
||||||
import asyncio
|
|
||||||
import secrets
|
import secrets
|
||||||
from typing import Optional, List
|
import traceback
|
||||||
import fastapi
|
import uuid
|
||||||
from fastapi import Depends, Request, APIRouter, Header, status
|
|
||||||
from fastapi import HTTPException
|
|
||||||
import litellm
|
|
||||||
from datetime import datetime, timedelta, timezone
|
from datetime import datetime, timedelta, timezone
|
||||||
|
from typing import List, Optional
|
||||||
|
|
||||||
|
import fastapi
|
||||||
|
from fastapi import APIRouter, Depends, Header, HTTPException, Request, status
|
||||||
|
|
||||||
|
import litellm
|
||||||
from litellm._logging import verbose_proxy_logger
|
from litellm._logging import verbose_proxy_logger
|
||||||
|
from litellm.proxy._types import *
|
||||||
from litellm.proxy.auth.user_api_key_auth import user_api_key_auth
|
from litellm.proxy.auth.user_api_key_auth import user_api_key_auth
|
||||||
from litellm.proxy.management_endpoints.key_management_endpoints import (
|
from litellm.proxy.management_endpoints.key_management_endpoints import (
|
||||||
generate_key_helper_fn,
|
generate_key_helper_fn,
|
||||||
)
|
)
|
||||||
from litellm.proxy._types import *
|
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
|
@ -55,6 +56,7 @@ async def new_user(data: NewUserRequest):
|
||||||
- send_invite_email: Optional[bool] - Specify if an invite email should be sent.
|
- send_invite_email: Optional[bool] - Specify if an invite email should be sent.
|
||||||
- user_role: Optional[str] - Specify a user role - "proxy_admin", "proxy_admin_viewer", "internal_user", "internal_user_viewer", "team", "customer". Info about each role here: `https://github.com/BerriAI/litellm/litellm/proxy/_types.py#L20`
|
- user_role: Optional[str] - Specify a user role - "proxy_admin", "proxy_admin_viewer", "internal_user", "internal_user_viewer", "team", "customer". Info about each role here: `https://github.com/BerriAI/litellm/litellm/proxy/_types.py#L20`
|
||||||
- max_budget: Optional[float] - Specify max budget for a given user.
|
- max_budget: Optional[float] - Specify max budget for a given user.
|
||||||
|
- budget_duration: Optional[str] - Budget is reset at the end of specified duration. If not set, budget is never reset. You can set duration as seconds ("30s"), minutes ("30m"), hours ("30h"), days ("30d").
|
||||||
- models: Optional[list] - Model_name's a user is allowed to call. (if empty, key is allowed to call all models)
|
- models: Optional[list] - Model_name's a user is allowed to call. (if empty, key is allowed to call all models)
|
||||||
- tpm_limit: Optional[int] - Specify tpm limit for a given user (Tokens per minute)
|
- tpm_limit: Optional[int] - Specify tpm limit for a given user (Tokens per minute)
|
||||||
- rpm_limit: Optional[int] - Specify rpm limit for a given user (Requests per minute)
|
- rpm_limit: Optional[int] - Specify rpm limit for a given user (Requests per minute)
|
||||||
|
@ -280,9 +282,9 @@ async def user_info(
|
||||||
```
|
```
|
||||||
"""
|
"""
|
||||||
from litellm.proxy.proxy_server import (
|
from litellm.proxy.proxy_server import (
|
||||||
prisma_client,
|
|
||||||
general_settings,
|
general_settings,
|
||||||
litellm_master_key_hash,
|
litellm_master_key_hash,
|
||||||
|
prisma_client,
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -674,3 +676,36 @@ async def get_users(
|
||||||
)
|
)
|
||||||
|
|
||||||
return all_users
|
return all_users
|
||||||
|
|
||||||
|
|
||||||
|
@router.post(
|
||||||
|
"/user/delete",
|
||||||
|
tags=["Internal User management"],
|
||||||
|
dependencies=[Depends(user_api_key_auth)],
|
||||||
|
)
|
||||||
|
async def delete_user(
|
||||||
|
data: DeleteUserRequest,
|
||||||
|
user_api_key_dict: UserAPIKeyAuth = Depends(user_api_key_auth),
|
||||||
|
litellm_changed_by: Optional[str] = Header(
|
||||||
|
None,
|
||||||
|
description="The litellm-changed-by header enables tracking of actions performed by authorized users on behalf of other users, providing an audit trail for accountability",
|
||||||
|
),
|
||||||
|
):
|
||||||
|
"""
|
||||||
|
delete user and associated user keys
|
||||||
|
|
||||||
|
```
|
||||||
|
curl --location 'http://0.0.0.0:8000/team/delete' \
|
||||||
|
|
||||||
|
--header 'Authorization: Bearer sk-1234' \
|
||||||
|
|
||||||
|
--header 'Content-Type: application/json' \
|
||||||
|
|
||||||
|
--data-raw '{
|
||||||
|
"user_ids": ["45e3e396-ee08-4a61-a88e-16b3ce7e0849"]
|
||||||
|
}'
|
||||||
|
```
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
- user_ids: List[str] - The list of user id's to be deleted.
|
||||||
|
"""
|
||||||
|
|
|
@ -61,6 +61,7 @@ async def generate_key_fn(
|
||||||
- spend: Optional[int] - Amount spent by key. Default is 0. Will be updated by proxy whenever key is used. https://docs.litellm.ai/docs/proxy/virtual_keys#managing-auth---tracking-spend
|
- spend: Optional[int] - Amount spent by key. Default is 0. Will be updated by proxy whenever key is used. https://docs.litellm.ai/docs/proxy/virtual_keys#managing-auth---tracking-spend
|
||||||
- send_invite_email: Optional[bool] - Whether to send an invite email to the user_id, with the generate key
|
- send_invite_email: Optional[bool] - Whether to send an invite email to the user_id, with the generate key
|
||||||
- max_budget: Optional[float] - Specify max budget for a given key.
|
- max_budget: Optional[float] - Specify max budget for a given key.
|
||||||
|
- budget_duration: Optional[str] - Budget is reset at the end of specified duration. If not set, budget is never reset. You can set duration as seconds ("30s"), minutes ("30m"), hours ("30h"), days ("30d").
|
||||||
- max_parallel_requests: Optional[int] - Rate limit a user based on the number of parallel requests. Raises 429 error, if user's parallel requests > x.
|
- max_parallel_requests: Optional[int] - Rate limit a user based on the number of parallel requests. Raises 429 error, if user's parallel requests > x.
|
||||||
- metadata: Optional[dict] - Metadata for key, store information for key. Example metadata = {"team": "core-infra", "app": "app2", "email": "ishaan@berri.ai" }
|
- metadata: Optional[dict] - Metadata for key, store information for key. Example metadata = {"team": "core-infra", "app": "app2", "email": "ishaan@berri.ai" }
|
||||||
- permissions: Optional[dict] - key-specific permissions. Currently just used for turning off pii masking (if connected). Example - {"pii": false}
|
- permissions: Optional[dict] - key-specific permissions. Currently just used for turning off pii masking (if connected). Example - {"pii": false}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue