Skip to main content

Lago

Lago 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

litellm.callbacks = ["lago"] # logs cost + usage of successful calls to lago
# uv add 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
os.environ["LAGO_API_CHARGE_BY"] = "user_id" # the default, end_user_id, is only populated for proxy requests

# 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-5.6-luna",
messages=[
{"role": "user", "content": "Hi 👋 - i'm openai"}
],
metadata={"user_api_key_user_id": "your_customer_id"} # 👈 SET YOUR CUSTOMER ID HERE
)

Advanced - Lagos Logging object​

This is what LiteLLM will log to Lagos

{
"event": {
"transaction_id": "<generated_unique_id>",
"external_subscription_id": <customer_id>, # selected by LAGO_API_CHARGE_BY
"code": os.getenv("LAGO_API_EVENT_CODE"),
"properties": {
"model": <string>,
"response_cost": <number>, # 👈 LITELLM CALCULATED RESPONSE COST - https://github.com/BerriAI/litellm/blob/d43f75150a65f91f60dc2c0c9462ce3ffc713c1f/litellm/utils.py#L1473
"prompt_tokens": <number>,
"completion_tokens": <number>,
"total_tokens": <number>
}
}
}

LAGO_API_CHARGE_BY picks the value sent as external_subscription_id. end_user_id (default) uses the user param of a proxy request, user_id uses the virtual key's user_id and team_id uses the virtual key's team_id. If the selected value is missing, nothing is sent to Lago. In the SDK there is no proxy request, so set LAGO_API_CHARGE_BY=user_id and pass the customer id as metadata={"user_api_key_user_id": ...}

LiteLLM Enterprise
SSO/SAML, audit logs, spend tracking, multi-team management, and guardrails, built for production.
Learn more →