From 3f2f864cc8087edf0e3fad6313bc8a9b51c2b5fc Mon Sep 17 00:00:00 2001 From: ishaan-jaff Date: Sat, 3 Feb 2024 10:59:06 -0800 Subject: [PATCH] (docs) /user/new --- docs/my-website/docs/proxy/virtual_keys.md | 76 +++++++++++++++++++++- litellm/proxy/proxy_server.py | 4 +- 2 files changed, 77 insertions(+), 3 deletions(-) diff --git a/docs/my-website/docs/proxy/virtual_keys.md b/docs/my-website/docs/proxy/virtual_keys.md index 11ca903cd..dd5edc6da 100644 --- a/docs/my-website/docs/proxy/virtual_keys.md +++ b/docs/my-website/docs/proxy/virtual_keys.md @@ -1,4 +1,4 @@ -# Virtual Keys +# Virtual Keys, Users Track Spend, Set budgets and create virtual keys for the proxy Grant other's temporary access to your proxy, with keys that expire after a set duration. @@ -278,6 +278,80 @@ Request Params: } ``` +## /user/new + +### Request + +All [key/generate params supported](#keygenerate) for creating a user +```shell +curl 'http://0.0.0.0:4000/user/new' \ +--header 'Authorization: Bearer sk-1234' \ +--header 'Content-Type: application/json' \ +--data-raw '{ + "user_id": "ishaan1", + "user_email": "ishaan@litellm.ai", + "user_role": "admin", + "team_id": "cto-team", + "max_budget": 20, + "budget_duration": "1h" + +}' +``` + +Request Params: + +- user_id: str (optional - defaults to uuid) - The unique identifier for the user. +- user_email: str (optional - defaults to "") - The email address associated with the user. +- user_role: str (optional - defaults to "app_user") - The role assigned to the user. Can be "admin", "app_owner", "app_user" + +**Possible `user_role` values** +``` +"admin" - Maintaining the proxy and owning the overall budget +"app_owner" - employees maintaining the apps, each owner may own more than one app +"app_user" - users who know nothing about the proxy. These users get created when you pass `user` to /chat/completions +``` +- team_id: str (optional - defaults to "") - The identifier for the team to which the user belongs. +- max_budget: float (optional - defaults to `null`) - The maximum budget allocated for the user. No budget checks done if `max_budget==null` +- budget_duration: str (optional - defaults to `null`) - The duration for which the budget is valid, e.g., "1h", "1d" + +### Response +A key will be generated for the new user created + +```shell +{ + "models": [], + "spend": 0.0, + "max_budget": null, + "user_id": "ishaan1", + "team_id": null, + "max_parallel_requests": null, + "metadata": {}, + "tpm_limit": null, + "rpm_limit": null, + "budget_duration": null, + "allowed_cache_controls": [], + "key_alias": null, + "duration": null, + "aliases": {}, + "config": {}, + "key": "sk-JflB33ucTqc2NYvNAgiBCA", + "key_name": null, + "expires": null +} + +``` + +Request Params: +- keys: List[str] - List of keys to delete + +### Response + +```json +{ + "deleted_keys": ["sk-kdEXbIqZRwEeEiHwdg7sFA"] +} +``` + ## Default /key/generate params Use this, if you need to control the default `max_budget` or any `key/generate` param per key. diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.py index 919499bdf..7679d8732 100644 --- a/litellm/proxy/proxy_server.py +++ b/litellm/proxy/proxy_server.py @@ -3008,9 +3008,9 @@ async def new_user(data: NewUserRequest): if "user_role" in data_json: user_role = data_json["user_role"] if user_role is not None: - if user_role not in ["proxy_admin", "app_owner", "app_user"]: + if user_role not in ["admin", "app_owner", "app_user"]: raise ProxyException( - message=f"Invalid user role, passed in {user_role}. Must be one of 'proxy_admin', 'app_owner', 'app_user'", + message=f"Invalid user role, passed in {user_role}. Must be one of 'admin', 'app_owner', 'app_user'", type="invalid_user_role", param="user_role", code=status.HTTP_400_BAD_REQUEST,