mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-27 11:43:54 +00:00
fix(key_management_endpoints.py): expose 'key' param, for setting your own key value
This commit is contained in:
parent
0861180bfe
commit
325538f8a4
2 changed files with 9 additions and 1 deletions
|
@ -587,6 +587,7 @@ class GenerateRequestBase(LiteLLMBase):
|
||||||
|
|
||||||
class GenerateKeyRequest(GenerateRequestBase):
|
class GenerateKeyRequest(GenerateRequestBase):
|
||||||
key_alias: Optional[str] = None
|
key_alias: Optional[str] = None
|
||||||
|
key: Optional[str] = None
|
||||||
duration: Optional[str] = None
|
duration: Optional[str] = None
|
||||||
aliases: Optional[dict] = {}
|
aliases: Optional[dict] = {}
|
||||||
config: Optional[dict] = {}
|
config: Optional[dict] = {}
|
||||||
|
|
|
@ -55,6 +55,7 @@ async def generate_key_fn(
|
||||||
Parameters:
|
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").
|
- 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_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
|
- team_id: Optional[str] - The team id of the key
|
||||||
- user_id: Optional[str] - The user 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)
|
- 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
|
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
|
budget_duration: Optional[str] = None, # max_budget is used to Budget Per user
|
||||||
token: Optional[str] = None,
|
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,
|
user_id: Optional[str] = None,
|
||||||
team_id: Optional[str] = None,
|
team_id: Optional[str] = None,
|
||||||
user_email: Optional[str] = None,
|
user_email: Optional[str] = None,
|
||||||
|
@ -763,7 +767,10 @@ async def generate_key_helper_fn(
|
||||||
)
|
)
|
||||||
|
|
||||||
if token is None:
|
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
|
if duration is None: # allow tokens that never expire
|
||||||
expires = None
|
expires = None
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue