Skip to main content

🤖 Build resilient AI workflows with automatic GPT and Gemini failover chain

Workflow preview

Workflow preview
100%
🤖 Build resilient AI workflows with automatic GPT and Gemini failover chain preview
Open on n8n.io

Important notice

This workflow is provided as-is. Please review and test before using in production.

1. Workflow Overview

This workflow contains community nodes that are only compatible with the self hosted version of n8n. How it works This workflow demonstrates how to create a resilient AI Agent that automatically fa...

Best for

  • Engineering automation workflows
  • AI Chatbot automation workflows
  • intermediate n8n builders looking for reusable templates

Tools used

@n8n/n8n-nodes-langchain.agent, n8n-nodes-base.set, @n8n/n8n-nodes-langchain.code, @n8n/n8n-nodes-langchain.lmchatopenai, @n8n/n8n-nodes-langchain.lmchatgooglegemini, n8n-nodes-base.stickynote, n8n-nodes-base.manualtrigger

Source and attribution

This workflow is cataloged by N8N Workflows and links back to its original n8n.io source page by Lucas Peyrin.

Original n8n.io source

1.1 Workflow description

Title
🤖 Build resilient AI workflows with automatic GPT and Gemini failover chain
Workflow name
🤖 Build resilient AI workflows with automatic GPT and Gemini failover chain

This workflow contains community nodes that are only compatible with the self-hosted version of n8n.

How it works

This workflow demonstrates how to create a resilient AI Agent that automatically falls back to a different language model if the primary one fails. This is useful for handling API errors, rate limits, or model outages without interrupting your process.

  1. State Initialization: The Agent Variables node initializes a fail_count to 0. This counter tracks how many models have been attempted.
  2. Dynamic Model Selection: The Fallback Models (a LangChain Code node) acts as a router. It receives a list of all connected AI models and, based on the current fail_count, selects which one to use for this attempt (0 for the first model, 1 for the second, etc.).
  3. Agent Execution: The AI Agent node attempts to run your prompt using the model selected by the router.
  4. The Fallback Loop:
    • On Success: The workflow completes successfully.
    • On Error: If the AI Agent node fails, its "On Error" output is triggered. This path loops back to the Agent Variables node, which increments the fail_count by 1. The process then repeats, causing the Fallback Models router to select the next model in the list.
  5. Final Failure: If all connected models are tried and fail, the workflow will stop with an error.

Set up steps

Setup time: ~3-5 minutes

  1. Configure Credentials: Ensure you have the necessary credentials (e.g., for OpenAI, Google AI) configured in your n8n instance.
  2. Define Your Model Chain:
    • Add the AI model nodes you want to use to the canvas (e.g., OpenAI, Google Gemini, Anthropic).
    • Connect them to the Fallback Models node.
    • Important: The order in which you connect the models determines the fallback order. The model nodes first created/connected will be tried first.
  3. Set Your Prompt: Open the AI Agent node and enter the prompt you want to execute.
  4. Test: Run the workflow. To test the fallback logic, you can temporarily disable the First Model node or configure it with invalid credentials to force an error.

1.2 Logical Blocks

This catalog entry is organized from the workflow JSON. The node-level section below shows the executable blocks available for review before importing the template.

2. Block-by-Block Analysis

Block 1 - AI Agent

Type / Role
@n8n/n8n-nodes-langchain.agent - agent
Config choices
Version 2

Block 2 - Agent Variables

Type / Role
n8n-nodes-base.set - set
Config choices
Version 3.4

Block 3 - Fallback Models

Type / Role
@n8n/n8n-nodes-langchain.code - code
Config choices
Version 1

Block 4 - First Model

Type / Role
@n8n/n8n-nodes-langchain.lmChatOpenAi - lmChatOpenAi
Config choices
Version 1.2

Block 5 - Falback Model

Type / Role
@n8n/n8n-nodes-langchain.lmChatGoogleGemini - lmChatGoogleGemini
Config choices
Version 1

Block 6 - Sticky Note

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 7 - Sticky Note1

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 8 - Sticky Note2

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 9 - Manual Trigger

Type / Role
n8n-nodes-base.manualTrigger - manualTrigger
Config choices
Version 1

Block 10 - Sticky Note10

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

3. Summary Table

Workflow 🤖 Build resilient AI workflows with automatic GPT and Gemini failover chain
Complexity intermediate
Nodes 10
Categories Engineering, AI Chatbot
Author Lucas Peyrin
Published 23 Jun 2025

4. Reproducing the Workflow from Scratch

  1. 1. Download the workflow JSON

    Use the JSON export at /data/workflows/5160/5160.json as the source template for this automation.

  2. 2. Import the template into n8n

    Open n8n, import the downloaded JSON, and review each node before activating the workflow.

  3. 3. Configure credentials and variables

    Replace placeholder credentials, API keys, webhook URLs, account IDs, and environment-specific values with your own settings.

  4. 4. Test with sample data

    Run the workflow manually or in a staging workspace, inspect node output, and confirm downstream systems receive the expected data.

  5. 5. Activate and monitor

    Enable the workflow only after testing, then monitor executions, errors, and rate limits during the first production runs.

5. General Notes & Resources

Review imported nodes carefully before activation. This catalog entry is intended to help you inspect the workflow structure, understand required services, and find related templates faster.

Node names, credentials, schedules, webhook paths, and external service limits may need adjustment for your workspace.

Frequently asked questions

What does 🤖 Build resilient AI workflows with automatic GPT and Gemini failover chain do?

This workflow contains community nodes that are only compatible with the self hosted version of n8n. How it works This workflow demonstrates how to create a resilient AI Agent that automatically fa...

What do I need before importing this workflow?

Review the workflow JSON, configure any required credentials in n8n, and test the automation in a safe workspace before using it in production.

Can I customize this workflow?

Yes. Use the block-by-block analysis and the downloadable JSON to inspect each node, then adjust credentials, prompts, schedules, filters, or destinations for your Engineering, AI Chatbot use case.