fix(proxy_server.py): accept keys with none duration

This commit is contained in:
Krrish Dholakia 2023-12-25 13:45:49 +05:30
parent 485f05ea02
commit b3a98d8400
3 changed files with 20 additions and 1 deletions

View file

@ -3,6 +3,13 @@ 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.
:::info
Complete API documentation in the Swagger docs on your proxy base url (e.g. `http://0.0.0.0:8000)`
:::
## Quick Start
Requirements:
@ -59,6 +66,17 @@ Expected response:
}
```
## Keys that don't expire
Just set duration to None.
```bash
curl --location 'http://0.0.0.0:8000/key/generate' \
--header 'Authorization: Bearer sk-1234' \
--header 'Content-Type: application/json' \
--data '{"models": ["azure-models"], "aliases": {"mistral-7b": "gpt-3.5-turbo"}, "duration": null}'
```
## Upgrade/Downgrade Models
If a user is expected to use a given model (i.e. gpt3-5), and you want to:

View file

@ -149,7 +149,7 @@ class UserAPIKeyAuth(LiteLLMBase): # the expected response object for user api k
class GenerateKeyResponse(LiteLLMBase):
key: str
expires: datetime
expires: Optional[datetime]
user_id: str
class _DeleteKeyObject(LiteLLMBase):

View file

@ -189,6 +189,7 @@ class PrismaClient:
else:
# Token exists but is expired.
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="expired user key")
return response
else:
# Token does not exist.
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="invalid user key")