Route LLM prompts with Claude as primary and OpenAI as fallback

Quick overview A reusable LLM router. Another workflow calls it with a prompt, it asks Claude first, and it falls back to OpenAI when the primary answer is empty. It checks the answer field itself, so an empty HTTP 200 also triggers the fallback.

How it works Receives input from another n8n workflow through the Execute Workflow trigger. Normalizes the incoming payload into prompt, system, mode, and max_tokens with defaults. Sends the prompt to the Anthropic Messages API (Claude) to generate a response. Checks whether Claude returned usable text content rather than relying only on the HTTP status. If no usable content is returned, sends the same prompt to the OpenAI Chat Completions API (gpt-4o-mini) as a fallback. Returns the first usable result to the caller, including text, the responding model, and whether fallback_used is true or false.

Setup Add an Anthropic API credential for the Claude HTTP request. Add an OpenAI API credential for the fallback OpenAI HTTP request. Change primary_model and fallback_model in the Set node to use different models. If using as a sub-workflow, call it from another workflow using an Execute Workflow node and pass the expected input fields.

0
Downloads
0
Views
7.33
Quality Score
beginner
Complexity
Author:Invara(View Original →)
Created:8/25/2026
Updated:8/25/2026

🔒 Please log in to import templates to n8n and favorite templates

Workflow Visualization

Loading...

Preparing workflow renderer

Comments (0)

Login to post comments