n8n

How to Automate Gmail Usage Invoices?

Collect resume PDFs through a simple online form, turn each file into a clean JSON record, and track AI token costs for every request. At the end of the month, totals are calculated from a shared log and an invoice is sent by email. This setup fits teams that sell usage based AI services and need clear, simple billing.

Here is how it works. A form receives a PDF file. The file is parsed, then an AI extractor organizes the resume into a set JSON structure. A custom LLM subnode records token usage and cost, and writes the details into Google Sheets. The user sees the JSON output right away. On a schedule at month end, the flow reads the sheet, filters last month, sums totals, and sends an invoice through Gmail.

Use a self hosted n8n instance because the Langchain code subnode is needed. Connect Google Sheets, OpenAI, and Gmail with proper credentials. Expect to cut billing prep from hours to minutes and reduce errors from manual tracking. Good for AI agencies, IT teams, and finance teams that bill clients by usage or need internal cost reporting.

What are the key features?

  • Form trigger captures PDF uploads and client choices in one step
  • Extract from File reads the PDF so the AI can work with the text
  • Information Extractor converts the resume into a clean JSON schema
  • Custom LLM subnode captures token usage and cost from each AI call
  • Google Sheets Tool appends usage rows with date, workflow id, and totals
  • Set node adds extra log fields like workflow id and execution data
  • Display JSON Document returns the structured result to the user
  • Schedule trigger runs at month end to start billing steps
  • Google Sheets read and Filter nodes pull last month records only
  • Summarize node calculates totals and Gmail sends the invoice

What are the benefits?

  • Reduce monthly billing prep from 3 hours to 10 minutes by logging usage automatically
  • Improve cost accuracy to over 99 percent by pulling token data directly from the LLM response
  • Handle 10 times more client requests without adding manual work
  • Connect Google Sheets, OpenAI, and Gmail in one flow for simple invoicing
  • Give clients clear breakdowns with itemized logs and totals

How do you set it up?

  1. Import the template into n8n: Create a new workflow in n8n > Click the three dots menu > Select 'Import from File' > Choose the downloaded JSON file.
  2. You'll need accounts with Google Sheets, Gmail and OpenAI. See the Tools Required section above for links to create accounts with these services.
  3. Use a self hosted n8n instance because the Langchain code subnode is required for token tracking.
  4. Open the Form Trigger node and confirm it accepts PDF files. Keep the response mode set to send results after the last node.
  5. Double click the Extract from File node and test with a sample PDF to ensure the text is parsed correctly.
  6. Open the Information Extractor node and review the JSON schema so the output matches the fields you need.
  7. Open the Custom LLM Subnode. In the credential dropdown click Create new credential and follow the steps to add your OpenAI API key from the OpenAI dashboard API page. Set model and cost values if the code requires them.
  8. Open the Client Usage Log Google Sheets Tool and select Create new credential for Google Sheets OAuth2. Choose the correct Google account and grant access. Point to your spreadsheet and Sheet1.
  9. Open the Get Client Logs Google Sheets node and use the same credential. Select the same document and sheet so reads match the log.
  10. Review the Filter Last Month node and confirm the date field matches the date column written in the sheet.
  11. Open the Send Invoice Gmail node and create a new Gmail OAuth2 credential. Choose the sender account and set the To, Subject, and body fields. Include totals from the Summarize node.
  12. Run a test: submit the form with a PDF. Confirm the user sees the JSON, a new row appears in Google Sheets, and the data includes token and cost values.
  13. Trigger the month end path by manually executing from the schedule step for testing. Confirm it reads last month, calculates totals, and sends a test email.
  14. If Gmail fails with a permission error, reauthorize the Gmail credential. If the sheet is empty, check that the Google Sheets Tool is pointing to the correct document and sheet.

Tools Required

$24 / mo or $20 / mo billed annually to use n8n in the cloud. However, the local or self-hosted n8n Community Edition is free.

Gmail

Sign up

No cost: Personal Gmail (Gmail API has no usage-based pricing; quotas apply)

Google Sheets

Sign up

Free: $0 (Google Sheets API usage has no additional cost; quota limits apply)

OpenAI

Sign up

Pay-as-you-go: GPT-5 at $1.25 per 1M input tokens and $10 per 1M output tokens

Similar Templates

Join Futurise to access 1,200+ automation templates

Get instant access to ready-made automation workflows for n8n, Make.com, AI agents, and more. Download, customise, and deploy in minutes.