n8n-nodes-openrouter-chat-model
v0.1.4
Published
Custom n8n OpenRouter Chat Model sub-node with JSON options support (reasoning, max_tokens, etc.) for use with AI Agents and Chains.
Downloads
216
Maintainers
Readme
OpenRouter Chat Model — custom JSON options
This bundle gives you the PR #21780
feature ("set OpenRouter chat model options as JSON", incl. reasoning /
reasoning.effort) applied on top of the current official node
([email protected]), in two forms.
What the PR actually does
It adds a Define Options dropdown to the OpenRouter Chat Model node:
- Using Fields Below — the original typed fields (temperature, max tokens, …).
- Using JSON — a free-form JSON box whose keys are sent straight to the
OpenRouter chat-completions body (so you can set
reasoning,reasoning.effort,provider, etc.).
Because the node runs LangChain's ChatOpenAI under the hood, a few options
(max_tokens, reasoning, reasoning.effort, max_retries, timeout) are
mapped to LangChain constructor fields explicitly — otherwise LangChain
overwrites them with undefined. That mapping is preserved here.
PR vs current master — was it "too far apart"?
No. Diffing the PR file against [email protected], the only real divergences are:
- The release added a
createOpenRouterFetchwrapper (fixes empty tool-call args from Anthropic-via-OpenRouter). Additive — kept here. - Internal helper imports were moved into
@n8n/ai-utilities. The PR still uses the old@utils/*/../N8nLlmTracingpaths. getProxyAgentgained a timeout-options argument.- The release added a
builderHintto the model field.
None of these touch the PR's logic, so it re-applies cleanly. The version in
patch/ even keeps the proxy timeout and the tool-args fetch fix, which the
original PR had dropped.
Option A — patch/LmChatOpenRouter.node.ts (recommended, most robust)
The official node, on top of [email protected], with the PR feature merged in. It
still imports n8n's internal modules, so it is meant to be dropped into a fork
/ custom build of n8n, not installed as a community package.
packages/@n8n/nodes-langchain/nodes/llms/LmChatOpenRouter/LmChatOpenRouter.node.tsThen pnpm install && pnpm build (or rebuild just @n8n/n8n-nodes-langchain)
and run your custom image. This route shares LangChain instances with the Agent
node, so there are no compatibility surprises.
Built against: @langchain/[email protected], @langchain/[email protected] (n8n 2.22.5
catalog). If you target a different n8n version, check that release's catalog.
Option B — n8n-nodes-openrouter-custom/ (standalone community node)
A self-contained community package — install it via Settings → Community Nodes with no custom build. It adds a node called "OpenRouter Chat Model (Custom)" and an "OpenRouter Custom API" credential (same fields as the built-in one: API key + base URL).
To keep it installable, the n8n-internal helpers were removed/replaced:
| Official dependency | In the community node |
|---|---|
| N8nLlmTracing callback | dropped — no per-call token-usage display in the UI; the model works fully |
| makeN8nLlmFailedAttemptHandler | dropped — LangChain's built-in maxRetries still applies |
| getProxyAgent | dropped — re-add only if you run behind an HTTP(S) proxy |
| getConnectionHintNoticeField | inlined as a static notice |
| internal credential type | local OpenRouterCredential interface |
| createOpenRouterFetch (tool-args fix) | kept (self-contained) |
Build & install
cd n8n-nodes-openrouter-custom
npm install
npm run build # tsc + copies the icon into dist/
npm publish # or: npm pack, then install the tarballIn n8n: Settings → Community Nodes → Install → n8n-nodes-openrouter-custom.
⚠️ The one caveat that actually matters: LangChain instance matching
An ai_languageModel sub-node returns a LangChain ChatOpenAI. n8n's AI
Agent must recognise it as a LangChain model. If the community package bundles
its own copy of @langchain/*, you can hit instanceof/duplicate-module
issues and the Agent may reject the model.
That's why @langchain/core and @langchain/openai are declared as
peerDependencies (not bundled) — the goal is to use n8n's own copies. Match
them to your n8n version (2.22.5 → core 1.1.41, openai 1.4.4). If your n8n
install does not expose those modules to community nodes, or the Agent refuses
the model, fall back to Option A (the patched node in a custom build), which
is guaranteed to share instances.
This LangChain-isolation point — not the PR/master drift — is the real reason a community node "might not just work", and is the honest answer to "what else can we do": run the patched official node in a custom n8n image.
Using JSON mode
Set Define Options → Using JSON and supply e.g.:
{
"max_retries": 2,
"timeout": 60000,
"temperature": 1.0,
"reasoning": { "effort": "high" },
"response_format": { "type": "text" }
}Keys map to the OpenRouter chat-completion request.
