Showing posts with label ai agent. Show all posts
Showing posts with label ai agent. Show all posts

Wednesday, 29 April 2026

n8n OpenRouter Tutorial: Build Multi-Model AI Automation Workflows

n8n + OpenRouter Tutorial

How to Use n8n with OpenRouter for Multi-Model AI Automation

Learn how to connect n8n to OpenRouter and use multiple AI models in one automation workflow.

If you want to build flexible AI automations, combining n8n with OpenRouter is a powerful setup. OpenRouter gives you access to many AI models through one unified API, while n8n lets you automate how those models are used.

๐Ÿ’ก Example: user submits a question → n8n sends it to OpenRouter → AI generates a response → result is sent to Telegram, Gmail, CRM, or your website chatbot.

What You’ll Learn

  • What OpenRouter is
  • How to connect OpenRouter to n8n
  • How to call AI models using HTTP Request
  • How to use dynamic prompts from previous nodes
  • How to build real AI automation workflows

What Is OpenRouter?

OpenRouter is a unified AI model gateway. Instead of integrating many separate AI providers one by one, you can call different models through one OpenRouter API.

This is useful when you want to test different models for chatbots, AI agents, blog automation, summarization, customer support, and internal tools.

Simple explanation: OpenRouter is like a router for AI models. n8n sends the request, OpenRouter sends it to the selected AI model.

Step 1: Get Your OpenRouter API Key

  1. Create or log in to your OpenRouter account
  2. Go to API Keys
  3. Create a new API key
  4. Copy and save it securely
⚠️ Security tip: never expose your OpenRouter API key in frontend code or public pages.

Step 2: Add HTTP Request Node in n8n

OpenRouter can be connected using the n8n HTTP Request node.

HTTP Request settings:

  • Method: POST
  • URL: https://openrouter.ai/api/v1/chat/completions
  • Authentication: None or Generic Header Auth
  • Send Body: JSON

Headers:

Content-Type: application/json
Authorization: Bearer YOUR_OPENROUTER_API_KEY

Step 3: Send Your First AI Request

Example JSON body:

{
  "model": "openai/gpt-4o-mini",
  "messages": [
    {
      "role": "system",
      "content": "You are a helpful AI automation assistant."
    },
    {
      "role": "user",
      "content": "Explain n8n in simple terms."
    }
  ]
}

After executing the node, OpenRouter will return an AI-generated response from the selected model.

Step 4: Use Dynamic Data from Previous Nodes

In real workflows, your prompt usually comes from a webhook, form, chat widget, Google Sheet, or database.

Example dynamic message:

{
  "model": "openai/gpt-4o-mini",
  "messages": [
    {
      "role": "system",
      "content": "You are a helpful customer support assistant."
    },
    {
      "role": "user",
      "content": "{{ $json.message }}"
    }
  ]
}

This lets n8n send user input directly to OpenRouter and use the response in the next node.

Step 5: Extract the AI Response

The AI response is usually returned inside the output JSON. In many chat completion responses, the generated text can be found in:

{{ $json.choices[0].message.content }}

You can pass this value to Telegram, Gmail, Google Sheets, WordPress, CRM, or a website chatbot.

Example n8n + OpenRouter Workflow

Webhook / Chat Trigger
   ↓
Set
   ↓
HTTP Request (OpenRouter)
   ↓
Set / Extract AI Response
   ↓
Telegram / Gmail / Google Sheets / WordPress

This workflow receives input, sends it to an AI model through OpenRouter, extracts the AI answer, and sends it to another app.

Real Use Cases

AI chatbot replies
Blog post generation
Email auto-response
AI agent workflows
Document summarization
Customer support automation

Example: AI Support Bot with OpenRouter

You can use OpenRouter as the AI brain of a support bot. A simple workflow can look like this:

Website Chat Form
   ↓
n8n Webhook
   ↓
OpenRouter AI
   ↓
Business Logic / IF Node
   ↓
Reply to User
   ↓
Log to Google Sheets

This is useful for schools, LGUs, service businesses, online stores, and internal helpdesks.

Common Errors and Fixes

1. Unauthorized error
Check your Authorization header and make sure it uses Bearer YOUR_API_KEY.

2. Model not found
Confirm the model ID from the OpenRouter models page before using it.

3. Empty response
Check your messages array and make sure user content is not blank.

4. Wrong output expression
Inspect the HTTP Request output and adjust the expression path if needed.

5. High cost or slow response
Try a smaller model for simple tasks and reserve larger models for complex reasoning.

Best Practices

  • Start with a low-cost model for testing
  • Use clear system prompts
  • Log prompts and responses during development
  • Keep API keys inside n8n credentials or secure variables
  • Use IF nodes to handle errors or empty responses
  • Use different models depending on task complexity

Watch My AI Automation Builds on YouTube

I share real n8n workflows, AI agent builds, and automation systems on my YouTube channel.

▶ Visit My YouTube Channel

FAQ

Can n8n connect to OpenRouter?
Yes. You can use the HTTP Request node to call OpenRouter’s API directly.

Is OpenRouter compatible with OpenAI-style requests?
Yes. OpenRouter’s request and response schemas are similar to the OpenAI Chat API, which makes it easier to integrate.

Can I use OpenRouter for AI agents?
Yes. You can use OpenRouter as the model backend for AI chatbots, assistants, and agent-style workflows in n8n.


SEO Title

n8n OpenRouter Tutorial: Build Multi-Model AI Automation Workflows

Meta Description

Learn how to connect n8n with OpenRouter using HTTP Request, send AI prompts, extract responses, and build multi-model AI automation workflows.

Suggested Labels

n8n, OpenRouter, AI Automation, AI Agent, Workflow Automation, Chatbot, OpenAI API, Blogspot Tutorial

Thursday, 16 April 2026

How to Create an AI Agent in n8n Using AI Agent Node and OpenAI

n8n + OpenAI Tutorial

How to Create an AI Agent in n8n Using AI Agent Node and OpenAI

Learn how to build a working AI agent in n8n using the AI Agent node, OpenAI Chat Model, tools, memory, and chat trigger.

If you want to build an AI agent inside n8n, the easiest modern setup is to use the AI Agent node together with the OpenAI Chat Model node. This lets your agent understand user requests, choose tools, and return useful answers automatically.

Important: In current n8n versions, the AI Agent now works as a Tools Agent. Also, you must connect at least one tool to the AI Agent node for it to work properly.

What You’ll Learn

  • What the AI Agent node does in n8n
  • How to connect OpenAI to n8n
  • How to add Chat Trigger, Memory, and Tools
  • How to test your first AI agent
  • Common mistakes and how to fix them

What Is the AI Agent Node in n8n?

The AI Agent node in n8n is used to create an autonomous assistant that can receive input, reason about the task, and use connected tools to perform actions or retrieve information. Instead of giving only a simple text response, an agent can decide which tool to use depending on the user’s request.

This is what makes it different from a normal prompt-based AI flow. An AI agent can do more than just answer questions. It can also interact with APIs, run tools, search knowledge, and handle more advanced logic.

๐Ÿ’ก Simple explanation: a normal AI node answers; an AI agent can also decide and act.

What You Need Before Starting

  • A working n8n instance
  • An OpenAI account and API key
  • Basic understanding of nodes and workflow connections

n8n supports OpenAI authentication using an API key. After you add the credential, you can use it in the OpenAI Chat Model node.

Basic Workflow Structure

Your first AI agent workflow in n8n will usually look like this:

Chat Trigger → AI Agent → OpenAI Chat Model
                    ↘ Memory
                    ↘ Tool(s)

This structure allows the user to send a message, the AI Agent to process it, OpenAI to generate reasoning, memory to keep context, and tools to perform actions.

Step 1: Add the Chat Trigger Node

