diff --git a/docs/my-website/docs/proxy/alerting.md b/docs/my-website/docs/proxy/alerting.md index 9574a4dc34..3ef676bbd6 100644 --- a/docs/my-website/docs/proxy/alerting.md +++ b/docs/my-website/docs/proxy/alerting.md @@ -178,23 +178,26 @@ curl -X GET --location 'http://0.0.0.0:4000/health/services?service=webhook' \ } ``` -**API Spec for Webhook Event** +## **API Spec for Webhook Event** - `spend` *float*: The current spend amount for the 'event_group'. -- `max_budget` *float*: The maximum allowed budget for the 'event_group'. +- `max_budget` *float or null*: The maximum allowed budget for the 'event_group'. null if not set. - `token` *str*: A hashed value of the key, used for authentication or identification purposes. -- `user_id` *str or null*: The ID of the user associated with the event (optional). +- `customer_id` *str or null*: The ID of the customer associated with the event (optional). +- `internal_user_id` *str or null*: The ID of the internal user associated with the event (optional). - `team_id` *str or null*: The ID of the team associated with the event (optional). -- `user_email` *str or null*: The email of the user associated with the event (optional). +- `user_email` *str or null*: The email of the internal user associated with the event (optional). - `key_alias` *str or null*: An alias for the key associated with the event (optional). - `projected_exceeded_date` *str or null*: The date when the budget is projected to be exceeded, returned when 'soft_budget' is set for key (optional). - `projected_spend` *float or null*: The projected spend amount, returned when 'soft_budget' is set for key (optional). - `event` *Literal["budget_crossed", "threshold_crossed", "projected_limit_exceeded"]*: The type of event that triggered the webhook. Possible values are: + * "spend_tracked": Emitted whenver spend is tracked for a customer id. * "budget_crossed": Indicates that the spend has exceeded the max budget. * "threshold_crossed": Indicates that spend has crossed a threshold (currently sent when 85% and 95% of budget is reached). * "projected_limit_exceeded": For "key" only - Indicates that the projected spend is expected to exceed the soft budget threshold. -- `event_group` *Literal["user", "key", "team", "proxy"]*: The group associated with the event. Possible values are: - * "user": The event is related to a specific user. +- `event_group` *Literal["customer", "internal_user", "key", "team", "proxy"]*: The group associated with the event. Possible values are: + * "customer": The event is related to a specific customer + * "internal_user": The event is related to a specific internal user. * "key": The event is related to a specific key. * "team": The event is related to a team. * "proxy": The event is related to a proxy. diff --git a/docs/my-website/docs/proxy/customers.md b/docs/my-website/docs/proxy/customers.md index bd609322ab..230eec9d07 100644 --- a/docs/my-website/docs/proxy/customers.md +++ b/docs/my-website/docs/proxy/customers.md @@ -1,3 +1,6 @@ +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; + # 🙋‍♂️ Customers Track spend, set budgets for your customers. @@ -30,6 +33,11 @@ If the customer_id already exists, spend will be incremented. 2. Get Customer Spend + + + +Call `/customer/info` to get a customer's all up 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 @@ -47,4 +55,68 @@ Expected Response: "default_model": null, "litellm_budget_table": null } -``` \ No newline at end of file +``` + + + + +To update spend in your client-side DB, point the proxy to your webhook. + +E.g. if your server is `https://webhook.site` and your listening on `6ab090e8-c55f-4a23-b075-3209f5c57906` + +1. Add webhook url to your proxy environment: + +```bash +export WEBHOOK_URL="https://webhook.site/6ab090e8-c55f-4a23-b075-3209f5c57906" +``` + +2. Add 'webhook' to config.yaml + +```yaml +general_settings: + alerting: ["webhook"] # 👈 KEY CHANGE +``` + +3. 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": "krrish12" +} +' +``` + +Expected Response + +```json +{ + "spend": 0.0011120000000000001, # 👈 SPEND + "max_budget": null, + "token": "88dc28d0f030c55ed4ab77ed8faf098196cb1c05df778539800c9f1243fe6b4b", + "customer_id": "krrish12", # 👈 CUSTOMER ID + "user_id": null, + "team_id": null, + "user_email": null, + "key_alias": null, + "projected_exceeded_date": null, + "projected_spend": null, + "event": "spend_tracked", + "event_group": "customer", + "event_message": "Customer spend tracked. Customer=krrish12, spend=0.0011120000000000001" +} +``` + +[See Webhook Spec](./alerting.md#api-spec-for-webhook-event) + + +