Zum Hauptinhalt springen

Lago - Nutzungsbasierte Abrechnung

Lago bietet eine selbst gehostete und Cloud-Lösung für Messung und nutzungsbasierte Abrechnung.

Schnellstart

Verwenden Sie nur 1 Zeile Code, um Ihre Antworten über alle Anbieter hinweg mit Lago sofort zu protokollieren.

Holen Sie sich Ihren Lago API-Schlüssel

litellm.callbacks = ["lago"] # logs cost + usage of successful calls to lago
# 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"}
],
user="your_customer_id" # 👈 SET YOUR CUSTOMER ID HERE
)

Erweitert - Lagos Logging-Objekt

Dies wird von LiteLLM in Lagos protokolliert

{
"event": {
"transaction_id": "<generated_unique_id>",
"external_customer_id": <litellm_end_user_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": <number>,
"output_tokens": <number>,
"model": <string>,
"response_cost": <number>, # 👈 LITELLM CALCULATED RESPONSE COST - https://github.com/BerriAI/litellm/blob/d43f75150a65f91f60dc2c0c9462ce3ffc713c1f/litellm/utils.py#L1473
}
}
}