n8n · Workflow automation

n8n + Leanroute

n8n's OpenAI node accepts a custom base URL out of the box. Point it at Leanroute and every Chat Model + AI Agent node in your workflows routes through us — one credential object covers the whole automation, including agentic chains and tool use.

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/model string directly. For example anthropic/claude-sonnet-4-6, deepseek/deepseek-chat, 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-4-6) tends to plan most reliably; DeepSeek-V3 (deepseek/deepseek-chat) 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-4-6",
      "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 /v1 suffix. 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/model string.
  • AI Agent tool calls hang: the model likely doesn't support tools well. Switch to anthropic/claude-sonnet-4-6 — 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.