Start by adding a Chat Trigger node. This lets you test your agent using n8n’s chat interface.

  1. Create a new workflow
  2. Add Chat Trigger
  3. Leave the default settings for now

If you want ongoing multi-message conversations, n8n recommends connecting the same memory sub-node to both the Chat Trigger and the AI Agent. This helps maintain a single source of truth for the conversation.

Step 2: Add the AI Agent Node

Next, add the AI Agent node and connect it to the Chat Trigger.

  1. Add the AI Agent node
  2. Connect Chat Trigger → AI Agent
  3. Set your system prompt or instructions inside the agent
Note: Older n8n versions had multiple agent types. In current documentation, this was removed, and AI Agent now works as a Tools Agent.

Step 3: Add the OpenAI Chat Model Node

The AI Agent needs a model to think and respond. Add the OpenAI Chat Model node and connect it to the AI Agent’s model input.

  1. Add OpenAI Chat Model
  2. Create or select your OpenAI credential
  3. Choose the model you want to use
  4. Connect it to the AI Agent model connector

In the OpenAI Chat Model node, you can optionally enable Use Responses API. When enabled, it uses OpenAI’s Responses API instead of Chat Completions. n8n also notes that OpenAI built-in tools are available only when the OpenAI Chat Model is used together with the AI Agent node.

Step 4: Add at Least One Tool

This is the step many beginners miss. The current AI Agent documentation says you must connect at least one tool sub-node to the AI Agent.

Examples of tools you can connect include:

  • HTTP Request tool
  • Calculator tool
  • Code tool
  • Knowledge/search tool
  • Sub-workflow tool
๐Ÿ’ก For a simple test, add an easy tool first so your agent can actually act on something.

Step 5: Add Memory for Conversations

If you want your AI agent to remember previous messages, attach a memory sub-node. This is useful for chatbots, customer support, and assistants that need conversation context.

For chat sessions, n8n recommends connecting the same memory node to both the Chat Trigger and the AI Agent.

Step 6: Add a System Prompt

A good system prompt tells the agent what role it should play and how it should behave.

Example system prompt:

You are a helpful AI assistant for customer support.
Answer clearly and briefly.
Use connected tools when needed.
If information is missing, ask a short follow-up question.

You can customize this for sales, support, HR, booking, lead qualification, or internal knowledge assistants.

Step 7: Test the AI Agent

Once all nodes are connected, execute the workflow and test it through the chat window.

Try sample prompts like:

  • “Summarize this request”
  • “Use the tool to fetch data”
  • “Help me answer a customer inquiry”

If everything is connected properly, the AI Agent will receive the message, use the OpenAI Chat Model for reasoning, and call the connected tool when necessary.

Simple Example Use Case

Here is a beginner-friendly example:

Chat Trigger
   ↓
AI Agent
   ├── OpenAI Chat Model
   ├── Simple Memory
   └── HTTP Request Tool

In this setup, the user asks a question, the agent decides whether it needs external information, and the HTTP Request tool can fetch that data from an API.

Common Problems and Fixes

1. Agent does not work
Check if you connected at least one tool to the AI Agent.

2. OpenAI model not responding
Verify your OpenAI API key and selected credential.

3. Memory is not working
Make sure the memory node is connected correctly, especially if using Chat Trigger sessions.

4. Multi-item expressions behave oddly
n8n notes that sub-nodes can resolve expressions differently from standard nodes.

5. API quota or bad request errors
Check your OpenAI usage, request parameters, and model configuration.

Best Practices

  • Start with one simple tool before building advanced agents
  • Write a clear system prompt
  • Use memory only when you actually need conversation context
  • Test the OpenAI credential separately if needed
  • Keep your first workflow small and easy to debug

Why This Setup Is Good

This approach is good because it is modular. You can start with a very simple AI agent, then later add more tools such as HTTP requests, Google Sheets, Telegram, CRM actions, or database queries.

It is also flexible enough to grow into customer support bots, internal assistants, data lookup bots, and AI-powered automation systems.

Watch My n8n tuts on YouTube

