Skip to content
NEWMarketplace and the trig8n Agent: sell what you build, and get plans and changes that are tested before you see them. See what is new

Library / Monitoring, Ops & Incidents

Monitoring, Ops & Incidents

Track LLM Usage and Cost in Google Sheets

When a form is submitted or on a schedule, a custom LLM subnode logs token usage and cost to Google Sheets and emails summaries via Gmail.

What it does

## 4. Use Custom LLM Subnode to Track Usage & Cost [Learn more about the Langchain Code Node]({{ $env.WEBHOOK_URL }} By creating our custom LLM subnode using the Langchain Code node, we are able to tap into the chat completion's response which contains the token usage metadata for the information extractor request. With this, we can calculate exactly how much the client's request is costing per use! The only remaining step then is to store this data somewhere. Rather than importing more dependencies or hardcoding more credentials, a novel solution can be to attach a tool to our subnode. Here, we've decided to use the Google Sheets tool and append the client's usage metrics to the sheet. Check it out here - [Client Usage Log]( {{ $env.WEBHOOK_URL }}

The steps

  1. Client Usage Log
  2. Logging Attributes
  3. On form submission
  4. Custom LLM Subnode
  5. Display JSON Document
  6. Filter Last Month
  7. Get Client Logs
  8. Calculate Totals
  9. Every End of Month
  10. Send Invoice
  11. Parse PDF Upload
  12. Extract Resume Data
  13. Error Handler for 8884df86
  14. Error Handler for 10d95dcb

16 steps in total.

Similar automations