Tips > AI & LLM Integration

Chain Multiple AI Calls -- Classify Cheap, Generate Expensive

Not every input needs a large, expensive model.

TipIntermediate2 min read

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)

Want this running in your stack?

I build production n8n and Cloudflare automation for teams — the same engineering behind HarperFlow. Fixed-price, escrow-protected, US-based.