I also share videos about automation, n8n workflows, and AI systems on my YouTube channel.

▶ Visit My YouTube

Want More n8n Tutorials?

You can use this same setup for Telegram bots, website chatbots, CRM assistants, and AI-powered business workflows.

Read More Tutorials

FAQ

Can I build an AI chatbot with n8n and OpenAI?
Yes. The usual starter setup is Chat Trigger, AI Agent, OpenAI Chat Model, memory, and at least one tool.

Do I need a tool connected to AI Agent?
Yes. Current n8n documentation says the AI Agent requires at least one connected tool sub-node.

Can the OpenAI Chat Model use the Responses API?
Yes. The OpenAI Chat Model node has a toggle for using the Responses API.

Does memory persist forever?
n8n notes that memory does not persist between sessions unless your setup is designed to handle session continuity appropriately.

Saturday, 11 April 2026

n8n AI Agent + OpenAI (ChatGPT) integration

How to Build an AI Agent in n8n Using OpenAI (Step-by-Step Tutorial)

AI agents are transforming automation. Instead of fixed workflows, you can build intelligent systems that understand input, process data, and respond dynamically.

In this tutorial, you’ll learn how to create an AI Agent using n8n and OpenAI (ChatGPT API).


๐Ÿš€ What You Will Learn

  • Build an AI agent in n8n
  • Connect OpenAI API
  • Process user input dynamically
  • Create smart automation workflows

๐Ÿค– What is an AI Agent?

An AI agent is a system that:

  • Receives input (question or task)
  • Processes it using AI
  • Performs actions or returns responses

This allows you to automate decision-making, not just tasks.


๐Ÿ”‘ Step 1: Get OpenAI API Key

1. Go to OpenAI dashboard

2. Generate API key

3. Save it securely


⚙️ Step 2: Create Workflow in n8n

Create workflow with:

  • Webhook Node (Input)
  • OpenAI Node (Processing)
  • Optional: Slack / Gmail / WhatsApp (Output)

๐ŸŒ Step 3: Add Webhook Trigger

Example input:

{
  "prompt": "Write a short marketing message for a real estate business"
}

๐Ÿง  Step 4: Configure OpenAI Node

Set up the OpenAI node:

Model: gpt-4 / gpt-4o / gpt-3.5

Prompt:
{{$json["prompt"]}}

You can also use advanced prompts:

You are an expert marketing assistant.

Task:
{{$json["prompt"]}}

Respond clearly and professionally.

๐Ÿงช Step 5: Test the AI Agent

Send request:

POST /webhook-url

{
  "prompt": "Create a Facebook ad for a restaurant"
}

The AI will generate a response instantly.


๐Ÿ”ฅ Real-World Use Cases

  • ๐Ÿค– AI chatbot
  • ๐Ÿ“ Content generation (blogs, ads)
  • ๐Ÿ“Š Data analysis assistant
  • ⚖️ Legal / business assistant
  • ๐Ÿ™️ LGU AI assistant

⚡ Pro Tips

  • Use structured prompts for better output
  • Store responses in Supabase
  • Add memory (RAG system)
  • Combine with voice AI
  • Add multi-channel outputs (Slack, Email, SMS)

Watch My n8n tuts on YouTube

I also share videos about automation, n8n workflows, and AI systems on my YouTube channel.

▶ Visit My YouTube

๐Ÿ“ˆ SEO Keywords

n8n ai agent tutorial, openai automation, chatgpt api workflow, no code ai agent, automation ai system


๐Ÿ’ก Tools Used in This Tutorial

Disclosure: This post may contain affiliate links.


๐ŸŽฏ Conclusion

n8n + OpenAI lets you build powerful AI agents that can automate thinking, not just tasks.

This is the foundation for AI SaaS, chatbots, and automation systems.

๐Ÿš€ Start building your AI agent today!

n8n + Microsoft Outlook Tutorial

n8n + Microsoft Outlook Tutorial How to Use n8n with Microsoft Outlook for Email Automation ...