Route LLM tasks to the cheapest capable Claude models with Anthropic
Quick Overview This workflow receives an LLM task via webhook (or manual run), uses Anthropic Claude to classify its needs, routes the request to the cheapest capable Claude model, and optionally escalates to higher tiers based on a quality score, returning the final answer with cost and routing details.
How it works Receives a POST request on the /webhook/llm-router endpoint (or runs manually) and normalizes inputs like task, context, budget, and minimum quality settings. Rejects requests without a non-empty task and returns a 400 validation error to the caller. Uses Anthropic Claude (Haiku) to classify the task’s complexity, risk, and requirements (for example code, reasoning, web search, long context), falling back to a built-in heuristic if classification fails. Selects the cheapest model from a configurable Anthropic Claude catalog that meets the required tier, context window, web search capability, and optional max-cost constraints, and builds an escalation chain. Executes the task with the current selected Claude model and records tokens, estimated cost, and any execution errors. If judging is enabled, uses Anthropic Claude (Haiku) to score the response quality and escalates to the next model in the chain with reviewer feedback when the score is below the threshold. Returns a JSON response to the webhook caller containing the final answer, routing trace, and cost breakdown (including savings vs a premium baseline model), and optionally posts call events to an external execution-ledger webhook.
Setup Create an HTTP Header Auth credential for Anthropic using header x-api-key, and select it for the Classify Task, Execute Model, and Judge Quality HTTP request steps. Review and update the router configuration values (model catalog IDs/tiers/pricing, premium baseline model, quality threshold, max attempts, and Anthropic API URL) to match your current Anthropic plan and preferred routing behavior. Send tasks to the webhook by copying the production URL for /webhook/llm-router into your client and POSTing JSON with at least a task field (optionally context, maxCostUsd, minTier, forceModel, minQualityScore, and maxAttempts). (Optional) Deploy an execution-ledger endpoint and set ledgerUrl so the workflow can POST routing decisions and token/cost events to your ledger webhook.
Related Templates
AI Weather Forecasts with MCP Integration
Real-time Weather Forecasts with MCP Tools This n8n workflow demonstrates how to integrate real-time weather intelligen...
Google Sheets UI for n8n Workflow
Google Sheets UI for Workflow Control This n8n template provides a practical and efficient way to manage your n8n workf...
Demo Workflow - How to use workflowStaticData()
This workflow demonstrates how to use the workflowStaticData() function to set any type of variable that will persist wi...
🔒 Please log in to import templates to n8n and favorite templates
Workflow Visualization
Loading...
Preparing workflow renderer
Comments (0)
Login to post comments