🔓 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

Telegram + Google Sheets: track AI token costs

Lisa Granqvist Partner Workflow Automation Expert

If you’re running an AI bot in Telegram or WhatsApp, costs can feel a little “mystical.” One day everything looks fine. Then you get an API bill and realize you have no idea which conversations (or which client) drove the spike.

This is where token cost tracking automation helps. It hits agency owners who bill clients hardest, but marketing teams running community bots feel it too. Even a solo consultant with one Telegram bot ends up guessing when they should be logging.

This workflow captures every interaction, totals tokens, estimates USD, and appends it to Google Sheets. You’ll see how it works, what you need, and where people usually get stuck.

How This Automation Works

Here’s the complete workflow you’ll be setting up:

n8n Workflow Template: Telegram + Google Sheets: track AI token costs

Why This Matters: AI Spend Is Invisible Until It Hurts

AI chat feels cheap in the moment. A few replies here, a voice note transcription there, and everything keeps moving. The trouble is you don’t see the meter running in real time. By the time finance asks, “Why did usage jump?” you’re digging through chat logs, trying to reconstruct what happened. That’s slow, and it’s honestly unreliable. If you support multiple channels (Telegram plus WhatsApp), the confusion doubles because each platform tells a different story.

It adds up fast. Here’s where it usually breaks down in day-to-day operations.

  • Token usage lives inside model dashboards, not inside your reporting workflow, so nobody checks it until billing day.
  • Manual logging never survives a busy week, especially when multiple teammates answer messages.
  • Client billing becomes “best effort,” which leads to awkward write-offs and scope creep.
  • When you add voice notes, transcription costs appear, and the spend is even harder to explain later.

What You’ll Build: Telegram/WhatsApp Token Logging to Google Sheets

This automation listens for incoming messages from Telegram and/or WhatsApp (via a webhook). If the message is text, it moves forward immediately. If it’s an audio message, the workflow fetches the media file, converts it into a usable format, and transcribes it before continuing. From there, an AI Agent runs your intended assistant logic using a chat model (configured through OpenRouter), and the workflow normalizes the result so token counts and metadata are clean. Finally, it appends a new row into Google Sheets with prompt tokens, completion tokens, total tokens, timestamps, and the sender/channel. Optionally, it calculates a simple USD estimate so you can audit spend without opening an AI dashboard.

The flow starts at Telegram Trigger or a WhatsApp webhook intake. Then it routes the input source, processes text or audio, and runs the AI agent. At the end, it logs usage to Sheets and sends a success message (or records an error and notifies you) depending on what happened.

What You’re Building

Expected Results

Say your bot handles about 20 conversations a day across Telegram and WhatsApp, and you want token totals plus cost notes for each. Manually, you might spend 5 minutes per conversation checking dashboards and pasting numbers into a sheet, which is roughly 100 minutes daily. With this workflow, logging is automatic after each message, so your “work” becomes a quick weekly review in Google Sheets (maybe 20 minutes). That’s a real chunk of time back, and the billing trail is already there.

Before You Start

  • n8n instance (try n8n Cloud free)
  • Self-hosting option if you prefer (Hostinger works well)
  • Google Sheets for the usage log and reporting.
  • Telegram Bot to receive messages and reply back.
  • WhatsApp Evolution API (optional) to capture WhatsApp chats via webhook.
  • OpenRouter API key (get it from your OpenRouter dashboard) to run the chat model and report token usage.

Skill level: Intermediate. You’ll connect accounts, edit a Sheet ID, and confirm webhook/Telegram settings.

Want someone to build this for you? Talk to an automation expert (free 15-minute consultation).

Step by Step

A message comes in from Telegram or WhatsApp. Telegram uses a bot trigger, while WhatsApp arrives through a webhook intake. A routing step (Switch) tags the source so replies and error notices go to the right place.

The workflow turns messy inputs into clean text. If the message includes audio, it fetches the media file, converts it, and transcribes it with an OpenAI transcription node. If it’s already text, it skips the audio path and maps the fields you’ll want to log (user/channel, message, timestamp).

