n8n-nodes-cloudflare-workers-ai
v0.1.2
Published
Use Cloudflare Workers AI (@cf/…) models through AI Gateway as a chat model for n8n AI Agents and chains
Maintainers
Readme
n8n-nodes-cloudflare-workers-ai
A Cloudflare Workers AI chat-model sub-node for n8n. Routes @cf/… models through AI Gateway (so logging, caching, rate/spend limits, and fallbacks apply) and exposes them to the AI Agent node and LLM chains.
Solves the friction of pointing the built-in OpenAI node at Cloudflare:
- Credential test hits
/chat/completions(which exists), not/models(which Cloudflare doesn't implement) — so a green tick means something. - Live model dropdown fetched from Cloudflare's catalogue, filtered to function-calling models by default.
- CF-native credential fields (Account ID, Gateway ID, tokens) instead of a hand-built base URL and raw custom headers.
Requirements
- Self-hosted n8n (community node with an npm dependency).
- A Cloudflare AI Gateway (any name; e.g.
n8n). - A Cloudflare API token with Workers AI – Read (add Workers AI – Edit if you want writes elsewhere).
Install (self-hosted)
Three steps:
- In n8n, open Settings → Community Nodes → Install.
- Enter
n8n-nodes-cloudflare-workers-aiand confirm. - Restart n8n if it doesn't hot-load.
Manual/dev install instead:
git clone <this-package> n8n-nodes-cloudflare-workers-ai
cd n8n-nodes-cloudflare-workers-ai
npm install
npm run build
# link into your n8n custom folder:
mkdir -p ~/.n8n/custom
ln -s "$(pwd)" ~/.n8n/custom/n8n-nodes-cloudflare-workers-aiThen restart n8n.
Credential setup
| Field | Value |
|-------|-------|
| Account ID | Cloudflare account ID |
| Gateway ID | Your gateway name, e.g. n8n |
| API Token | CF token with Workers AI – Read |
| Gateway Authorization Token | Blank unless Authenticated Gateway is on |
The runtime base URL is assembled as:
https://gateway.ai.cloudflare.com/v1/{accountId}/{gatewayId}/workers-ai/v1
The credential test hits a different, deprecation-proof endpoint — the account model catalogue (/ai/models/search), the same call that fills the model dropdown. A green tick means your token, account ID, and Workers AI – Read permission are valid. (It does not check the Gateway ID; a typo there shows up on the first run, not at credential-test time.)
Wire it up
- Add an AI Agent node.
- On its Chat Model input, add Cloudflare Workers AI Chat Model.
- Pick a model (🛠 = function-calling capable) and run.
The one thing to verify on your n8n version
The AI Agent historically kept an allowlist of which chat-model nodes could attach to its model input. If this node's output won't connect to the Agent's Chat Model port, that allowlist is still present in your build. Workarounds, cheapest first:
- Use this node with Basic LLM Chain (unaffected) and drive tools there.
- Keep the built-in OpenAI Chat Model node (base URL → the gateway path above) for Agent work, and use this node everywhere else.
If it does connect, you're done — nothing else needed.
Local development & testing
Fast loop — test the credential/connection without n8n. This hits the exact endpoint the credential test uses and prints Cloudflare's raw error body (n8n hides it behind a generic "request is invalid" message):
# PowerShell
$env:CF_ACCOUNT_ID="..."; $env:CF_GATEWAY_ID="..."; $env:CF_API_TOKEN="..."
# optional: $env:CF_AIG_TOKEN="..." (only if Authenticated Gateway is on)
npm run build # not required for this script, but keep dist in sync
npm run test:connection# bash
CF_ACCOUNT_ID=... CF_GATEWAY_ID=... CF_API_TOKEN=... npm run test:connectionHTTP 200 = credential is good. Any other status prints the Cloudflare error code (e.g. 7077 = authenticated-gateway token missing/wrong, auth errors = token permissions, model errors = probe model retired).
Full loop — run the node in a local n8n. Build, link into n8n's custom folder, and start n8n:
npm run build
mkdir -p ~/.n8n/custom # Windows: %USERPROFILE%\.n8n\custom
# from the repo root:
npm link
cd ~/.n8n/custom && npm link n8n-nodes-cloudflare-workers-ai
npx n8n start # then open http://localhost:5678Use npm run dev (tsc watch) in the repo while iterating; restart n8n to pick up changes. Docker alternative: mount ./dist into /home/node/.n8n/custom/n8n-nodes-cloudflare-workers-ai in the n8nio/n8n image.
Notes
- Workers AI has no
/modelsinference endpoint, so the dropdown uses the account-level catalogue API (/ai/models/search) — that's why the credential needs the Account ID and token even though inference goes through the gateway host. cf-aig-authorizationis only sent when you fill the Gateway Authorization Token.
