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
Automate LLM models with n8n and OpenRouter

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

Learn how to Build this Workflow with AI:

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.


Automate LLM models with n8n and OpenRouter

Visit through Desktop to Interact with the Workflow.

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 Twist Channel Creation and Messaging with n8n

This workflow automates creating and updating a channel in Twist and sending a personalized message to specific users. It eliminates manual setup errors and saves time managing Twist communications.

Automate Ideogram Image Generation with Google Sheets & Gmail

This workflow automates graphic design image generation via Ideogram AI, storing image data in Google Sheets and Google Drive, with email alerts via Gmail. It saves designers hours by automating image creation, remixing, review, and record-keeping.

Automate IT Support with Slack and OpenAI in n8n

Streamline IT support by automating Slack message handling using n8n and OpenAI. This workflow handles Slack DMs, filters bots, queries a Confluence knowledge base, and delivers AI-generated responses, improving support efficiency and response time.

Automate Crypto Analysis with CoinMarketCap & n8n AI Agent

Discover how this unique n8n workflow leverages CoinMarketCap’s multi-agent AI to deliver precise, real-time cryptocurrency insights directly via Telegram. Manage crypto data analysis efficiently with automated multi-source API integration.

Automate Gumroad to Beehiiv Subscriber Sync with n8n

Learn how to automatically add new Gumroad sales customers as Beehiiv newsletter subscribers using n8n automation. This workflow saves time by syncing sales data to Google Sheets CRM and notifying your Telegram channel instantly.

Generate On-Brand Blog Articles Using n8n and OpenAI

This workflow automates the creation of on-brand blog articles by analyzing existing company content using n8n and OpenAI. It extracts article structures and brand voice to produce consistent draft articles, saving significant content creation time.
1:1 Free Strategy Session
Your competitors are already automating. Are you still paying for it manually?

Do you want to adopt AI Automation?

Every hour your team does repetitive work, you're burning real money.
While you wait, faster businesses are cutting costs and moving quicker.
AI and automations aren't the future anymore — they're the present.

Book a live 1-on-1 session where we show you exactly which of your daily tasks can be automated — and what it’s costing you not to.