Your AI Agent runs, then the workflow extracts usage. The AI Orchestrator calls the chat model (through OpenRouter) and produces both an answer and usage metadata. Code/normalization nodes reshape the output so you have consistent “prompt tokens,” “completion tokens,” and “total tokens,” even when different message types come through.

Google Sheets becomes your system of record. A Google Sheets node appends a new row to your log tab. On success, the workflow can send a quick confirmation back to Telegram or WhatsApp; on failure, it records an error row and sends an alert.

You can easily modify the spreadsheet columns to match your billing model based on your needs. See the full implementation guide below for customization options.

Step-by-Step Implementation Guide

Step 1: Configure the Webhook Trigger

Set up the incoming channels so the workflow can accept webhook payloads and Telegram messages.

  1. Add and open Webhook Intake, then copy the Test URL for initial testing.
  2. Open Telegram Trigger and set the update types you want to receive (e.g., message, audio).
  3. Confirm the flow: Webhook IntakeMap Webhook Payload and Telegram TriggerMap Telegram Payload.

Credential Required: Connect your Telegram API credentials in Telegram Trigger.

If you are testing from an external service, make sure it sends a payload structure that matches the fields you plan to map in Map Webhook Payload.

Step 2: Connect Google Sheets

Prepare the logging destinations used for usage tracking and error records.

  1. Open Update Usage Log and select the spreadsheet and sheet tab where usage rows will be written.
  2. Open Record Error Log and select the spreadsheet and sheet tab for error records.
  3. Ensure both nodes map the columns you expect (e.g., timestamp, input source, message, model).

Credential Required: Connect your Google Sheets credentials in Update Usage Log and Record Error Log.

⚠️ Common Pitfall: If your sheet headers change, the logging nodes may write to the wrong columns. Keep headers stable once mapped.

Step 3: Set Up AI Orchestrator

Configure the AI layer that interprets input and coordinates optional tools.

  1. Open Chat Model Engine and select your OpenRouter model and temperature as needed.
  2. Open AI Orchestrator and attach Chat Model Engine as its language model.
  3. If you plan to use tools, keep Dispatch Email Alert, Retrieve Contact List, and Generate Calendar Event enabled and connected to AI Orchestrator.

Credential Required: Connect your OpenRouter credentials in Chat Model Engine.

Credential Required: Connect your OpenAI credentials in Transcribe Audio.

OpenAI credentials for Transcribe Audio are required when audio is sent through the workflow.

The AI tools Dispatch Email Alert, Retrieve Contact List, and Generate Calendar Event are tool sub-nodes. Add their credentials on the parent AI Orchestrator, not on the tool nodes themselves.

Step 4: Configure Input Mapping and Audio Handling

Normalize incoming data so both webhook and Telegram payloads feed the same processing path.

  1. In Map Webhook Payload, map incoming webhook fields into your internal schema (e.g., message text, media URL, sender).
  2. In Map Telegram Payload, map Telegram fields into the same schema as the webhook mapping.
  3. Configure Detect Audio vs Text to route audio messages to Fetch Media File and text messages directly to Map Text Fields.
  4. Verify the audio flow: Fetch Media FileConvert Media FileTranscribe AudioMap Text Fields.
  5. Use Filter Records to drop incomplete or empty messages before they hit AI Orchestrator.
⚠️ Common Pitfall: If the media URL is missing or protected, Fetch Media File will fail and audio messages will not be transcribed.

Step 5: Configure Output and Success Routing

Define how successful AI results are normalized and sent back to users and logs.

  1. Ensure AI Orchestrator outputs to Normalize Output and then to Update Usage Log.
  2. Verify the routing from Update Usage Log into Route Input Source for source-aware replies.
  3. Route Input Source outputs to both Post WhatsApp Reply and Send Success Notice in parallel—configure each response format.

Credential Required: Connect your Telegram API credentials in Send Success Notice.

