From c0593529087ca907fec925806779c650d5733eda Mon Sep 17 00:00:00 2001 From: Krrish Dholakia Date: Wed, 12 Jun 2024 08:54:58 -0700 Subject: [PATCH] docs(enterprise.md): add logging spend with custom metadata --- docs/my-website/docs/proxy/cost_tracking.md | 21 ++- docs/my-website/docs/proxy/enterprise.md | 140 ++++++++++++++++++++ 2 files changed, 160 insertions(+), 1 deletion(-) diff --git a/docs/my-website/docs/proxy/cost_tracking.md b/docs/my-website/docs/proxy/cost_tracking.md index b63fab106..f01e1042e 100644 --- a/docs/my-website/docs/proxy/cost_tracking.md +++ b/docs/my-website/docs/proxy/cost_tracking.md @@ -427,4 +427,23 @@ model_list: ## Custom Input/Output Pricing -👉 Head to [Custom Input/Output Pricing](https://docs.litellm.ai/docs/proxy/custom_pricing) to setup custom pricing or your models \ No newline at end of file +👉 Head to [Custom Input/Output Pricing](https://docs.litellm.ai/docs/proxy/custom_pricing) to setup custom pricing or your models + +## ✨ Custom k,v pairs + +Log specific key,value pairs as part of the metadata for a spend log + +:::info + +Logging specific key,value pairs in spend logs metadata is an enterprise feature. [See here](./enterprise.md#tracking-spend-with-custom-metadata) + +::: + + +## ✨ Custom Tags + +:::info + +Tracking spend with Custom tags is an enterprise feature. [See here](./enterprise.md#tracking-spend-for-custom-tags) + +::: \ No newline at end of file diff --git a/docs/my-website/docs/proxy/enterprise.md b/docs/my-website/docs/proxy/enterprise.md index 48cab6093..e657d3b73 100644 --- a/docs/my-website/docs/proxy/enterprise.md +++ b/docs/my-website/docs/proxy/enterprise.md @@ -205,6 +205,146 @@ curl -X GET "http://0.0.0.0:4000/spend/tags" \ ``` +## Tracking Spend with custom metadata + +Requirements: + +- Virtual Keys & a database should be set up, see [virtual keys](https://docs.litellm.ai/docs/proxy/virtual_keys) + +#### Usage - /chat/completions requests with special spend logs metadata + + + + + + + +Set `extra_body={"metadata": { }}` to `metadata` you want to pass + +```python +import openai +client = openai.OpenAI( + api_key="anything", + base_url="http://0.0.0.0:4000" +) + +# request sent to model set on litellm proxy, `litellm --model` +response = client.chat.completions.create( + model="gpt-3.5-turbo", + messages = [ + { + "role": "user", + "content": "this is a test request, write a short poem" + } + ], + extra_body={ + "metadata": { + "spend_logs_metadata": { + "hello": "world" + } + } + } +) + +print(response) +``` + + + + +Pass `metadata` as part of the request body + +```shell +curl --location 'http://0.0.0.0:4000/chat/completions' \ + --header 'Content-Type: application/json' \ + --data '{ + "model": "gpt-3.5-turbo", + "messages": [ + { + "role": "user", + "content": "what llm are you" + } + ], + "metadata": { + "spend_logs_metadata": { + "hello": "world" + } + } +}' +``` + + + +```python +from langchain.chat_models import ChatOpenAI +from langchain.prompts.chat import ( + ChatPromptTemplate, + HumanMessagePromptTemplate, + SystemMessagePromptTemplate, +) +from langchain.schema import HumanMessage, SystemMessage + +chat = ChatOpenAI( + openai_api_base="http://0.0.0.0:4000", + model = "gpt-3.5-turbo", + temperature=0.1, + extra_body={ + "metadata": { + "spend_logs_metadata": { + "hello": "world" + } + } + } +) + +messages = [ + SystemMessage( + content="You are a helpful assistant that im using to make a test request to." + ), + HumanMessage( + content="test from litellm. tell me why it's amazing in 1 sentence" + ), +] +response = chat(messages) + +print(response) +``` + + + + + +#### Viewing Spend w/ custom metadata + +#### `/spend/logs` Request Format + +```bash +curl -X GET "http://0.0.0.0:4000/spend/logs?request_id=