Tips > AI & LLM Integration

Chain Multiple AI Calls -- Classify Cheap, Generate Expensive

Not every input needs a large, expensive model.

Not every input needs a large, expensive model. Use a two-stage pattern: a fast, cheap model classifies or triages the input, and only inputs that require sophisticated generation get routed to the more powerful (and costly) model. This can cut LLM costs by 60-80% in high-volume workflows.

Real-world example: Incoming customer questions are classified by gpt-4o-mini (fast, cheap). Only complex questions are sent to claude-sonnet-4-20250514 for a detailed response. Simple FAQs get a template answer.

Workflow structure:

[Webhook] → [Classify: gpt-4o-mini] → [IF: is_complex] →── true ──→ [Generate: Claude Sonnet]
                                                          └─ false ─→ [Template Response]
```text
**Classification node** (OpenAI, gpt-4o-mini):

```text
Classify the following customer question into exactly one category:
- "faq" — answerable from standard documentation
- "complex" — requires detailed, contextual reasoning
- "escalate" — needs human agent

Return JSON: {"type": "faq" | "complex" | "escalate", "faq_topic": "string or null"}

Question: {{ $json.question }}
```text
**IF node** condition:

```text
{{ JSON.parse($json.message.content).type === "complex" }}
```text
**Generation node** (Anthropic, Claude Sonnet) -- only runs for complex questions:

```text
You are a senior customer success agent. Provide a thorough, empathetic
response to this customer question. Reference specific product features
and include next steps.

Question: {{ $json.question }}
Customer tier: {{ $json.account_tier }}
```text
Cost comparison for 1,000 daily questions (hypothetical):

| Approach           | Model           | Cost/day (approx) |
|--------------------|-----------------|--------------------|
| All to Sonnet      | Claude Sonnet   | ~$15.00            |
| Classify + Route   | Mini + Sonnet   | ~$4.50             |

The classify-then-route pattern is one of the highest-ROI optimizations for AI workflows at scale.

**Related:** [Use Manual Trigger During Development Instead of Webhook or Schedule](../api-cost-optimization/01-use-manual-trigger-during-development-instead-of-webhook-or-schedule.md) | [Flatten Deeply Nested API Responses](../code-node-mastery/01-flatten-deeply-nested-api-responses.md)

Showcase builds

19 complete workflows from my own projects, each with its n8n workflow JSON to import. Showcase entries link the file at the end of the article.

See the showcase builds

Keep reading

191 entries grouped by topic, from first workflow to queue mode. Free, no signup.

Browse the encyclopedia

Need it built?

I design, build and run n8n systems for clients. Every engagement starts with a $1,500 diagnostic audit, credited toward the build.

Book a 20-minute call