forked from phoenix/litellm-mirror
docs(customers.md): tutorial for setting customer budgets on proxy
This commit is contained in:
parent
ea30769190
commit
939ddf8986
3 changed files with 132 additions and 3 deletions
|
@ -1,3 +1,4 @@
|
|||
import Image from '@theme/IdealImage';
|
||||
import Tabs from '@theme/Tabs';
|
||||
import TabItem from '@theme/TabItem';
|
||||
|
||||
|
@ -7,7 +8,7 @@ Track spend, set budgets for your customers.
|
|||
|
||||
## Tracking Customer Credit
|
||||
|
||||
1. Track LLM API Spend by Customer ID
|
||||
### 1. Make LLM API call w/ Customer ID
|
||||
|
||||
Make a /chat/completions call, pass 'user' - First call Works
|
||||
|
||||
|
@ -31,7 +32,7 @@ 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
|
||||
### 2. Get Customer Spend
|
||||
|
||||
<Tabs>
|
||||
<TabItem value="all-up" label="All-up spend">
|
||||
|
@ -120,3 +121,131 @@ Expected Response
|
|||
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
|
||||
## Setting Customer Budgets
|
||||
|
||||
Set customer budgets (e.g. monthly budgets, tpm/rpm limits) on LiteLLM Proxy
|
||||
|
||||
### Quick Start
|
||||
|
||||
Create / Update a customer with budget
|
||||
|
||||
**Create New Customer w/ budget**
|
||||
```bash
|
||||
curl -X POST 'http://0.0.0.0:4000/customer/new'
|
||||
-H 'Authorization: Bearer sk-1234'
|
||||
-H 'Content-Type: application/json'
|
||||
-D '{
|
||||
"user_id" : "my-customer-id",
|
||||
"max_budget": "0", # 👈 CAN BE FLOAT
|
||||
}'
|
||||
```
|
||||
|
||||
**Test it!**
|
||||
|
||||
```bash
|
||||
curl -X POST 'http://localhost:4000/chat/completions' \
|
||||
-H 'Content-Type: application/json' \
|
||||
-H 'Authorization: Bearer sk-1234' \
|
||||
-D '{
|
||||
"model": "mistral",
|
||||
"messages": [
|
||||
{
|
||||
"role": "user",
|
||||
"content": "What'\''s the weather like in Boston today?"
|
||||
}
|
||||
],
|
||||
"user": "ishaan-jaff-48"
|
||||
}
|
||||
```
|
||||
|
||||
### Assign Pricing Tiers
|
||||
|
||||
Create and assign customers to pricing tiers.
|
||||
|
||||
#### 1. Create a budget
|
||||
|
||||
<Tabs>
|
||||
<TabItem value="ui" label="UI">
|
||||
|
||||
- Go to the 'Budgets' tab on the UI.
|
||||
- Click on '+ Create Budget'.
|
||||
- Create your pricing tier (e.g. 'my-free-tier' with budget $4). This means each user on this pricing tier will have a max budget of $4.
|
||||
|
||||
<Image img={require('../../img/create_budget_modal.png')} />
|
||||
|
||||
</TabItem>
|
||||
<TabItem value="api" label="API">
|
||||
|
||||
Use the `/budget/new` endpoint for creating a new budget. [API Reference](https://litellm-api.up.railway.app/#/budget%20management/new_budget_budget_new_post)
|
||||
|
||||
```bash
|
||||
curl -X POST 'http://localhost:4000/budget/new' \
|
||||
-H 'Content-Type: application/json' \
|
||||
-H 'Authorization: Bearer sk-1234' \
|
||||
-D '{
|
||||
"budget_id": "my-free-tier",
|
||||
"max_budget": 4
|
||||
}
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
|
||||
#### 2. Assign Budget to Customer
|
||||
|
||||
In your application code, assign budget when creating a new customer.
|
||||
|
||||
Just use the `budget_id` used when creating the budget. In our example, this is `my-free-tier`.
|
||||
|
||||
```bash
|
||||
curl -X POST 'http://localhost:4000/customer/new' \
|
||||
-H 'Content-Type: application/json' \
|
||||
-H 'Authorization: Bearer sk-1234' \
|
||||
-D '{
|
||||
"user_id": "my-customer-id",
|
||||
"budget_id": "my-free-tier" # 👈 KEY CHANGE
|
||||
}
|
||||
```
|
||||
|
||||
#### 3. Test it!
|
||||
|
||||
<Tabs>
|
||||
<TabItem value="curl" label="curl">
|
||||
|
||||
```bash
|
||||
curl -X POST 'http://localhost:4000/customer/new' \
|
||||
-H 'Content-Type: application/json' \
|
||||
-H 'Authorization: Bearer sk-1234' \
|
||||
-D '{
|
||||
"user_id": "my-customer-id",
|
||||
"budget_id": "my-free-tier" # 👈 KEY CHANGE
|
||||
}
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
<TabItem value="openai" label="OpenAI">
|
||||
|
||||
```python
|
||||
from openai import OpenAI
|
||||
client = OpenAI(
|
||||
base_url="<your_proxy_base_url",
|
||||
api_key="<your_proxy_key>"
|
||||
)
|
||||
|
||||
completion = client.chat.completions.create(
|
||||
model="gpt-3.5-turbo",
|
||||
messages=[
|
||||
{"role": "system", "content": "You are a helpful assistant."},
|
||||
{"role": "user", "content": "Hello!"}
|
||||
],
|
||||
user="my-customer-id"
|
||||
)
|
||||
|
||||
print(completion.choices[0].message)
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
</Tabs>
|
BIN
docs/my-website/img/create_budget_modal.png
Normal file
BIN
docs/my-website/img/create_budget_modal.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 193 KiB |
|
@ -91,7 +91,7 @@ const Sidebar: React.FC<SidebarProps> = ({
|
|||
|
||||
{userRole == "Admin" ? (
|
||||
<Menu.Item key="9" onClick={() => setPage("budgets")}>
|
||||
<Text>Rate Limits</Text>
|
||||
<Text>Budgets</Text>
|
||||
</Menu.Item>
|
||||
) : null}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue