Dynamic AI Model Router and Orchestrator - n8n Workflow

Deploy a sophisticated n8n workflow to route user queries dynamically to the best LLM (GPT, Claude, Gemini, Perplexity) based on request type (coding, reasoning, general). Perfect n8n template for AI orchestration.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Users building advanced, multi-model AI chatbots.
Developers needing robust n8n templates for AI model management.
Engineers focused on optimizing LLM usage and minimizing costs.
Anyone seeking to deploy complex AI orchestration using the n8n node ecosystem.

Overview

This advanced n8n workflow solves the common problem of relying on a single Large Language Model (LLM) for diverse conversational tasks. By implementing a smart classification layer, the n8n automation first determines the intent of the user's message (e.g., coding, complex reasoning, or general query). It then uses the powerful Model Selector n8n node to dynamically dispatch the query to the specific LLM best suited for that task. For instance, coding questions are routed to a top-tier code model like Claude Opus 4, while reasoning tasks go to a highly capable GPT n8n node. This approach maximizes response quality, ensures speed, and significantly improves cost efficiency, making this one of the most practical n8n templates for building scalable AI solutions.

How it Works

This intelligent n8n workflow operates entirely based on dynamic routing decisions:


  1. Trigger: The automation starts via the When chat message received n8n trigger, which activates the n8n workflow upon receiving a new user input from the configured chat application.

  2. Classification: The input is immediately processed by the Request Type Chain LLM. This step uses a primary OpenAI Chat Model alongside a Structured Output Parser n8n node to classify the user's intent into categories like 'coding', 'reasoning', 'general', or 'search'.

  3. Orchestration & Memory: The classified data is passed to the central AI Agent n8n node. This agent maintains conversation context using the Simple Memory n8n node, ensuring the LLM response is relevant to the history.

  4. Dynamic Routing: The Model Selector n8n node reads the request_type output from the classification step. It contains preset rules that match the intent to a specific LLM.

For 'coding' requests, the n8n workflow routes to Anthropic's Opus
4.
For 'reasoning' requests, it routes to GPT 4.1 mini.
* For 'general' requests, it routes to Perplexity via OpenRouter.

  1. Execution: The selected specialist LLM executes the task and generates a high-quality response, which is then fed back through the n8n workflow to the user.

Installation Guide

To install this robust n8n workflow, follow these steps:


  1. Import: Copy the provided JSON code. In your n8n instance, go to the Workflows section, click 'New', and select 'Import from JSON'.

  2. Credentials Setup: This n8n template requires several credentials for the various LLM nodes:

OpenAI API Key (for GPT classification and execution).
Anthropic API Key (for Claude Opus 4).
Google Gemini/PaLM API Key.
OpenRouter API Key (for Perplexity).

  1. Trigger Configuration: Activate the When chat message received n8n trigger. You may need to specify the chat platform or configure the webhook ID depending on your environment.

  2. Activation: Once all credentials are set up in each corresponding n8n node, save and activate the n8n workflow to begin dynamic routing.

Node Details

The core intelligence of this n8n workflow is built upon specialized Langchain n8n node types:

When chat message received (n8n trigger):
Function: Starts the n8n workflow immediately upon receiving a chat message input.
Key Configuration: Uses a specific webhook ID to listen for incoming chat data.

Request Type (Chain LLM) & OpenAI Chat Model:
Function: Classifies the incoming text using an initial LLM model (GPT 4.1 mini) based on a defined prompt that outputs the request type (coding, reasoning, general, search).
Key Configuration: Input prompt explicitly defines the classification criteria.

Structured Output Parser (n8n node):
Function: Enforces a rigid JSON schema {"requesttype": "string"} on the LLM's classification output, ensuring reliable data for the Model Selector.
Key Configuration: Defines a simple object schema to capture the classification.

AI Agent (n8n node):
Function: Acts as the execution orchestrator, tying together the input, memory, and the dynamically selected LLM for the final task.
Key Configuration: Input text is mapped from the original chatInput of the n8n trigger.

Simple Memory (n8n node):
Function: Manages conversation history, using the chat sessionId to maintain context for multi-turn conversations.

Model Selector (n8n node):
Function: The central routing decision point. It checks the request
type output and directs the query to one of the four connected specialized LLM n8n nodes.
* Key Configuration: Contains conditional logic (e.g., If request_type equals 'coding', use Anthropic's Opus 4).

Related n8n Workflows

Free

Nodes: 11 Nodes
Updated: December 26 2025
View all
Created by

Full-stack Web Developer based in Italy specialising in Marketing & AI-powered automations. For business enquiries, send me an email at [email protected] or add me on Linkedin.com/in/davideboizza

Featured*