# Route AI tasks between Anthropic Claude models with Postgres: n8n workflow

> Started by another system calling it, and works across Postgres. It hands the judgement calls to Claude.

Source: https://millionrounds.com/workflow/route-ai-tasks-between-anthropic-claude-models-with-postgres (Millionrounds; every figure on the page links to its filing or article)

[Automation library](https://millionrounds.com/workflows) · [Content](https://millionrounds.com/workflows?category=Content#library)

# Route AI tasks between Anthropic Claude models with Postgres

Started by another system calling it, and works across Postgres. It hands the judgement calls to Claude. 20 steps, 1 branch: a working afternoon to understand properly.

Medium Calls a model: Claude

[Download free](https://millionrounds.com/login?next=%2Fapp%2Fworkflow%2Froute-ai-tasks-between-anthropic-claude-models-with-postgres)

**20 steps** Medium: a working afternoon

**1** Branch: places the flow splits

**0** Loops or waits

**1** Service it connects to

## The flow

Starts it 3 Model 7 Logic 6 Service 4

The steps in the order they run, from what starts it.

- 1 **Task Input Webhook** Webhook *Starts it*
- 2 **Weekly Self-Tuning Schedule** Schedule trigger *Starts it*
- 3 **Anthropic Chat Model - Classifier** Lm Chat Anthropic *Model*
- 4 **Classification Output Parser** Output Parser Structured *Model*
- 5 **Anthropic Chat Model - Small** Lm Chat Anthropic *Model*
- 6 **Anthropic Chat Model - Large** Lm Chat Anthropic *Model*
- 7 **Workflow Configuration** Set *Logic*
- 8 **Fetch Historical Data** Postgres *Service*
- 9 **Task Classifier Agent** Agent *Model*
- 10 **Small Model Execution** Agent *Model*
- 11 **Large Model Execution** Agent *Model*
- 12 **Aggregate Success Metrics** Aggregate *Logic*
- 13 **Load Policy Rules** Postgres *Service*
- 14 **Prepare Telemetry Data** Set *Logic*
- 15 **Calculate Routing Adjustments** Code *Logic*
- 16 **Policy Engine Decision** Code *Logic*
- 17 **Store Telemetry** Postgres *Service*
- 18 **Update Policy Rules** Postgres *Service*
- 19 **Route by Model Selection** Switch *Logic*
- 20 **Return Response** Respond To Webhook *Starts it*

## How it's built

- **Starts on:** Another system calling it
- **Steps:** 20, with 1 branch
- **Size:** Medium: a working afternoon
- **Connects to:** Postgres
- **Model:** Claude

## Questions

What does it need to run?

An n8n account, plus your own Postgres account, and a key for Claude. You connect your own accounts after importing it; none are included.

What starts it?

It starts on another system calling it.

Does it use AI?

Yes. It calls Claude. Model calls are billed by the provider, not by n8n.

How long does it take to set up?

Plan an afternoon. 20 steps is enough that you should read each one before running it.

How do I import it?

Copy the workflow, open a new workflow in n8n and paste. The steps appear on the canvas, ready for your own accounts.

**Before you run it**

Nothing here has been tested by us. It is somebody's working automation, read and described from its own steps. Treat the connections it wants as a list of accounts it will touch, and read the 20 steps before you point it at anything that matters.

## Run it in n8n

- **Create your n8n account** Free to start. n8n is where the workflow runs. [Create an n8n account ↗](https://millionrounds.com/n8n)
- **Download the workflow** Free with a Millionrounds account. [Download free](https://millionrounds.com/login?next=%2Fapp%2Fworkflow%2Froute-ai-tasks-between-anthropic-claude-models-with-postgres)
- **Paste it into n8n** Open a new workflow in n8n and paste. Then connect your own accounts.

Stored with the author's traces removed: canvas notes, instance identifiers, saved credential names and any live document they had left behind.

## Connects to

Each opens the other workflows that use it.

[Postgres](https://millionrounds.com/workflows?service=Postgres#library)

## Workflows like it

Also content, with the same services where possible, closest in size first.

- [**Query Google Sheets/CSV data with PostgreSQL** 20 steps · calls a model · Google Sheets, Postgres](https://millionrounds.com/workflow/query-google-sheets-csv-data-with-postgresql)
- [**Review Terraform pull requests with GitHub and OpenAI** 20 steps · calls a model · GitHub, Postgres](https://millionrounds.com/workflow/review-terraform-pull-requests-with-github-and-openai)
- [**Conversational PostgreSQL agent with Claude** 19 steps · calls a model · Postgres](https://millionrounds.com/workflow/conversational-postgresql-agent-with-claude)
- [**Gate pgvector indexing by checking consent in Postgres** 21 steps · calls a model · Postgres, Slack](https://millionrounds.com/workflow/gate-pgvector-indexing-by-checking-consent-in-postgres)
- [**Publish LinkedIn posts from RSS with Ollama and PostgreSQL** 19 steps · calls a model · LinkedIn, Postgres](https://millionrounds.com/workflow/publish-linkedin-posts-from-rss-with-ollama-and-postgresql)
- [**Query PostgreSQL from Slack with Google Sheets and Gemini** 21 steps · calls a model · Google Sheets, Postgres](https://millionrounds.com/workflow/query-postgresql-from-slack-with-google-sheets-and-gemini)
