diff --git a/docs/my-website/docs/proxy/customers.md b/docs/my-website/docs/proxy/customers.md new file mode 100644 index 0000000000..bd609322ab --- /dev/null +++ b/docs/my-website/docs/proxy/customers.md @@ -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 +} +``` \ No newline at end of file diff --git a/docs/my-website/sidebars.js b/docs/my-website/sidebars.js index 330a3c550e..29095d41fe 100644 --- a/docs/my-website/sidebars.js +++ b/docs/my-website/sidebars.js @@ -41,6 +41,7 @@ const sidebars = { "proxy/reliability", "proxy/cost_tracking", "proxy/users", + "proxy/customers", "proxy/billing", "proxy/user_keys", "proxy/enterprise", diff --git a/litellm/batches/main.py b/litellm/batches/main.py index 5d9a3a1411..4043606d53 100644 --- a/litellm/batches/main.py +++ b/litellm/batches/main.py @@ -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, diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.py index f228b16056..6efa150a44 100644 --- a/litellm/proxy/proxy_server.py +++ b/litellm/proxy/proxy_server.py @@ -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( diff --git a/litellm/types/llms/openai.py b/litellm/types/llms/openai.py index 77791b8ece..57c199b61f 100644 --- a/litellm/types/llms/openai.py +++ b/litellm/types/llms/openai.py @@ -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]]