AI ChatModelsPriceDocsGuides

Add AI to n8n workflows with an OpenAI-compatible API

In n8n, create an OpenAI credential, paste your sk- key and set Base URL to https://api.macloudai.com/v1. Then use that credential in the OpenAI Chat Model or OpenAI nodes and type a model name from the models page. Claude, GPT, Gemini and DeepSeek all work through the same credential, billed per token.

Updated 2026-11-01 · MaCloud AI

Why use an OpenAI-compatible API in n8n?

n8n has built-in OpenAI nodes and AI agent nodes that speak the OpenAI format. By changing the Base URL on the credential, those same nodes can call any model on the gateway. You keep one credential for every workflow, switch models by typing a different name, and see each call's token count and cost in one usage log. This works on n8n Cloud and self-hosted n8n.

Set up the credential

  1. Create an API key at API Keys and name it "n8n".
  2. In n8n, open Credentials (or Overview, then Create, then Credential) and choose OpenAI.
  3. Paste your sk- key into API Key.
  4. Set Base URL to https://api.macloudai.com/v1. Leave Organization ID empty.
  5. Save. n8n tests the credential; if the test fails, check the key and the /v1 at the end of the URL.
  6. In any OpenAI or OpenAI Chat Model node, select this credential and enter a model name from the models page.

If the model dropdown in a node is empty or shows only some models, switch the model field to By ID (or use an expression) and type the exact name, for example hk-5-5. The Base URL must end in /v1.

Example workflow: summarize and classify incoming messages

A simple, useful pattern: a form or webhook receives a customer message, the AI writes a one-line summary and a category, and the result goes to a sheet or chat channel.

  1. Webhook node (POST), which receives JSON like {"message": "..."}.
  2. Basic LLM Chain node with an OpenAI Chat Model sub-node using your credential and model deepseek-v4.1-flash or another cheap model.
  3. Prompt: "Summarize this customer message in one line and give one category: billing, bug, feature, other. Reply as JSON with keys summary and category."
  4. Turn on the output parser option, or add a Code or Edit Fields node to parse the JSON.
  5. Send the result to Google Sheets, Slack, email or wherever your team works.

For tool-using workflows, replace the Basic LLM Chain with an AI Agent node and attach the same OpenAI Chat Model. Choose a model that supports tool calling well; Claude and GPT models are common choices for agents.

Alternative: the HTTP Request node

If you want full control over the request, or your n8n version does not show a Base URL field, call the API directly with an HTTP Request node. Set Method to POST, URL to https://api.macloudai.com/v1/chat/completions, add the header Authorization with value Bearer sk-... (better: store it in a Header Auth credential), and send this JSON body:

{
  "model": "tt-6-luna",
  "max_tokens": 300,
  "messages": [
    {"role": "system", "content": "Reply as JSON with keys summary and category."},
    {"role": "user", "content": "{{ $json.body.message }}"}
  ]
}

The answer is in choices[0].message.content of the response, and the token counts are in usage. You can reference them in later nodes with an expression such as {{ $json.choices[0].message.content }}.

When you insert user text into a JSON body with an expression, quotes or line breaks in the text can break the JSON. Use the HTTP Request node's "Using Fields Below" option for the body, or build the body in a Code node with JSON.stringify, to avoid this.

Test the webhook

Activate the workflow (or click Listen for test event) and send a test message:

curl -X POST https://YOUR-N8N-HOST/webhook/YOUR-PATH \
  -H "Content-Type: application/json" \
  -d '{"message": "I was charged twice this month, please check my invoice."}'

Then open Usage in the console to see the call, its input and output tokens, and the cost.

Choosing a model for automations

  • High-volume classification, tagging and extraction: start with a cheap model such as deepseek-v4.1-flash or a small Gemini or GPT model.
  • Agents that call tools and make decisions: hk-5-5 or tt-6-luna.
  • Long documents, PDFs turned into text, transcripts: consider gem-3.8-flash.

Workflows run without anyone watching, so set max_tokens (Maximum Number of Tokens in the node options) to keep each call bounded, and add an error branch that retries 429 and 5xx errors after a short wait. More on picking models: which model for which job. Prices per 1M tokens:

Real prices now

Estimated from the prices on the models page: 2,000 input tokens and 500 output tokens per chat. The console shows the actual charge.

ModelsPer chat1,000 chats
GEM 3.8 FlashRp 4Rp 4.434
TT-6 LunaRp 11Rp 10.642
TT-6.1 TerraRp 7Rp 7.263
HK-5.5Rp 3Rp 3.487
GEM 4 ArgonRp 85Rp 84.649
TT-6.1 SolRp 15Rp 14.526

Common errors in n8n

ErrorCauseFix
401Wrong or deleted keyPaste a fresh key into the credential
403Balance too lowTop up, then rerun the execution
404Base URL missing /v1, or model name typoUse https://api.macloudai.com/v1; type the model name by ID
429Too many executions at onceAdd Wait or Retry On Fail; lower the batch size
5xxTemporary upstream errorEnable Retry On Fail in node settings

FAQ

Q1What Base URL do I use in the n8n OpenAI credential?
Use https://api.macloudai.com/v1, with /v1 at the end.
Q2Can I use Claude in n8n with the OpenAI node?
Yes. Use the OpenAI credential with the custom Base URL and type the Claude model name from the models page.
Q3The model list in n8n is empty. What should I do?
Switch the model field to By ID or use an expression and type the exact model name.
Q4Does this work on self-hosted n8n?
Yes. The credential setup is the same on n8n Cloud and self-hosted n8n, as long as the server can reach https://api.macloudai.com.
Q5How do I control costs in automated workflows?
Use a cheaper model for bulk steps, set the maximum tokens per call, and check the Usage page in the console after test runs.

More guides