diff --git a/docs/my-website/docs/observability/lago.md b/docs/my-website/docs/observability/lago.md new file mode 100644 index 00000000000..aed02e99169 --- /dev/null +++ b/docs/my-website/docs/observability/lago.md @@ -0,0 +1,114 @@ +import Image from '@theme/IdealImage'; +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; + +# Lago - Usage Based Billing + +[Lago](https://www.getlago.com/) offers a self-hosted and cloud, metering and usage-based billing solution. + + + +## Quick Start +Use just 1 lines of code, to instantly log your responses **across all providers** with Lago + +Get your Lago [API Key](https://docs.getlago.com/guide/self-hosted/docker#find-your-api-key) + +```python + + + +litellm.callbacks = ["lago"] # logs cost + usage of successful calls to lago +``` + + + + + +```python +# pip install lago +import litellm +import os + +os.environ["LAGO_API_BASE"] = "" # http://0.0.0.0:3000 +os.environ["LAGO_API_KEY"] = "" +os.environ["LAGO_API_EVENT_CODE"] = "" # The billable metric's code - https://docs.getlago.com/guide/events/ingesting-usage#define-a-billable-metric + +# LLM API Keys +os.environ['OPENAI_API_KEY']="" + +# set lago as a callback, litellm will send the data to lago +litellm.success_callback = ["lago"] + +# openai call +response = litellm.completion( + model="gpt-3.5-turbo", + messages=[ + {"role": "user", "content": "Hi 👋 - i'm openai"} + ] +) +``` + + + + +1. Add to Config.yaml +```yaml +model_list: +- litellm_params: + api_base: https://openai-function-calling-workers.tasslexyz.workers.dev/ + api_key: my-fake-key + model: openai/my-fake-model + model_name: fake-openai-endpoint + +litellm_settings: + callbacks: ["lago"] # 👈 KEY CHANGE +``` + +2. Start Proxy + +``` +litellm --config /path/to/config.yaml +``` + +3. Test it! + +```bash +curl --location 'http://0.0.0.0:4000/chat/completions' \ +--header 'Content-Type: application/json' \ +--data ' { + "model": "fake-openai-endpoint", + "messages": [ + { + "role": "user", + "content": "what llm are you" + } + ], + } +' +``` + + + + + + + +## Advanced - Lagos Logging object + +This is what LiteLLM will log to Lagos + +``` +{ + "event": { + "transaction_id": "", + "external_customer_id": , # passed via `user` param in /chat/completion call - https://platform.openai.com/docs/api-reference/chat/create + "code": os.getenv("LAGO_API_EVENT_CODE"), + "properties": { + "input_tokens": , + "output_tokens": , + "model": , + "response_cost": , # 👈 LITELLM CALCULATED RESPONSE COST - https://github.com/BerriAI/litellm/blob/d43f75150a65f91f60dc2c0c9462ce3ffc713c1f/litellm/utils.py#L1473 + } + } +} +``` \ No newline at end of file diff --git a/docs/my-website/docs/observability/openmeter.md b/docs/my-website/docs/observability/openmeter.md index 64d9c39d215..2f53568757f 100644 --- a/docs/my-website/docs/observability/openmeter.md +++ b/docs/my-website/docs/observability/openmeter.md @@ -20,7 +20,7 @@ Use just 2 lines of code, to instantly log your responses **across all providers Get your OpenMeter API Key from https://openmeter.cloud/meters ```python -litellm.success_callback = ["openmeter"] # logs cost + usage of successful calls to openmeter +litellm.callbacks = ["openmeter"] # logs cost + usage of successful calls to openmeter ``` @@ -28,7 +28,7 @@ litellm.success_callback = ["openmeter"] # logs cost + usage of successful calls ```python -# pip install langfuse +# pip install openmeter import litellm import os @@ -39,8 +39,8 @@ os.environ["OPENMETER_API_KEY"] = "" # LLM API Keys os.environ['OPENAI_API_KEY']="" -# set langfuse as a callback, litellm will send the data to langfuse -litellm.success_callback = ["openmeter"] +# set openmeter as a callback, litellm will send the data to openmeter +litellm.callbacks = ["openmeter"] # openai call response = litellm.completion( @@ -64,7 +64,7 @@ model_list: model_name: fake-openai-endpoint litellm_settings: - success_callback: ["openmeter"] # 👈 KEY CHANGE + callbacks: ["openmeter"] # 👈 KEY CHANGE ``` 2. Start Proxy diff --git a/docs/my-website/img/lago.jpeg b/docs/my-website/img/lago.jpeg new file mode 100644 index 00000000000..546852f1c45 Binary files /dev/null and b/docs/my-website/img/lago.jpeg differ diff --git a/docs/my-website/img/lago_2.png b/docs/my-website/img/lago_2.png new file mode 100644 index 00000000000..e51a93b0776 Binary files /dev/null and b/docs/my-website/img/lago_2.png differ diff --git a/docs/my-website/sidebars.js b/docs/my-website/sidebars.js index 62202cc7eb6..1cd32866593 100644 --- a/docs/my-website/sidebars.js +++ b/docs/my-website/sidebars.js @@ -175,6 +175,7 @@ const sidebars = { "observability/custom_callback", "observability/langfuse_integration", "observability/sentry", + "observability/lago", "observability/openmeter", "observability/promptlayer_integration", "observability/wandb_integration", diff --git a/litellm/__init__.py b/litellm/__init__.py index d6ddf8db2a4..ac2b420d715 100644 --- a/litellm/__init__.py +++ b/litellm/__init__.py @@ -27,7 +27,7 @@ input_callback: List[Union[str, Callable]] = [] success_callback: List[Union[str, Callable]] = [] failure_callback: List[Union[str, Callable]] = [] service_callback: List[Union[str, Callable]] = [] -_custom_logger_compatible_callbacks_literal = Literal["lago"] +_custom_logger_compatible_callbacks_literal = Literal["lago", "openmeter"] callbacks: List[Union[Callable, _custom_logger_compatible_callbacks_literal]] = [] _langfuse_default_tags: Optional[ List[