Перейти к содержанию
НОВОЕПознакомьтесь с Alaaddin — вашим ИИ-джинном с голосом. trig8n запускается 1 января 2027. Что нового

Библиотека / Финансы, счета и бухгалтерия

Финансы, счета и бухгалтерия

Учитывайте использование токенов ИИ в Lago и предупреждайте, когда предоплаченные кредиты заканчиваются

Получает данные об использовании токенов ИИ через вебхук, проверяет их, записывает событие в Lago на предоплаченные кошельки и возвращает квитанцию с предупреждением, когда остаток кредитов опускается ниже порога.

Что делает

## Meter AI token usage in Lago and warn before credits run out ### How it works This workflow receives AI token usage through a webhook, validates and normalizes the payload, then estimates the Lago fees for the reported usage. For valid requests, it checks the customer’s prepaid wallet, calculates whether remaining credits are below a guardrail threshold, records the usage event in Lago, and returns a metering receipt. It branches the final response to warn when credits are running low, return a healthy receipt otherwise, or return a validation error for invalid input. ### Setup steps - Configure the webhook endpoint and any authentication or signing checks expected by the incoming AI usage producer. - Add Lago credentials in n8n and verify the Lago customer, billable metric, event code, plan, and prepaid wallet identifiers used by the Lago nodes. - Review the custom code nodes so the incoming payload fields, token quantities, customer IDs, and currency assumptions match your application. - Test both valid and invalid requests, plus low-credit and healthy-credit wallet scenarios, to confirm each webhook response path. ### Customization Adjust the credit guardrail threshold, response messages, Lago event metadata, and validation rules to match your pricing model and customer communication style.

Шаги

  1. When AI Usage Posted
  2. Normalize AI Usage Data
  3. If AI Usage Valid
  4. Compute Usage Fees
  5. Total Estimated Fees
  6. Retrieve Prepaid Wallet
  7. Determine Credit Level
  8. Transmit Usage Event
  9. Create Metering Receipt
  10. Check Low Credit Alert
  11. Setup Low Credit Alert
  12. Send Low Credit Response
  13. Setup Healthy Credit Response
  14. Send Healthy Credit Response

Всего шагов: 15.

Похожие автоматизации