n8n-nodes-fallback-chat-model
v0.1.3
Published
n8n sub-node that chains multiple chat models (OpenAI, Anthropic, Mistral, Ollama/llama.cpp, ...) and automatically switches to the next model when one fails.
Readme
n8n-nodes-fallback-chat-model
Community node "Fallback Chat Model" for n8n. It attaches to the AI Agent node ("Chat Model" input) just like the built-in OpenAI/Anthropic/Mistral chat model nodes.
Below it, you can connect 2 to 10 arbitrary chat model nodes
(e.g. local llama.cpp/Ollama, then OpenAI, then Anthropic, ...).
When a model fails (timeout, rate limit, connection error, HTTP 5xx, ...),
the next model in the connected order is tried automatically.
Tool/function calling is preserved (important for the AI Agent), because
internally a real BaseChatModel class is used instead of a simple
.withFallbacks() chain.
How it works
[llama.cpp Chat Model] ─┐
[OpenAI Chat Model] ─┼─► [Fallback Chat Model] ─► [AI Agent]
[Anthropic Chat Model] ─┘- Input 1 = primary model (required)
- Inputs 2–10 = fallback models, in the displayed order
- The node parameter "Number of Models" controls how many inputs are shown
- On failure, a warning is logged (can be disabled) and the next model is tried automatically
- On startup, the actual fallback order is written to the n8n log
(
Fallback order: 1. ..., 2. ...) so you can verify it - If your n8n version delivers the models in reverse order, enable the "Reverse Order" toggle in the node
Known limitations:
- If a model fails mid-stream (after tokens were already emitted), we cannot seamlessly switch to another model in the middle of an answer. The fallback reliably covers failures before or at the start of the response (connection errors, auth errors, rate limits, timeouts), which is the main use case.
- Intentional aborts (stop button in n8n, timeout signals) are propagated immediately and do not trigger the fallback chain.
Installation (self-hosted n8n)
Via the n8n UI: Settings → Community Nodes → Install a community node and enter:
n8n-nodes-fallback-chat-modelNote: unverified community nodes require a self-hosted n8n instance; they are not available on n8n Cloud.
Manual installation (without npm registry)
For a quick local setup without publishing to npm, mount the built package into your n8n Docker container:
# 1. On the server: create a folder for custom nodes (if it doesn't exist)
mkdir -p ~/n8n-custom-nodes
# 2. Copy this package directory there, e.g.
scp -r n8n-nodes-fallback-chat-model user@server:~/n8n-custom-nodes/
# 3. Build once on the server (if you don't copy dist/ along)
cd ~/n8n-custom-nodes/n8n-nodes-fallback-chat-model
npm install --ignore-scripts
npm run buildThen add to your n8n docker-compose service:
services:
n8n:
# ... your existing configuration ...
environment:
- N8N_CUSTOM_EXTENSIONS=/home/node/.n8n/custom-nodes
volumes:
- ~/n8n-custom-nodes/n8n-nodes-fallback-chat-model:/home/node/.n8n/custom-nodes/n8n-nodes-fallback-chat-model:roRestart the container:
docker compose up -d --force-recreate n8nThe node "Fallback Chat Model" should then appear in the node search under AI → Language Models.
Development
npm install --ignore-scripts
npm run build # build once
npm run dev # tsc --watchNote: --ignore-scripts skips the native build of isolated-vm (a
transitive dev dependency of n8n-workflow that is only needed for
n8n's code node sandbox, not for this package). This avoids build
failures on very recent Node.js versions.
Changelog
- 0.1.3 – All descriptions, log messages, and docs translated to English
- 0.1.2 – Fixed model ordering (n8n returns connections in reverse order / as bulk arrays depending on version), added deduplication, "Reverse Order" toggle, and startup logging of the active order
- 0.1.1 – Fixed lost failure logging after
bindTools(), added abort detection (stop button/timeouts no longer trigger the fallback chain), added streaming support with pre-first-chunk fallback - 0.1.0 – Initial release
