Route AI queries cost‑efficiently with GPT‑4o‑mini, GPT‑4o and confidence scoring
Ready for 3.0What 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.
- Workflow Configuration (Edit Fields (Set)): sets 3 fields: confidenceThreshold, cheapModelCostPer1kTokens, expensiveModelCostPer1kTokens
- Cheap Model (GPT-5-mini) (OpenAI): uses OpenAI
- Confidence Evaluator (AI Agent): runs an AI agent, with model: OpenAI Chat Model; output parser: Parse Confidence JSON
- Check Confidence Threshold (If): checks a condition and branches into true / false
- Expensive Model (GPT-5.4) (OpenAI): uses OpenAI
- Calculate Cost Difference (Code): runs custom JavaScript code
- Format Final Response (Edit Fields (Set)): sets 6 fields: response, model_used, confidence_score…
Services it uses
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)
- Webhook
n8n-nodes-base.webhook - Edit Fields (Set)
n8n-nodes-base.set - If
n8n-nodes-base.if - Code
n8n-nodes-base.code - AI Agent
@n8n/n8n-nodes-langchain.agent - Structured Output Parser
@n8n/n8n-nodes-langchain.outputParserStructured - OpenAI Chat Model
@n8n/n8n-nodes-langchain.lmChatOpenAi - OpenAI
@n8n/n8n-nodes-langchain.openAi
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…