diff --git a/litellm/proxy/_types.py b/litellm/proxy/_types.py index f2bef739c1..dd038d80bd 100644 --- a/litellm/proxy/_types.py +++ b/litellm/proxy/_types.py @@ -587,6 +587,7 @@ class GenerateRequestBase(LiteLLMBase): class GenerateKeyRequest(GenerateRequestBase): key_alias: Optional[str] = None + key: Optional[str] = None duration: Optional[str] = None aliases: Optional[dict] = {} config: Optional[dict] = {} diff --git a/litellm/proxy/management_endpoints/key_management_endpoints.py b/litellm/proxy/management_endpoints/key_management_endpoints.py index 9bb07cfee3..00e17400c3 100644 --- a/litellm/proxy/management_endpoints/key_management_endpoints.py +++ b/litellm/proxy/management_endpoints/key_management_endpoints.py @@ -55,6 +55,7 @@ async def generate_key_fn( Parameters: - duration: Optional[str] - Specify the length of time the token is valid for. You can set duration as seconds ("30s"), minutes ("30m"), hours ("30h"), days ("30d"). - key_alias: Optional[str] - User defined key alias + - key: Optional[str] - User defined key value. If not set, a 16-digit unique sk-key is created for you. - team_id: Optional[str] - The team id of the key - user_id: Optional[str] - The user id of the key - models: Optional[list] - Model_name's a user is allowed to call. (if empty, key is allowed to call all models) @@ -728,6 +729,9 @@ async def generate_key_helper_fn( max_budget: Optional[float] = None, # max_budget is used to Budget Per user budget_duration: Optional[str] = None, # max_budget is used to Budget Per user token: Optional[str] = None, + key: Optional[ + str + ] = None, # dev-friendly alt param for 'token'. Exposed on `/key/generate` for setting key value yourself. user_id: Optional[str] = None, team_id: Optional[str] = None, user_email: Optional[str] = None, @@ -763,7 +767,10 @@ async def generate_key_helper_fn( ) if token is None: - token = f"sk-{secrets.token_urlsafe(16)}" + if key is not None: + token = key + else: + token = f"sk-{secrets.token_urlsafe(16)}" if duration is None: # allow tokens that never expire expires = None