Use Any LLM Model with OpenRouter and n8n Automation

Struggling to integrate diverse large language models into your projects? This n8n workflow leverages OpenRouter to seamlessly connect any LLM, enabling dynamic prompts, memory, and agent-based AI responses for smarter automation.
chatTrigger
set
agent
+3
Workflow Identifier: 1933
NODES in Use: chatTrigger, set, agent, memoryBufferWindow, lmChatOpenAi, stickyNote

Press CTRL+F5 if the workflow didn't load.

Learn how to Build this Workflow with AI:

Visit through Desktop for Best experience

What This Automation Does ⚙️

This workflow helps users connect to many large language models (LLMs) through OpenRouter easily.
It solves the problem where switching LLMs meant rewriting code every time.
The result is faster setup and flexible AI responses with saved conversation history.

You get a system that listens for chat messages, selects any LLM model you want dynamically, remembers past chat per user session, and creates smart replies using an AI agent.


Tools and Services Used

  • OpenRouter API: Provides access to many large language models via one interface.
  • n8n automation platform: Hosts and runs the workflow nodes that handle chat and AI tasks.
  • Langchain integration in n8n: Offers nodes for chat triggers, AI agents, chat memory, and language model calls.
  • Webhook URL: Triggers the workflow when new chat inputs arrive.

How This Workflow Works (Input → Process → Output)

Inputs

  • Incoming chat messages via webhook from users or clients.
  • Dynamic model selection string indicating which LLM to use (e.g., “deepseek/deepseek-r1-distill-llama-8b”).
  • Session identifiers from chat input to manage memory per user.

Processing Steps

  • Langchain Chat Trigger listens for new chat inputs and activates the workflow.
  • Set Node defines key variables: model ID, prompt from chat, and session ID.
  • Langchain OpenAI Chat node uses the model ID to call OpenRouter and get AI responses.
  • Langchain Memory Buffer Window manages the chat history per session ID to keep context alive.
  • Langchain AI Agent combines prompt, model reply, and memory to generate the final AI reply.

Outputs

  • Smart, context-aware AI chatbot responses sent back upon incoming messages.
  • Ability to switch the AI model used without changing the main flow.
  • Stored user conversation history per session for better dialogue.

Beginner Step-by-Step: How to Use This Workflow in n8n

Download and Import

  1. Click the Download button on this page to get the workflow JSON file.
  2. Open n8n editor where workflows are managed.
  3. Choose the Import from File option and select the downloaded JSON file.

Configure Credentials

  1. Go to the Langchain OpenAI Chat node and add your OpenRouter API Key in credentials.
  2. If there are nodes needing IDs, emails, or folders, update those fields to your setup.

Test and Activate

  1. Trigger the webhook URL manually by sending a simple chat message JSON, or use the test panel to check the nodes.
  2. Fix any errors by checking credentials or model names.
  3. Once testing shows proper responses, toggle the workflow status to active. This puts it into production handling live user chats.

If hosting n8n on your own server, consider seeing a self-host n8n option to keep full control.


Customize Your Workflow

  • Change the model value in the Set node to try other LLMs available on OpenRouter like “google/gemini-2.0-flash-001”.
  • Adjust the buffer size in Langchain Memory Buffer Window node for how much past chat to remember.
  • Add a Code node after the AI Agent to log conversations for audits or debugging.
  • Edit prompts in the Set node to prepend instructions or change tone of the AI replies.

Common Issues and Fixes

  • AI Agent has no reply: Check that OpenRouter API Key and model string are correct in the Langchain OpenAI Chat node.
  • Session memory lost context: Verify that sessionId is correctly extracted and passed in the Set node matching no typos.
  • Webhook not triggering: Ensure the webhook URL from Langchain Chat Trigger is correct and public.
  • Model name invalid: Confirm the model ID matches a model listed on OpenRouter’s model list.

Summary

✓ Save time by using one workflow for multiple LLMs with just one setting change.
✓ Keep chat context well with session memory for better conversations.
✓ Get AI replies that use an agent to think and answer clearly.
→ Easy import, configure, and activate steps make it simple to go live fast.


Frequently Asked Questions

The user can change the model by editing the model field in the Set node to match the desired OpenRouter-compatible LLM model string.
No response occurs if the OpenRouter API Key is missing or incorrect, or the model name in the Langchain OpenAI Chat node is invalid.
Conversation context is preserved per user session using the Langchain Memory Buffer Window node, which stores chat history based on sessionId.
The user must add OpenRouter API credentials, update any IDs or channels if needed, test the workflow by sending test inputs, and then activate it to start production use.

Promoted by BULDRR AI

Related Workflows

Automate Viral UGC Video Creation Using n8n + Degaus (Beginner-Friendly Guide)

Learn how to automate viral UGC video creation using n8n, AI prompts, and Degaus. This beginner-friendly guide shows how to import, configure, and run the workflow without technical complexity.
Form Trigger
Google Sheets
Gmail
+37
Free

AI SEO Blog Writer Automation Workflows in n8n

A complete beginner guide to building an AI SEO blog writer automation using n8n.
AI Agent
Google Sheets
httpRequest
+5
Free

Automate CrowdStrike Alerts with VirusTotal, Jira & Slack

This workflow automates processing of CrowdStrike detections by enriching threat data via VirusTotal, creating Jira tickets for incident tracking, and notifying teams on Slack for quick response. Save hours daily by transforming complex threat data into actionable alerts effortlessly.
scheduleTrigger
httpRequest
jira
+5
Free

Automate Telegram Invoices to Notion with AI Summaries & Reports

Save hours on financial tracking by automating invoice extraction from Telegram photos to Notion using Google Gemini AI. This workflow extracts data, records transactions, and generates detailed spending reports with charts sent on schedule via Telegram.
lmChatGoogleGemini
telegramTrigger
notion
+9
Free

Automate Email Replies with n8n and AI-Powered Summarization

Save hours managing your inbox with this n8n workflow that uses IMAP email triggers, AI summarization, and vector search to draft concise replies requiring minimal review. Automate business email processing efficiently with AI guidance and Gmail integration.
emailReadImap
vectorStoreQdrant
emailSend
+12
Free

Automate Email Campaigns Using n8n with Gmail & Google Sheets

This n8n workflow automates personalized email outreach campaigns by integrating Gmail and Google Sheets, saving hours of manual follow-up work and reducing errors in email sequences. It ensures timely follow-ups based on previous email interactions, optimizing communication efficiency.
googleSheets
gmail
code
+5
Free