🔓 Unlock all 10,000+ workflows & prompts free Join Newsletter →
✅ Full access unlocked — explore all 10,000 AI workflow and prompt templates Browse Templates →
Home n8n Workflow
January 22, 2026

OpenAI costs to Google Sheets, tracked per run

Lisa Granqvist Partner Workflow Automation Expert

Your OpenAI bill lands, it looks higher than you expected, and you still can’t answer the basic question: which workflow caused it? Without per-run visibility, “AI spend” turns into a fuzzy line item you can’t control.

This kind of OpenAI cost tracking hits automation builders first, honestly. But marketing leads running AI content workflows and agency owners managing client automations feel it too. You need a clean log of tokens and cost per execution, not another spreadsheet you have to maintain manually.

This n8n workflow logs OpenAI usage into Google Sheets per run, then makes it readable (and actionable). You’ll see how the tracking works, what you need to set it up, and where teams usually trip up.

How This Automation Works

The full n8n workflow, from trigger to final output:

n8n Workflow Template: OpenAI costs to Google Sheets, tracked per run

The Problem: AI costs are invisible until it’s too late

n8n makes it easy to ship AI-powered automations fast. The downside is that cost details don’t ship with them. A workflow runs, produces a nice output, and nobody thinks about tokens again until the month-end invoice shows up. Then the blame game starts: was it the new prompt, the wrong model, a loop that ran too many times, or a teammate testing in production? You end up guessing, which leads to overcorrecting (like turning off useful automations) or doing nothing and hoping next month is better.

The friction compounds. A few tiny unknowns turn into a budget you can’t defend.

  • Costs get lumped together, so you can’t tell which workflow execution was expensive.
  • Prompt changes ship quickly, but nobody can see the cost impact without digging through logs.
  • When something spikes, you find out after the fact, usually when finance asks awkward questions.
  • Manual tracking never sticks because it’s one more step after “the real work.”

The Solution: Log OpenAI tokens and cost per execution into Sheets

This workflow gives you a repeatable way to capture token usage and cost every time an AI-enabled workflow runs. It starts by receiving run data through a webhook, then pulls execution details from n8n so it can extract what matters (prompt tokens, completion tokens, model used, and identifiers like workflow name or ID). After that, it calculates the estimated cost using pricing logic (either preset pricing or live pricing when you want it), and writes a clean record into Google Sheets. Finally, it can return a friendly webhook response and render a simple HTML view so you can see results without hunting through raw JSON.

In plain terms: a workflow execution happens, the tracker collects the token stats, it calculates cost, and a new row appears in Google Sheets. From there you can trend it over time, filter by workflow, and spot waste before it becomes a monthly surprise.

What You Get: Automation vs. Results

Example: What This Looks Like

Say you have 6 AI-enabled workflows (content summaries, lead enrichment, support replies), and each runs about 20 times a day. Without tracking, your “cost audit” is usually an hour of log-clicking and rough estimates, and you still won’t know which runs were outliers. With this workflow, each run posts a payload in seconds, the tracker waits briefly to pull the execution details, then writes one row to Google Sheets. Realistically, you spend about 10 minutes a week reviewing the sheet, and you catch spikes the same day.

What You’ll Need

  • n8n instance (try n8n Cloud free)
  • Self-hosting option if you prefer (Hostinger works well)
  • Google Sheets for storing per-run token and cost logs
  • OpenAI (or another LLM) to generate token usage you want to track
  • n8n API access (create an API key in your n8n user settings)

Skill level: Intermediate. You’ll paste a webhook call into your existing workflows and connect Google Sheets credentials.

Don’t want to set this up yourself? Talk to an automation expert (free 15-minute consultation).

How It Works

A tracking webhook gets called. At the end of any workflow you want to monitor, you add a simple HTTP Request that posts run context (workflow ID, execution ID, model info if you have it) into this tracker.

The tracker fetches execution details. After a short delay (so the execution is fully available), it uses HTTP Request to pull the detailed execution log from n8n, then a Code step extracts prompt tokens, completion tokens, and the model/tool used.

