{"product_id":"meter-ai-tokens-to-lago-credits-via-webhook-receipt","title":"Meter AI Tokens to Lago Credits via Webhook Receipt","description":"\u003ch3\u003eAutomatically meter AI token usage and translate it into Lago credits (with a webhook receipt)\u003c\/h3\u003e\n\u003cp\u003eThis n8n workflow receives AI token metering via a webhook, estimates the prepaid cost in \u003cstrong\u003eLago\u003c\/strong\u003e, records the usage as a Lago event, and returns an HTTP receipt that warns you when credits are at (or below) a configurable threshold.\u003c\/p\u003e\n\n\u003ch3\u003eWhat this workflow does\u003c\/h3\u003e\n\u003cul\u003e\n  \u003cli\u003e\n\u003cstrong\u003eReceives a POST webhook\u003c\/strong\u003e with subscription identifiers, token counts, and metering details.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eValidates and normalizes input\u003c\/strong\u003e (including an optional timestamp). Invalid requests return a \u003cstrong\u003e400 JSON error response\u003c\/strong\u003e.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eEstimates pay-in-advance fees in Lago\u003c\/strong\u003e for the provided metric and sums the returned fee amounts.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eFetches the customer’s Lago prepaid wallet\u003c\/strong\u003e and converts the estimated fee into credits to compute a \u003cstrong\u003eprojected post-usage credit balance\u003c\/strong\u003e.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eSends the usage event to Lago\u003c\/strong\u003e, using the provided transaction ID for \u003cstrong\u003eidempotency\u003c\/strong\u003e.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eBuilds a JSON receipt\u003c\/strong\u003e that includes estimated cost and projected balance, and returns \u003cstrong\u003eHTTP 202\u003c\/strong\u003e with a status that flags low credits when at\/below the configured threshold.\u003c\/li\u003e\n\u003c\/ul\u003e\n\n\u003ch3\u003eUse cases\u003c\/h3\u003e\n\u003cul\u003e\n  \u003cli\u003e\n\u003cstrong\u003eSaaS metering:\u003c\/strong\u003e Track model token consumption per customer and automatically charge against Lago prepaid credits.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eUsage-aware budgeting:\u003c\/strong\u003e Proactively detect when customers are nearing a credit cutoff using the webhook receipt warning.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eOperations automation:\u003c\/strong\u003e Centralize token metering logic in n8n while keeping Lago as the billing source of record.\u003c\/li\u003e\n\u003c\/ul\u003e\n\n\u003ch3\u003eTechnical details\u003c\/h3\u003e\n\u003cul\u003e\n  \u003cli\u003e\n\u003cstrong\u003en8n nodes:\u003c\/strong\u003e webhook, if, set, code, sticky note, respond to webhook.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eLago integration:\u003c\/strong\u003e uses Lago community node credentials to estimate fees, fetch prepaid wallet info, and send the usage event with idempotency via transaction ID.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eSetup notes:\u003c\/strong\u003e create a billable metric in Lago (e.g., Sum aggregation on a \u003ccode\u003eunits\u003c\/code\u003e property) and add it to an active plan as a pay-in-advance charge so fee estimation works.\u003c\/li\u003e\n\u003c\/ul\u003e","brand":"N8N Commerce","offers":[{"title":"Default Title","offer_id":45891849781427,"sku":"N8N-18615","price":16.99,"currency_code":"GBP","in_stock":true}],"thumbnail_url":"\/\/cdn.shopify.com\/s\/files\/1\/0749\/6279\/6723\/files\/1vvUbtqvPD0kOrYDD-Ypl_iF8MbdA2.png?v=1787562547","url":"https:\/\/buyflowscripts.com\/products\/meter-ai-tokens-to-lago-credits-via-webhook-receipt","provider":"N8N Commerce","version":"1.0","type":"link"}