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

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

Needs changes

by Lucas Peyrin ✓ · 2,620 views · created 2025-06-23 · Engineering, AI Chatbot

Needs changes. This template uses 1 thing(s) that n8n 3.0 removes: LangChain Code (legacy). 1 breaking item(s) found. Static check, last run 2026-10-19.

What to replace before upgrading

Removed in 3.0Replace with
LangChain Code (legacy)
Fallback Models
No direct replacement

Nodes used (6)

AI AgentLangChain CodeOpenAI Chat ModelGoogle Gemini Chat Model

What it does

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 failcount 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 failcount, 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 failcount 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.

View the original on n8n.io → Check your own copy

Get the weekly “what broke” email

New templates, newly broken ones, and n8n release changes. One short email a week.

Form not loading? Subscribe here.