Templates / Route AI queries cost‑efficiently with GPT‑4o‑mini, GPT‑4o and confidence scoring

Route AI queries cost‑efficiently with GPT‑4o‑mini, GPT‑4o and confidence scoring

Ready for 3.0

by ResilNext ✓ · 32 views · created 2026-03-09 · Engineering, AI Summarization

Ready for 3.0. This template uses no nodes that n8n 3.0 removes. No removed nodes, versions or helpers found. Static check, last run 2026-10-19.

What this workflow does

This AI workflow has 10 nodes and runs when an HTTP POST request hits its webhook URL. Along the way it connects OpenAI Chat Model and OpenAI.

How it runs

Trigger: When an HTTP POST request hits its webhook URL.

  1. Workflow Configuration (Edit Fields (Set)): sets 3 fields: confidenceThreshold, cheapModelCostPer1kTokens, expensiveModelCostPer1kTokens
  2. Cheap Model (GPT-5-mini) (OpenAI): uses OpenAI
  3. Confidence Evaluator (AI Agent): runs an AI agent, with model: OpenAI Chat Model; output parser: Parse Confidence JSON
  4. Check Confidence Threshold (If): checks a condition and branches into true / false
  5. Expensive Model (GPT-5.4) (OpenAI): uses OpenAI
  6. Calculate Cost Difference (Code): runs custom JavaScript code
  7. Format Final Response (Edit Fields (Set)): sets 6 fields: response, model_used, confidence_score…

Services it uses

OpenAI Chat ModelOpenAI

Before you upgrade to n8n 3.0

Nothing in this workflow is removed in n8n 3.0, so it should import and run after the upgrade.

Nodes used (8)

From the author

This workflow implements a cost-optimized AI routing system using n8n. It intelligently decides whether a request should be handled by a low-cost model or escalated to a higher-quality model based on response confidence. The goal is to minimize LLM usage…

Excerpt from ResilNext's description on n8n.io.

View the original on n8n.io → Check your own copy

Get the weekly “what broke” email

New templates, newly broken ones, and n8n release changes. One short email a week.

Form not loading? Subscribe here.