Implement smart AI routing with this advanced n8n workflow. Automatically select the best LLM via OpenRouter based on query complexity and type for optimized results. Import this n8n template now.
Download this n8n workflow template and start using it instantly.
Users and organizations seeking to optimize AI costs by routing complex queries only to expensive models, while routing simpler queries to cost-effective ones.
Developers building robust n8n templates who require dynamic LLM selection capabilities.
AI engineers leveraging the diverse model ecosystem provided by OpenRouter.
Anyone looking to implement a sophisticated AI agent structure within an n8n workflow.
Achieving optimal results from Large Language Models often requires utilizing a model specifically tailored to the task—whether it's coding, complex reasoning, or web search. This sophisticated n8n workflow solves the routing problem by implementing an automated Routing Agent.
Instead of hardcoding a single LLM, this n8n automation analyzes the incoming user query (the intent and complexity) and dynamically selects the best-suited model available via OpenRouter (e.g., GPT-4o Mini for reasoning, Claude 3.7 Sonnet for coding, or Perplexity Sonar for web search).
This dynamic routing dramatically improves the quality of the response, reduces latency, and ensures cost efficiency across your n8n deployments. This powerful design serves as an excellent foundation for other complex n8n templates.
This powerful n8n workflow utilizes several LangChain nodes to establish an intelligent decision loop:
When chat message received n8n trigger, which activates the n8n workflow upon receiving a new chat message or query.Routing Agent n8n node. This agent, configured with an extensive system prompt detailing the strengths of eight different models (e.g., perplexity/sonar, openai/gpt-4o-mini), decides which LLM is most suitable for the task.OpenRouter Chat Model provides the reasoning engine for the Routing Agent to make its selection, formulating the decision as a strict JSON object containing the desired target model and the original prompt.Structured Output Parser n8n node strictly enforces the JSON output schema, ensuring the next step receives reliable, structured data (prompt and model).AI Agent. Critically, the OpenRouter Chat Model1 n8n node used for execution has its model parameter dynamically set using an n8n expression: ={{ $json.output.model }}. This completes the dynamic routing, and the appropriate LLM executes the prompt, delivering an optimized response.To deploy this advanced n8n workflow, follow these steps:
OpenRouter Chat Model n8n nodes.When chat message received n8n trigger is a specialized node that requires specific integration (often via n8n's LangChain integration layer). Ensure this n8n trigger is correctly linked to your desired chat front-end or service.Routing Agent parameters, save the n8n workflow and set it to 'Active' to start running the automation.This n8n workflow relies on specialized LangChain integration nodes:
When chat message received (n8n trigger):
Function: Starts the n8n workflow upon receiving input, providing the user query that needs routing.
Key Configuration: Acts as the essential entry point, ensuring immediate response capability.
OpenRouter Chat Model (n8n node):
Function: Provides the Large Language Model service (via OpenRouter) that the Routing Agent uses to analyze the query and make a decision.
Key Configuration: Requires an active OpenRouter credential setup.
Routing Agent (n8n node):
Function: Acts as the AI decision layer. Its extensive system message defines the purpose and capabilities of eight different LLMs, ensuring intelligent model selection based on query intent.
Key Configuration: Contains a detailed prompt defining model strengths (e.g., perplexity/sonar for web search, openai/gpt-4o-mini for reasoning) and enforcing a strict JSON output format.
Structured Output Parser (n8n node):
Function: Ensures the output from the Routing Agent is a validated JSON object with prompt and model fields, preventing errors in the subsequent dynamic model selection.
Key Configuration: Uses a manual schema definition to enforce structure.
OpenRouter Chat Model1 (n8n node):
Function: This is the final execution n8n node. It dynamically calls the specific LLM chosen by the Routing Agent to provide the final answer.
* Key Configuration: The model name is set via an n8n expression: ={{ $json.output.model }}, enabling dynamic routing across the OpenRouter ecosystem.
Automate error alerts for your n8n workflows using WhatsApp and Gmail simultaneously. Use this robust n8n template for immediate incident response and better DevOps monitoring.

Automate lead generation using an n8n workflow that checks for duplicates, assigns unique coupons from Google Sheets, and synchronizes new leads directly into SuiteCRM for efficient follow-up.

Use this powerful n8n workflow to automatically sync your latest Spotify liked songs to a dedicated 'Downloads' playlist, ensuring you always have the newest tracks available offline while maintaining a defined size limit. Explore n8n templates for music automation.

A sophisticated n8n workflow that dynamically updates form dropdowns with available AI models using the n8n node for self-configuration, enabling compliant AI chat interfaces.

Generate highly structured research data and export to CSV using this advanced n8n workflow. Utilizes GPT-4/5 for dynamic planning and Linkup for deep web extraction.

Use this advanced n8n workflow to automate lead routing based on AI qualification. Triggered by HubSpot, it uses GPT-4 and Airtable capacity data to assign leads and send instant notifications via Slack and Gmail.

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







































