n8n · Workflow automation
n8n + Leanroute
Two ways to route n8n through Leanroute. On self-hosted n8n, install the Leanroute community node: it adds a Leanroute Chat Model you can plug straight into an AI Agent. On n8n Cloud, or if you'd rather not install anything, use the built-in OpenAI node with a custom base URL.

Option 1: the Leanroute community node (recommended)
- Create a Leanroute API key at /dashboard/keys.
- In n8n, go to Settings → Community Nodes → Install, enter
n8n-nodes-leanrouteand install. You need to be the instance owner. - In a workflow, add an AI Agent and choose Leanroute Chat Model as its chat model. Create a Leanroute credential with your API key.
- Pick a model, for example
anthropic/claude-sonnet-5for planning-heavy agents ordeepseek/deepseek-v4-1-flashfor cheap, fast ones. On a BYOK plan, pick one from a provider you've added a key for. - Open the chat panel and send a message. The request appears in your Leanroute logs with its cost.
The package also includes a plain Leanroute node for single calls outside an agent. Source and issues: github.com/leanroute/n8n-nodes-leanroute.
Option 2: the built-in OpenAI node
1. Get a gateway key
From /dashboard/keys create a key labeled "n8n". If your n8n instance runs multiple distinct workflows with different cost expectations, consider one key per workflow with its own daily spend cap — an "every minute" trigger on the wrong workflow can chew through a balance fast.
2. Add the Leanroute credential
In n8n, open Credentials (left sidebar → Settings → Credentials in n8n Cloud, or the top-right key icon in self-hosted). Click Create new → search for and pick OpenAI.
- Credential name: "Leanroute" (or whatever helps you spot it in the credential picker later).
- API Key: your
gw_live_*from step 1. - Expand Custom OpenAI URL (or Base URL depending on n8n version) and set:
https://api.leanroute.dev/v1. - Organization ID: leave blank. We don't use OpenAI's org-id concept.
- Click Save. n8n runs a test call against the credential; a green checkmark means routing + auth + the gateway are healthy.
3. Use it from a Chat Model node
In any workflow, drop an OpenAI Chat Model node (or attach one to an AI Agent).
- Credential: pick the "Leanroute" credential you just created.
- Model: type the canonical
provider/modelstring directly. For exampleanthropic/claude-sonnet-5,deepseek/deepseek-v4-1-flash,google/gemini-3.1-flash-lite. If the picker only shows OpenAI defaults, switch the model field to Expression mode (the small={{ }}toggle) and type the string. Full catalog at /docs/models. - Streaming + tools: flip them on in the node options as needed. Our streaming-tool translation means the AI Agent node's tool calls work regardless of which underlying model you picked.
Alternative: AI Agent node
For multi-step agentic workflows, drop an AI Agent node and attach a Chat Model sub-node configured exactly as above. The AI Agent node handles the planning loop; Leanroute handles the LLM calls underneath. Sonnet (anthropic/claude-sonnet-5) tends to plan most reliably; DeepSeek V4.1 Flash (deepseek/deepseek-v4-1-flash) is the cost-optimized pick when the workflow doesn't need deep reasoning.
Alternative: HTTP Request node
For embeddings, the discovery endpoint, or any custom header (e.g. x-gateway-routing: explicit), the OpenAI node doesn't cover the surface. Drop an HTTP Request node:
- Method: POST
- URL:
https://api.leanroute.dev/v1/chat/completions - Authentication: Header Auth →
authorization:Bearer gw_live_YOUR_KEY - Send Body: JSON. Body:
{ "model": "anthropic/claude-sonnet-5", "messages": [ { "role": "user", "content": "Summarize this email in one sentence." } ] }
See /docs/api for every endpoint's request body. The model dropdown on that page generates a pre-configured Postman collection you can import wholesale into n8n via the HTTP Request node's Import-from-curl feature.
Cost controls
n8n workflows on a schedule trigger can spike cost fast, especially with AI Agent loops. Configure a daily spend cap on the workflow's API key in /dashboard/keys (e.g. $1/day for an experimental flow, $10/day for production). When the cap is hit the gateway returns 402; n8n shows the error in the execution log and you adjust the cap or top up at /dashboard/billing.
Troubleshooting
- Credential test fails: the base URL probably lost the
/v1suffix. n8n doesn't add it for you on the OpenAI credential. - 400 unknown_model: the model picker auto-completed an OpenAI default. Switch the model field to Expression mode and type the canonical
provider/modelstring. - AI Agent tool calls hang: the model likely doesn't support tools well. Switch to
anthropic/claude-sonnet-5— it's the most reliable agentic choice. - 402 insufficient_credit: top up at /dashboard/billing. n8n surfaces the 402 message in the workflow execution log so you'll catch it quickly.