Connecting OpenRouter as n8n's Model Backend
Point n8n chat and agent nodes at OpenRouter so you can swap models, keep provider fallbacks, and align canvas agents with the same gateway your code uses.
Search across all documentation pages
Point n8n chat and agent nodes at OpenRouter so you can swap models, keep provider fallbacks, and align canvas agents with the same gateway your code uses.
Configure OpenRouter credentials (native OpenRouter chat model node, or OpenAI-compatible base URL https://openrouter.ai/api/v1), pick an explicit model slug, smoke-test a one-shot completion, then attach that model to AI Agent or chain nodes with spend and logging discipline.
https://openrouter.ai/api/v1 when the node allows base URL (verify UI at build).openai/gpt-4o-mini or anthropic/claude-sonnet-4.5 (verify current slugs at build).HTTP-Referer for your app URL and X-Title / X-OpenRouter-Title for dashboard labeling.Manual Trigger
→ OpenRouter Chat Model
credential: OpenRouter (n8n key)
model: openai/gpt-4o-mini
prompt: "Reply with pong"
→ Set / NoOp (inspect JSON)Webhook / Chat Trigger
→ AI Agent
Chat Model: OpenRouter → anthropic/claude-sonnet-4.5 (verify slug)
tools: [one HTTP tool]
→ Slackimport os
from openai import OpenAI
client = OpenAI(
base_url="https://openrouter.ai/api/v1",
api_key=os.environ["OPENROUTER_API_KEY"],
default_headers={
"HTTP-Referer": "https://your-company.example", # optional
"X-OpenRouter-Title": "n8n-parity-check",
},
)
resp = client.chat.completions.create(
model="openai/gpt-4o-mini", # same slug as the n8n node
messages=[{"role": "user", "content": "Reply with pong"}],
)
print(resp.choices[0].message.content)
print(resp.usage)If Python works and n8n fails, the bug is credentials, base URL, or node wiring - not OpenRouter account health.
When a node only knows "OpenAI":
| Field | Value |
|---|---|
| API Key | sk-or-v1-... (OpenRouter) |
| Base URL | https://openrouter.ai/api/v1 |
| Model | OpenRouter slug (provider/model) |
Do not paste an OpenRouter key into a credential that still targets https://api.openai.com/v1.
| Benefit | Detail |
|---|---|
| Model mobility | Change slugs without new vendor credentials per provider |
| Unified billing view | Activity/API usage next to your coded agents |
| Provider fallback | Multi-host models keep completing when one host fails |
| Eval alignment | Same gateway in CI scripts and canvas pilots |
| Key | Use |
|---|---|
n8n-dev | Builders' sandboxes, low credit cap |
n8n-prod | Production workflows only, alerting on burn |
ci-eval | Offline golden tests in Python/CI |
Rotate keys if a workflow export or screenshot may have leaked them.
:free models before relying on them in prod; capacity and tool support vary.n8n shows node input/output. OpenRouter shows tokens, cost, provider, and model served.
Log a correlation id (webhook request id) into the prompt metadata or a Set field so you can join a failed Slack post to the exact generation later.
If prompts contain sensitive data, apply OpenRouter privacy / data-collection preferences on the account or per request where the API allows it.
Self-hosted n8n does not remove the fact that prompt content still goes to the model provider OpenRouter routes to.
vendor/model slugs, not only gpt-4o-mini, unless a node rewrites them (do not assume).usage.cost. You may need OpenRouter Activity or an HTTP poll of usage APIs for cost dashboards.| Backend | Pros | Cons |
|---|---|---|
| OpenRouter | Multi-model, fallbacks, one key shape | Extra platform to govern |
| Direct OpenAI/Anthropic/Google nodes | First-party features | Credential sprawl, weaker multi-vendor swap |
| Self-hosted Ollama node | Data stays local | Ops burden; weaker tool ecosystem |
| HTTP Request to any API | Full control | You build retries, parsing, auth |
| Your agent microservice | Best long-term product path | Higher build cost |
n8n's AI ecosystem has included OpenRouter chat model integrations and OpenAI-compatible paths. Exact node names vary by version - search "OpenRouter" in the node picker and confirm against current n8n docs at build.
models fallback arrays from n8n?Only if the node forwards OpenRouter-specific body fields. Many visual nodes expose model + temperature only. For full routing objects, call OpenRouter via HTTP Request or move that path to code.
Create an OpenRouter key with a credit limit (and reset policy if available), monitor Activity, and keep max iterations low on agent nodes.
Often the model/provider path does not support the tool schema the agent node sends, or the credential path strips needed fields. Bisect with a tool-capable first-party model, then reintroduce OpenRouter.
No. Classify and format on small models; reserve stronger slugs for tool-heavy agents. Record the matrix in the workflow description.
No. OpenRouter only serves models. Gmail, Slack, CRM, and HTTP APIs still need their own n8n credentials.
Keep system prompts, model slugs, and tool URLs in a shared doc. The Python OpenAI client against OpenRouter is a near-copy of what the node does.
Not for most automations. Batch request/response is enough for triage and drafting. Streaming matters more for chat UIs.
OpenRouter account and upstream provider limits both apply. Back off on 429s; reduce parallel workflow executions if you burst.
Not required. Separate keys and credit limits are usually enough for isolation.
Related: Building an AI Agent Node Workflow in n8n
Related: No/Low-Code Orchestration Basics
Related: From No-Code Prototype to Custom Code: A Migration Path
Related: No/Low-Code Orchestration Best Practices
Related: How OpenRouter's Provider Fallback Actually Protects Uptime
Stack versions: Pins from the category manifest (verify at build): OpenRouter (~315+ models, July 2026 pricing/fees); LangGraph 1.0+; CrewAI 1.14+; Microsoft Agent Framework 1.0; Vercel AI SDK 6; Pydantic AI (latest); LlamaIndex (latest); OpenAI Agents SDK (latest + MCP); MCP (Linux Foundation governance); A2A (HTTP+SSE+JSON-RPC 2.0); Solana
@solana/web3.js+@solana/spl-token.
Reviewed by Chris St. John·Last updated Jul 16, 2026