Skip to main content

Categorize Airtable invoices with OpenAI and TOON token optimization

Workflow preview

Workflow preview
100%
Categorize Airtable invoices with OpenAI and TOON token optimization preview
Open on n8n.io

1. Workflow Overview

️ Notice: This workflow uses the CustomJS JSON to TOON node from CustomJS, which requires a self hosted n8n instance and...

Best for

  • Invoice Processing automation workflows
  • AI Summarization automation workflows
  • advanced n8n builders looking for reusable templates

Tools used

@n8n/n8n-nodes-langchain.openai, @custom-js/n8n-nodes-pdf-toolkit.jsontotoon, n8n-nodes-base.manualtrigger, n8n-nodes-base.stickynote, n8n-nodes-base.airtable, n8n-nodes-base.aggregate, n8n-nodes-base.splitinbatches, n8n-nodes-base.set

Source and attribution

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

Original n8n.io source

1.1 Workflow description

Title
Categorize Airtable invoices with OpenAI and TOON token optimization
Workflow name
Categorize Airtable invoices with OpenAI and TOON token optimization

> ⚠️ Notice: > This workflow uses the CustomJS JSON to TOON node from CustomJS, which requires a self-hosted n8n instance and a CustomJS API key.


This workflow demonstrates how to automatically categorize invoices from Airtable using OpenAI, while significantly reducing token usage by converting structured data into TOON (Token-Optimized Object Notation) before sending it to the LLM.

Instead of passing large, nested JSON payloads (clients, invoices, invoice items) directly to OpenAI, the workflow converts the data into TOON, lets the AI focus purely on semantic classification, and then converts the result back into clean JSON that can safely be written back to Airtable.

The result is a reliable, cost-efficient, and production-ready invoice categorization pipeline.


Why This Workflow?

Categorizing invoices based on free-text invoice items is a perfect AI use case — but sending raw JSON to LLMs is:

  • expensive
  • slow
  • error-prone (broken JSON, hallucinated fields)

This workflow applies the TOON pattern, reducing token usage by 40–60%, while ensuring the AI only returns exactly the data you expect.

The LLM never sees raw JSON syntax — only a compact, schema-preserving representation.


What This Workflow Does

  • Fetches Invoices, Invoice Items, and Clients from Airtable
  • Aggregates invoice items per invoice
  • Converts the structured data into TOON
  • Uses OpenAI to assign exactly one category per invoice
  • Converts the AI result back into JSON
  • Writes the category back to Airtable

All without manual intervention.


Key Features

  • AI-based Invoice Categorization Automatically classify invoices (e.g. web_development, system_administration)

  • TOON Token Optimization Reduce OpenAI token usage by 40–60%

  • Schema Safety AI never breaks your JSON structure

  • Deterministic Output One category per invoice, enforced by prompt design

  • Airtable-Native Reads from and writes directly back to Airtable


How It Works

  1. Manual Trigger Run the workflow on demand

  2. Load Data from Airtable

  • Fetch ready invoices
  • Resolve related clients
  • Fetch and aggregate invoice items
  1. Prepare Structured Context Group client, invoice, and invoice items into a single object

  2. JSON → TOON Convert structured data into token-efficient TOON

  3. AI Categorization

  • OpenAI receives TOON data
  • Assigns exactly one category per invoice
  • Returns only TOON (no JSON, no prose)
  1. TOON → JSON Convert AI output back into valid JSON

  2. Persist Result Update the invoice category field in Airtable

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 - OpenAI Enhancement

Type / Role
@n8n/n8n-nodes-langchain.openAi - openAi
Config choices
Version 2.1

Block 2 - JSON to TOON

Type / Role
@custom-js/n8n-nodes-pdf-toolkit.jsonToToon - jsonToToon
Config choices
Version 1

Block 3 - When clicking ‘Execute workflow’

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

Block 4 - Sticky Note

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

Block 5 - Get Ready Invoices

Type / Role
n8n-nodes-base.airtable - airtable
Config choices
Version 2.1

Block 6 - Get Clients

Type / Role
n8n-nodes-base.airtable - airtable
Config choices
Version 2.1

Block 7 - Get Invoice Items

Type / Role
n8n-nodes-base.airtable - airtable
Config choices
Version 2.1

Block 8 - Aggregate

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

Block 9 - Loop Over Items

Type / Role
n8n-nodes-base.splitInBatches - splitInBatches
Config choices
Version 3

Block 10 - Update record

Type / Role
n8n-nodes-base.airtable - airtable
Config choices
Version 2.1

Block 11 - Map Fields

Type / Role
n8n-nodes-base.set - set
Config choices
Version 3.4

Block 12 - GroupClientAndInvoice

Type / Role
n8n-nodes-base.set - set
Config choices
Version 3.4

Block 13 - TOON to JSON

Type / Role
@custom-js/n8n-nodes-pdf-toolkit.toonToJson - toonToJson
Config choices
Version 1

Block 14 - Sticky Note1

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

Block 15 - Sticky Note2

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

Block 16 - Sticky Note3

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

3. Summary Table

Workflow Categorize Airtable invoices with OpenAI and TOON token optimization
Complexity advanced
Nodes 16
Categories Invoice Processing, AI Summarization
Author CustomJS
Published 13 Dec 2025

4. Reproducing the Workflow from Scratch

  1. 1. Download the workflow JSON

    Use the JSON export at /data/workflows/11761/11761.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 Categorize Airtable invoices with OpenAI and TOON token optimization do?

️ Notice: This workflow uses the CustomJS JSON to TOON node from CustomJS, which requires a self hosted n8n instance and...

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 Invoice Processing, AI Summarization use case.