Costs are calculated using pricing rules. The workflow can rely on preset prices (it includes a “Assign 2024 Pricing” style mapping), or it can optionally fetch live pricing and summarize it before calculating per-run cost.

Everything lands in Google Sheets (and can be displayed). A Google Sheets node appends a row for each run. Separate webhooks can read the sheet back, aggregate results, and return an HTML view for a lightweight dashboard experience.

You can easily modify the spreadsheet columns to match your reporting needs, then filter by workflow name, model, or date range. See the full implementation guide below for customization options.

Step-by-Step Implementation Guide

Step 1: Configure the Webhook Trigger

This workflow starts from multiple webhooks that drive different UI and data ingestion paths. You will configure the incoming endpoints that trigger the workflow logic.

  1. Add and configure the Incoming Data Webhook node to receive execution events that initiate the usage tracking flow.
  2. Add and configure the UI Webhook Trigger node to serve the HTML UI response path.
  3. Add and configure the Image Fetch Webhook node to receive image requests used for file generation.
  4. Add and configure the Payload Intake Webhook node to receive the payload that will be used in the aggregation and response.
  5. Verify the execution flow: UI Webhook TriggerRender HTML OutputReturn Webhook Result.

⚠️ Common Pitfall: Ensure each webhook has a unique path and that your external services target the correct webhook URL.

Step 2: Connect Google Sheets

Two Google Sheets nodes read and write data for model usage and pricing summaries.

  1. Open Read Spreadsheet Data and select the spreadsheet and sheet that contain your token usage data.
  2. Open Update Spreadsheet Log and select the spreadsheet and sheet where summarized pricing will be logged.
  3. Credential Required: Connect your Google Sheets credentials in both Read Spreadsheet Data and Update Spreadsheet Log.

Tip: Keep column names consistent across your input and output sheets to avoid mapping issues in later steps.

Step 3: Set Up Processing and Pricing Logic

This workflow processes execution data, derives metrics, applies pricing, and summarizes model costs.

  1. Configure Delay Execution to pause before data retrieval, ensuring the incoming run has completed.
  2. In Retrieve Execution Details, set the HTTP request parameters needed to fetch execution details from your n8n instance or data source.
  3. Use Fetch AI Usage Info to parse execution data and extract token usage fields.
  4. Map the extracted values into fields in Assign Run Metrics.
  5. Set pricing values or map pricing fields in Assign 2024 Pricing.
  6. Finalize model-level cost summaries in Summarize Model Pricing.

⚠️ Common Pitfall: If your HTTP requests need authentication, add the appropriate credentials inside Retrieve Execution Details or your request will fail silently.

Step 4: Configure Payload Assembly and Responses

These nodes build payloads, generate files, and return webhook responses for multiple entry points.

  1. In Compose Payload, map the spreadsheet data from Read Spreadsheet Data into the required response shape.
  2. Use Aggregate Payload Data to consolidate records for the response payload.
  3. Configure Send Webhook Reply to return the aggregated payload from Aggregate Payload Data.
  4. In Map Image Strings, prepare image data for conversion.
  5. Generate a file in Generate File Asset and send it through Finalize Webhook Response.
  6. Ensure Render HTML Output produces the HTML content and flows to Return Webhook Result.

Step 5: Configure Utility HTTP Requests (Optional Enhancements)

Utility calls provide optional pricing data and external dispatches for token statistics.

  1. Set up Utility: Live Pricing Fetch if you want live model pricing updates (this node retries on failure by default).
  2. Configure Utility: Dispatch Token Stats if you want to send token usage to external dashboards or services.
  3. If these HTTP requests require authentication, add the credentials directly inside each node.

Step 6: Configure Output Logging

Summarized pricing results are logged to your spreadsheet for reporting and analysis.

  1. Verify the execution flow: Summarize Model PricingUpdate Spreadsheet Log.
  2. Map the summarized pricing fields to the correct columns in Update Spreadsheet Log.

Step 7: Test and Activate Your Workflow