If you use WhatsApp APIs, add the required authentication headers in Post WhatsApp Reply and Post WhatsApp Error.

Step 6: Add Error Handling

Capture AI or processing errors and route notifications appropriately.

  1. Confirm AI Orchestrator sends error output to Normalize Error Output.
  2. From Normalize Error Output, verify the flow to Record Error Log and then Route Error Source.
  3. Route Error Source outputs to both Post WhatsApp Error and Send Error Notice in parallel—configure each message payload.

Credential Required: Connect your Telegram API credentials in Send Error Notice.

⚠️ Common Pitfall: If Route Error Source does not match the expected input values, error notifications may not be delivered.

Step 7: Test and Activate Your Workflow

Run end-to-end tests to validate both success and error paths before going live.

  1. Click Execute Workflow and send a test webhook to Webhook Intake or a test message to Telegram Trigger.
  2. Confirm successful runs create rows in Update Usage Log and trigger outputs from Post WhatsApp Reply and Send Success Notice.
  3. Simulate an error (e.g., invalid input) and verify Record Error Log, Post WhatsApp Error, and Send Error Notice receive the expected data.
  4. When everything looks correct, switch the workflow to Active for production use.
🔒

Unlock Full Step-by-Step Guide

Get the complete implementation guide + downloadable template

Troubleshooting Tips

  • Google Sheets credentials can expire or need specific permissions. If things break, check the connected Google account access in n8n credentials and confirm the Sheet is shared to that account first.
  • If you’re using Wait-style timing (for example, media processing and transcription), processing times vary. Bump up any wait duration or add retry logic if downstream nodes fail on empty responses.
  • Default prompts in AI nodes are generic. Add your brand voice and “what to log” rules early in the AI Agent instructions or you’ll be editing outputs forever.

Quick Answers

What’s the setup time for this token cost tracking automation?

About 30 minutes if your Telegram/WhatsApp and Google Sheets accounts are ready.

Is coding required for this token cost tracking?

No. You’ll mostly connect credentials and paste in the right Sheet details.

Is n8n free to use for this token 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 OpenRouter/OpenAI usage, which depends on your model and how chatty your bot is.

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 modify this token cost tracking workflow for different use cases?

Yes, and you probably should. You can change what gets logged by editing the “Map Text Fields” and “Update Usage Log” steps (for example, add a Client name, campaign, or internal project code). If you want only Telegram, disable the WhatsApp webhook route; if you want only WhatsApp, you can do the reverse. Many teams also tweak the AI Agent instructions so it returns a consistent “use case label” to store in Sheets.

Why is my Google Sheets connection failing in this workflow?

Usually it’s a permissions issue or the wrong spreadsheet ID. Confirm the Google account in n8n has access to the target Sheet, then re-check the document ID and tab name inside the Google Sheets node. If you recently changed the sheet structure (renamed columns or the tab), update the mapping so the append action still matches. It can also fail if your Google authorization expired, so re-authenticate the credential and run one test execution.

What volume can this token cost tracking workflow process?

Plenty for most small teams: hundreds of chat messages a day is realistic if your n8n instance is sized well. If you self-host, executions aren’t capped by n8n, but your server and API rate limits will be the real bottleneck. On n8n Cloud, your limit depends on the plan, so heavy usage may push you into a paid tier. Google Sheets can also become the limiting factor if you write too many rows too quickly, so batching or a database is better at higher volume.

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

Often, yes. This workflow includes branching (Telegram vs WhatsApp), error routing, and optional audio transcription, and those multi-step paths can get expensive or awkward in Zapier. n8n also gives you the self-host option, which is useful when message volume grows. That said, if your only goal is “send token usage to a sheet” with one source and no audio, Zapier or Make might feel simpler. If you want a second opinion, Talk to an automation expert and we’ll sanity-check your setup.

Once this is running, AI usage stops being a surprise and starts being a report. The workflow handles the repetitive logging so you can actually manage the spend.

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