docs(customers.md): add customer cost tracking to docs

This commit is contained in:
Krrish Dholakia 2024-05-29 14:55:08 -07:00
parent 098df3dcd6
commit 8f0019c241
5 changed files with 60 additions and 3 deletions

View file

@ -0,0 +1,50 @@
# 🙋‍♂️ Customers
Track spend, set budgets for your customers.
## Tracking Customer Credit
1. Track LLM API Spend by Customer ID
Make a /chat/completions call, pass 'user' - First call Works
```bash
curl -X POST 'http://0.0.0.0:4000/chat/completions' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer sk-1234' \ # 👈 YOUR PROXY KEY
--data ' {
"model": "azure-gpt-3.5",
"user": "ishaan3", # 👈 CUSTOMER ID
"messages": [
{
"role": "user",
"content": "what time is it"
}
]
}'
```
The customer_id will be upserted into the DB with the new spend.
If the customer_id already exists, spend will be incremented.
2. Get Customer Spend
```bash
curl -X GET 'http://0.0.0.0:4000/customer/info?end_user_id=ishaan3' \ # 👈 CUSTOMER ID
-H 'Authorization: Bearer sk-1234' \ # 👈 YOUR PROXY KEY
```
Expected Response:
```
{
"user_id": "ishaan3",
"blocked": false,
"alias": null,
"spend": 0.001413,
"allowed_model_region": null,
"default_model": null,
"litellm_budget_table": null
}
```

View file

@ -41,6 +41,7 @@ const sidebars = {
"proxy/reliability",
"proxy/cost_tracking",
"proxy/users",
"proxy/customers",
"proxy/billing",
"proxy/user_keys",
"proxy/enterprise",

View file

@ -348,7 +348,7 @@ async def acreate_batch(
def create_batch(
completion_window: Literal["24h"],
endpoint: Literal["/v1/chat/completions", "/v1/embeddings", "/v1/completions"],
endpoint: Literal["/v1/chat/completions", "/v1/embeddings"],
input_file_id: str,
custom_llm_provider: Literal["openai"] = "openai",
metadata: Optional[Dict[str, str]] = None,

View file

@ -8412,6 +8412,7 @@ async def new_end_user(
"/customer/info",
tags=["Customer Management"],
dependencies=[Depends(user_api_key_auth)],
response_model=LiteLLM_EndUserTable,
)
@router.get(
"/end_user/info",
@ -8436,7 +8437,12 @@ async def end_user_info(
where={"user_id": end_user_id}
)
return user_info
if user_info is None:
raise HTTPException(
status_code=400,
detail={"error": "End User Id={} does not exist in db".format(end_user_id)},
)
return user_info.model_dump(exclude_none=True)
@router.post(

View file

@ -214,7 +214,7 @@ class CreateBatchRequest(TypedDict, total=False):
"""
completion_window: Literal["24h"]
endpoint: Literal["/v1/chat/completions", "/v1/embeddings", "/v1/completions"]
endpoint: Literal["/v1/chat/completions", "/v1/embeddings"]
input_file_id: str
metadata: Optional[Dict[str, str]]
extra_headers: Optional[Dict[str, str]]