Run a manual test for each webhook path and verify that data flows to the correct outputs.

  1. Click Execute Workflow and trigger each webhook endpoint to validate the full data path.
  2. Confirm that Return Webhook Result, Send Webhook Reply, and Finalize Webhook Response return valid responses.
  3. Check your spreadsheet to ensure Update Spreadsheet Log added the expected pricing summary rows.
  4. When successful, toggle the workflow to Active to enable production use.
🔒

Unlock Full Step-by-Step Guide

Get the complete implementation guide + downloadable template

Common Gotchas

  • Google Sheets credentials can expire or the sheet permissions may be wrong. If rows stop appending, check the n8n credential, then confirm the target spreadsheet is shared with the same Google account.
  • If you’re using Wait nodes or external rendering, processing times vary. Bump up the wait duration if downstream nodes fail on empty responses.
  • Default prompts in AI nodes are generic. Add your brand voice early or you’ll be editing outputs forever.

Frequently Asked Questions

How long does it take to set up this OpenAI cost tracking automation?

About an hour if your n8n and Google Sheets access are ready.

Do I need coding skills to automate OpenAI cost tracking?

No. You’ll mostly connect accounts and paste a prebuilt HTTP Request into the workflows you want to track.

Is n8n free to use for this OpenAI cost tracking workflow?

Yes. n8n has a free self-hosted option and a free trial on n8n Cloud. Cloud plans start at $20/month for higher volume. You’ll also need to factor in OpenAI API costs, which can vary a lot depending on model and usage.

Where can I host n8n to run this automation?

Two options: n8n Cloud (managed, easiest setup) or self-hosting on a VPS. For self-hosting, Hostinger VPS is affordable and handles n8n well. Self-hosting gives you unlimited executions but requires basic server management.

Can I customize this OpenAI cost tracking workflow for Slack alerts when spend spikes?

Yes, and it’s a smart upgrade. After the cost is calculated (right after the pricing summary and “assign run metrics” logic), add an If condition that checks the run cost or token count, then send a message to Slack when it crosses your threshold. Common customizations include tagging runs by client, adding a “cost center” column in Google Sheets, and grouping costs by workflow ID for weekly summaries.

Why is my Google Sheets connection failing in this workflow?

Usually it’s permissions or an expired OAuth token. Reconnect the Google Sheets credential in n8n, then confirm the exact spreadsheet is shared with the same Google account used by the credential. Also check that the Sheet tab name hasn’t changed, because that can silently break “append row” actions. If you’re writing lots of rows quickly, Google API rate limits can show up too.

How many executions can this OpenAI cost tracking automation handle?

A lot. On n8n Cloud, capacity depends on your plan’s monthly executions, and most small teams are fine on Starter or Pro. If you self-host, there’s no execution cap from n8n; it mainly depends on your server size and how often you write to Google Sheets.

Is this OpenAI cost tracking automation better than using Zapier or Make?

Often, yes. This workflow relies on pulling n8n execution details, running custom extraction logic, and handling multiple webhooks, which is where n8n tends to be more flexible (and cheaper at scale). Zapier or Make can work if you only want a basic “log this value to a sheet” flow, but you’ll hit limits once you need branching, delays, or richer parsing. Another factor is data control: self-hosting n8n keeps your cost logs in your environment. If you’re unsure, Talk to an automation expert and map the simplest setup that still answers your finance questions.

When every run has a cost attached to it, decisions get easier. Set this up once, then use the sheet to spot waste, prove ROI, and keep your AI budget calm.

Need Help Setting This Up?

Our automation experts can build and customize this workflow for your specific needs. Free 15-minute consultation—no commitment required.

Lisa Granqvist

Workflow Automation Expert

Expert in workflow automation and no-code tools.

×

Use template

Get instant access to this n8n workflow Json file

💬
Get a free quote today!
Get a free quote today!

Tell us what you need and we'll get back to you within one working day.

Get a free quote today!
Get a free quote today!

Tell us what you need and we'll get back to you within one working day.

Launch login modal Launch register modal