Skip to main content

Smart chat routing between Gemini and GPT models based on query complexity

Workflow preview

Workflow preview
100%
Smart chat routing between Gemini and GPT models based on query complexity preview
Open on n8n.io

Important notice

This workflow is provided as-is. Please review and test before using in production.

1. Workflow Overview

Adaptive LLM Router for Optimized AI Chat Responses Elevate your AI chatbots with intelligent model selection: automatically route simple queries to cost effective LLMs and complex ones to powerful...

Best for

  • Engineering automation workflows
  • AI Chatbot automation workflows
  • intermediate n8n builders looking for reusable templates

Tools used

@n8n/n8n-nodes-langchain.agent, @n8n/n8n-nodes-langchain.chattrigger, @n8n/n8n-nodes-langchain.modelselector, @n8n/n8n-nodes-langchain.lmchatopenai, @n8n/n8n-nodes-langchain.lmchatgooglegemini, n8n-nodes-base.stickynote

Source and attribution

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

Original n8n.io source

1.1 Workflow description

Title
Smart chat routing between Gemini and GPT models based on query complexity
Workflow name
Smart chat routing between Gemini and GPT models based on query complexity

Adaptive LLM Router for Optimized AI Chat Responses

Elevate your AI chatbots with intelligent model selection: automatically route simple queries to cost-effective LLMs and complex ones to powerful ones, balancing performance and expenses seamlessly.

What It Does

This workflow listens for chat messages, uses a lightweight Gemini model to classify query complexity, then selects and routes to the optimal LLM (Gemini 2.5 Pro for complex, OpenAI GPT-4.1 Nano for simple) to generate responses—ensuring efficient resource use.

Key Features

  • Complexity Classifier - Quick assessment using Gemini 2.0 Flash
  • Dynamic Model Switching - Routes to premium or budget models based on needs
  • Chat Trigger - Webhook-based for real-time conversations
  • Current Date Awareness - Injects $now into system prompt
  • Modular Design - Easy to add more models or adjust rules
  • Cost Optimization - Reserves heavy models for demanding tasks only

Perfect For

  • Chatbot Developers: Build responsive, cost-aware AI assistants
  • Customer Support: Handle routine vs. technical queries efficiently
  • Educational Tools: Simple facts vs. in-depth explanations
  • Content Creators: Quick ideas vs. detailed writing assistance
  • Researchers: Basic lookups vs. complex analysis
  • Business Apps: Optimize API costs in production environments

Technical Highlights

Harnessing n8n's LangChain nodes, this workflow demonstrates:

  • Webhook triggers for instant chat handling
  • Agent-based classification with strict output rules
  • Conditional model selection for AI chains
  • Integration of multiple LLM providers (Google Gemini, OpenAI)
  • Scalable architecture for expanding model options

Ideal for minimizing AI costs while maximizing response quality. No coding required—import, configure credentials, and deploy!

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 - Model Selector

Type / Role
@n8n/n8n-nodes-langchain.agent - agent
Config choices
Version 1.9

Block 2 - When chat message received

Type / Role
@n8n/n8n-nodes-langchain.chatTrigger - chatTrigger
Config choices
Version 1.3

Block 3 - Model selector

Type / Role
@n8n/n8n-nodes-langchain.modelSelector - modelSelector
Config choices
Version 1

Block 4 - Main Agent

Type / Role
@n8n/n8n-nodes-langchain.agent - agent
Config choices
Version 2.2

Block 5 - 4.1 nano

Type / Role
@n8n/n8n-nodes-langchain.lmChatOpenAi - lmChatOpenAi
Config choices
Version 1.2

Block 6 - 2.5 pro

Type / Role
@n8n/n8n-nodes-langchain.lmChatGoogleGemini - lmChatGoogleGemini
Config choices
Version 1

Block 7 - 2.0 flash

Type / Role
@n8n/n8n-nodes-langchain.lmChatGoogleGemini - lmChatGoogleGemini
Config choices
Version 1

Block 8 - Overview Note

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

Block 9 - Note: Trigger

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

Block 10 - Note: Classifier

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

Block 11 - Note: Main Agent

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

3. Summary Table

Workflow Smart chat routing between Gemini and GPT models based on query complexity
Complexity intermediate
Nodes 11
Categories Engineering, AI Chatbot
Author Daniel Nkencho
Published 03 Oct 2025

4. Reproducing the Workflow from Scratch

  1. 1. Download the workflow JSON

    Use the JSON export at /data/workflows/9247/9247.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 Smart chat routing between Gemini and GPT models based on query complexity do?

Adaptive LLM Router for Optimized AI Chat Responses Elevate your AI chatbots with intelligent model selection: automatically route simple queries to cost effective LLMs and complex ones to powerful...

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 Engineering, AI Chatbot use case.