Skip to main content

Track and monitor AI token usage metrics for OpenAI and Gemini models

Workflow preview

Workflow preview
100%
Track and monitor AI token usage metrics for OpenAI and Gemini models preview
Open on n8n.io

Important notice

This workflow is provided as-is. Please review and test before using in production.

1. Workflow Overview

Token Usage Metrics Workflow Descripción: Este flujo de trabajo en n8n extrae y resume las métricas de uso de tokens (prompt, completion y total) y los modelos utilizados en una ejecución especí...

Best for

  • Engineering automation workflows
  • Multimodal AI automation workflows
  • intermediate n8n builders looking for reusable templates

Tools used

n8n-nodes-base.n8n, n8n-nodes-base.executeworkflowtrigger, n8n-nodes-base.code, n8n-nodes-base.stickynote, n8n-nodes-base.executeworkflow, @n8n/n8n-nodes-langchain.chattrigger, @n8n/n8n-nodes-langchain.agent, @n8n/n8n-nodes-langchain.lmchatgooglegemini

Source and attribution

This workflow is cataloged by N8N Workflows and links back to its original n8n.io source page by Elimeleth.

Original n8n.io source

1.1 Workflow description

Title
Track and monitor AI token usage metrics for OpenAI and Gemini models
Workflow name
Track and monitor AI token usage metrics for OpenAI and Gemini models

📊 Token Usage Metrics Workflow

Descripción: Este flujo de trabajo en n8n extrae y resume las métricas de uso de tokens (prompt, completion y total) y los modelos utilizados en una ejecución específica. Requiere el execution_id y un array con los nombres de los nodos de AI (por ejemplo: openai, gemini).

Requisitos:

execution_id: ID de la ejecución de n8n de la cual se extraerán los datos.

model_names: Array con los nombres de los nodos AI a buscar (ejemplo: openai, gemini).

Funcionamiento:

Obtiene la ejecución con el ID proporcionado.

Busca en los nodos indicados la información de token usage dentro de la ejecución.

Suma los tokens usados y genera un listado de modelos utilizados.

Devuelve métricas totales y un desglose detallado por modelo.

Configuración recomendada:

Este workflow debe configurarse para ejecutarse siempre al final del flujo de trabajo.

Desactivar la opción “Esperar a que termine” para evitar bloqueos y asegurar que se obtenga la ejecución completa.

📊 Token Usage Metrics Workflow

Description: This n8n workflow extracts and summarizes token usage metrics (prompt, completion, and total tokens) along with the models used in a specific execution. It requires the execution_id and an array of AI node names (e.g., openai, gemini).

Requirements:

execution_id: The n8n execution ID from which data will be extracted.

model_names: An array of AI node names to search for (e.g., openai, gemini).

How It Works:

Fetches the execution using the provided ID.

Searches the specified nodes for token usage information within the execution.

Aggregates token counts and compiles a list of models used.

Returns total metrics and a detailed breakdown per model.

Recommended Configuration:

Configure this workflow to run always at the end of your workflow.

Disable the “Wait until finished” option to avoid blocking and ensure the complete execution data is available.

1.2 Logical Blocks

This catalog entry is organized from the workflow JSON. The node-level section below shows the executable blocks available for review before importing the template.

2. Block-by-Block Analysis

Block 1 - Get an execution

Type / Role
n8n-nodes-base.n8n - n8n
Config choices
Version 1

Block 2 - Start

Type / Role
n8n-nodes-base.executeWorkflowTrigger - executeWorkflowTrigger
Config choices
Version 1.1

Block 3 - map json

Type / Role
n8n-nodes-base.code - code
Config choices
Version 2

Block 4 - Sticky Note

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 5 - Execute Workflow

Type / Role
n8n-nodes-base.executeWorkflow - executeWorkflow
Config choices
Version 1.2

Block 6 - When chat message received

Type / Role
@n8n/n8n-nodes-langchain.chatTrigger - chatTrigger
Config choices
Version 1.3

Block 7 - AI Agent

Type / Role
@n8n/n8n-nodes-langchain.agent - agent
Config choices
Version 2.2

Block 8 - gemini

Type / Role
@n8n/n8n-nodes-langchain.lmChatGoogleGemini - lmChatGoogleGemini
Config choices
Version 1

Block 9 - openai

Type / Role
@n8n/n8n-nodes-langchain.lmChatOpenAi - lmChatOpenAi
Config choices
Version 1.2

Block 10 - Simple Memory

Type / Role
@n8n/n8n-nodes-langchain.memoryBufferWindow - memoryBufferWindow
Config choices
Version 1.3

3. Summary Table

Workflow Track and monitor AI token usage metrics for OpenAI and Gemini models
Complexity intermediate
Nodes 10
Categories Engineering, Multimodal AI
Author Elimeleth
Published 11 Aug 2025

4. Reproducing the Workflow from Scratch

  1. 1. Download the workflow JSON

    Use the JSON export at /data/workflows/7265/7265.json as the source template for this automation.

  2. 2. Import the template into n8n

    Open n8n, import the downloaded JSON, and review each node before activating the workflow.

  3. 3. Configure credentials and variables

    Replace placeholder credentials, API keys, webhook URLs, account IDs, and environment-specific values with your own settings.

  4. 4. Test with sample data

    Run the workflow manually or in a staging workspace, inspect node output, and confirm downstream systems receive the expected data.

  5. 5. Activate and monitor

    Enable the workflow only after testing, then monitor executions, errors, and rate limits during the first production runs.

5. General Notes & Resources

Review imported nodes carefully before activation. This catalog entry is intended to help you inspect the workflow structure, understand required services, and find related templates faster.

Node names, credentials, schedules, webhook paths, and external service limits may need adjustment for your workspace.

Frequently asked questions

What does Track and monitor AI token usage metrics for OpenAI and Gemini models do?

Token Usage Metrics Workflow Descripción: Este flujo de trabajo en n8n extrae y resume las métricas de uso de tokens (prompt, completion y total) y los modelos utilizados en una ejecución especí...

What do I need before importing this workflow?

Review the workflow JSON, configure any required credentials in n8n, and test the automation in a safe workspace before using it in production.

Can I customize this workflow?

Yes. Use the block-by-block analysis and the downloadable JSON to inspect each node, then adjust credentials, prompts, schedules, filters, or destinations for your Engineering, Multimodal AI use case.