TokenMix Research Lab · 2026-04-30

n8n OpenAI-Compatible API 2026: Workflow Setup And Costs
Last Updated: 2026-04-30
Author: TokenMix Research Lab
Data checked: 2026-04-30
n8n can call OpenAI-compatible APIs, but the safest universal method is the HTTP Request node. Use the OpenAI Chat Model node only when your n8n version and credentials support the custom base URL you need.
n8n's AI workflow tutorial says AI agents in n8n use a chat model connection, and the OpenAI Chat Model is one supported option. n8n's OpenAI Chat Model docs say the node dynamically loads models from OpenAI and defaults to Chat Completions unless the Responses API toggle is used. n8n's HTTP Request docs describe the HTTP node as a versatile way to send POST requests, JSON bodies, and headers. The practical conclusion: for TokenMix.ai, OpenRouter, Ollama, SGLang, or any OpenAI-compatible gateway, the HTTP Request path is the least ambiguous.
Table of Contents
- Quick Answer
- Confirmed vs Caveat
- Best Setup Path
- HTTP Request Node Setup
- AI Agent Setup Caveats
- TokenMix.ai Example
- OpenRouter, Ollama, SGLang, And TGI Examples
- n8n vs Dify vs TokenMix.ai
- Cost And Reliability Math
- Troubleshooting
- Production Checklist
- Final Recommendation
- FAQ
- Related Articles
- Sources
Quick Answer
Use an n8n HTTP Request node:
| Field | Value |
|---|---|
| Method | POST |
| URL | https://api.tokenmix.ai/v1/chat/completions |
| Headers | Authorization: Bearer TOKENMIX_API_KEY, Content-Type: application/json |
| Body type | JSON |
| Body | OpenAI Chat Completions payload |
Use TokenMix.ai when the workflow needs one OpenAI-compatible API for GPT, Claude, Gemini, DeepSeek, and open models. Use direct OpenAI credentials only when the workflow is OpenAI-only.
Confirmed vs Caveat
| Claim | Status | Source / note |
|---|---|---|
| n8n has AI Agent workflows | Confirmed | n8n AI workflow docs |
| n8n has an OpenAI Chat Model node | Confirmed | n8n OpenAI Chat Model docs |
| OpenAI Chat Model dynamically loads models from OpenAI | Confirmed | n8n OpenAI Chat Model docs |
| HTTP Request node can send POST JSON with headers | Confirmed | n8n HTTP Request docs |
| Every n8n OpenAI node setup supports arbitrary custom base URLs | Not guaranteed | Version and node behavior vary |
| HTTP Request can call OpenAI-compatible chat endpoints | Confirmed by HTTP mechanics | You control URL, headers, and JSON body |
| n8n replaces an AI API gateway | No | n8n is workflow automation; gateway handles model access |
Best Setup Path
| Goal | Recommended n8n path | Why |
|---|---|---|
| Call TokenMix.ai from a workflow | HTTP Request node | Full control over URL and headers |
| Call OpenRouter from a workflow | HTTP Request node | Exact OpenRouter model IDs and headers |
| Use OpenAI-native AI Agent node | OpenAI Chat Model | Best if using OpenAI directly |
| Use local Ollama model | HTTP Request or Ollama node | Depends on workflow and version |
| Use many providers with one key | TokenMix.ai + HTTP Request | Keeps model access outside n8n node quirks |
| Need LangChain agent memory/tools | AI Agent + supported chat model | Test custom provider behavior carefully |
If the workflow must run tomorrow, use HTTP Request first. Add the AI Agent node later only after compatibility tests.
HTTP Request Node Setup
Create an HTTP Request node with:
| Parameter | Value |
|---|---|
| Method | POST |
| URL | https://api.tokenmix.ai/v1/chat/completions |
| Send headers | Yes |
| Header 1 | Authorization: Bearer {{$env.TOKENMIX_API_KEY}} |
| Header 2 | Content-Type: application/json |
| Send body | Yes |
| Body content type | JSON |
Example JSON body:
{
"model": "your-model-id",
"messages": [
{
"role": "system",
"content": "You are a concise workflow assistant."
},
{
"role": "user",
"content": "Summarize this support ticket: {{$json.ticket_text}}"
}
],
"temperature": 0.2,
"max_tokens": 500
}
Then map the response:
| Response field | Use |
|---|---|
choices[0].message.content |
Main assistant answer |
usage.prompt_tokens |
Input cost tracking |
usage.completion_tokens |
Output cost tracking |
model |
Confirm routed model |
id |
Trace request |
AI Agent Setup Caveats
n8n's AI Agent flow is powerful, but custom OpenAI-compatible APIs are more fragile there because the chat model node expects specific provider behavior.
| Area | Risk |
|---|---|
| Model list loading | Node may expect OpenAI account models |
| Tool calling | Third-party OpenAI-compatible models may return tool calls differently |
| Responses API | Non-OpenAI gateways may not implement OpenAI Responses API |
| Streaming | UI stream handling may differ by gateway |
| Memory | Agent memory is n8n-side; model context still costs tokens |
| Retries | Agent retries can multiply token spend |
Use the AI Agent node when you need n8n's agent framework. Use HTTP Request when you need predictable API integration.
TokenMix.ai Example
TokenMix.ai as model gateway:
| n8n field | Value |
|---|---|
| URL | https://api.tokenmix.ai/v1/chat/completions |
| Auth | Bearer token |
| Model | TokenMix-supported model ID |
| Good use | Workflow automation, support triage, classification, extraction |
| Avoid | Provider-native feature that requires a non-OpenAI endpoint |
Example workflow:
| Step | n8n node | Purpose |
|---|---|---|
| 1 | Webhook / Form Trigger | Receive user input |
| 2 | Set node | Normalize fields |
| 3 | HTTP Request to TokenMix.ai | Generate, classify, summarize, or route |
| 4 | IF node | Branch on model result |
| 5 | Slack / Email / CRM node | Send action |
| 6 | Google Sheets / DB node | Log cost and result |
This architecture keeps n8n focused on automation and TokenMix.ai focused on model access.
OpenRouter, Ollama, SGLang, And TGI Examples
| Provider | HTTP Request URL | Best for |
|---|---|---|
| TokenMix.ai | https://api.tokenmix.ai/v1/chat/completions |
Hosted multi-model workflows |
| OpenRouter | https://openrouter.ai/api/v1/chat/completions |
Broad model catalog |
| Ollama | http://localhost:11434/v1/chat/completions |
Local model workflows |
| SGLang | http://localhost:30000/v1/chat/completions |
Self-hosted high-throughput models |
| TGI | Hugging Face endpoint ending in /v1/chat/completions |
Hugging Face serving |
Use OpenRouter API, Ollama OpenAI-compatible API, SGLang OpenAI-compatible API, and TGI OpenAI-compatible API as provider-specific references.
n8n vs Dify vs TokenMix.ai
| Layer | n8n | Dify | TokenMix.ai |
|---|---|---|---|
| Main job | Workflow automation | AI app/workflow builder | Model API gateway |
| Best at | Connecting SaaS tools and logic | Chatbots, RAG, app flows | Multi-model hosted API access |
| OpenAI-compatible path | HTTP Request or supported model node | OpenAI-compatible plugin | Native API |
| Agent support | AI Agent nodes | App/workflow agents | Backend model routing |
| Model routing | Workflow logic | App/provider config | Gateway-level model access |
| Best pairing | n8n + TokenMix.ai | Dify + TokenMix.ai | Gateway for both |
n8n should not hold every provider-specific decision. It should call a stable gateway and keep workflow logic readable.
Cost And Reliability Math
Cost calculation 1: workflow retry multiplication
| Workflow behavior | Model calls per user event | Cost impact |
|---|---|---|
| Single HTTP Request | 1 | Baseline |
| Retry once on failure | 2 | 2x for failed branch |
| Agent loop with 3 tool calls | 4+ | 4x or more |
| Bad JSON parse plus retry | 2-3 | Hidden waste |
In n8n, one workflow execution can trigger several model calls. Track cost per workflow run, not just per API request.
Cost calculation 2: cheap-first routing
| Routing policy | Relative model cost | Good for |
|---|---|---|
| Premium model for all n8n runs | 8x | High-value reasoning only |
| Cheap model first, premium fallback | 1.7x-2.4x | Support, extraction, triage |
| Local model for safe drafts | Low token cost | Private drafts and simple automation |
| Gateway route by task type | Variable | Mature production workflows |
This is where an LLM API gateway helps. It moves routing policy out of individual n8n workflows.
Cost calculation 3: bad base URL debugging
| Mistake | Cost |
|---|---|
Wrong /v1 base URL |
Failed runs |
| Full endpoint pasted into base URL field | 404 errors |
| Responses API sent to Chat Completions-only gateway | Broken workflow |
| Tool call model mismatch | Agent retries and bad actions |
Most n8n OpenAI-compatible failures are configuration failures, not model failures.
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| 401 unauthorized | Missing or wrong bearer token | Check Authorization header |
| 404 not found | Wrong URL path | Use /v1/chat/completions for HTTP Request |
| Model not found | Wrong provider model ID | Use exact gateway model ID |
| JSON parse error | Invalid n8n expression or raw body | Validate JSON body and expressions |
| Agent node rejects model | Chat model compatibility issue | Use HTTP Request or supported chat model |
| Streaming hangs | Gateway or n8n stream mismatch | Disable streaming first |
| Tool calls fail | Model lacks tool support | Use a tool-capable model |
| Costs spike | Retries or loops | Add max tries, logging, and cost caps |
Production Checklist
| Check | Why |
|---|---|
| Store API keys in n8n credentials or environment variables | Avoid leaking secrets in workflow JSON |
| Use HTTP Request for first integration | Reduces node compatibility ambiguity |
| Log request ID, model, and usage | Needed for cost and debugging |
| Set max tokens | Prevent runaway output |
| Add timeout and max retries | Prevent stuck workflows |
| Validate model output before action nodes | Avoid sending bad emails or CRM updates |
| Separate draft and final approval flows | Human review for high-risk automation |
| Centralize model routing in TokenMix.ai or gateway | Avoid per-workflow model sprawl |
Final Recommendation
For n8n with OpenAI-compatible APIs, start with HTTP Request. It is explicit, debuggable, and provider-neutral.
Use n8n for workflow automation. Use TokenMix.ai for model access. Keep the boundary clean.
FAQ
Can n8n use OpenAI-compatible APIs?
Yes. The most reliable general method is the HTTP Request node calling an OpenAI-compatible endpoint such as /v1/chat/completions.
Can I use TokenMix.ai in n8n?
Yes. Use an HTTP Request node with https://api.tokenmix.ai/v1/chat/completions, a bearer token, and an OpenAI-style JSON body.
Can I use OpenRouter in n8n?
Yes. Use https://openrouter.ai/api/v1/chat/completions in the HTTP Request node with an OpenRouter API key and exact model ID.
Should I use the OpenAI Chat Model node or HTTP Request?
Use OpenAI Chat Model for native OpenAI workflows. Use HTTP Request when calling TokenMix.ai, OpenRouter, local models, or another OpenAI-compatible gateway where base URL behavior matters.
Does n8n AI Agent work with any OpenAI-compatible model?
Not guaranteed. Agent workflows depend on chat model behavior, tool calling, streaming, and sometimes Responses API support. Test before production.
What is the correct TokenMix.ai URL for n8n?
For HTTP Request, use https://api.tokenmix.ai/v1/chat/completions. If a node asks for a base URL instead of a full endpoint, use https://api.tokenmix.ai/v1.
Why does my n8n OpenAI-compatible request return 404?
Usually the URL is wrong, the model ID is wrong, or the endpoint does not exist on that provider. Confirm whether the gateway expects /v1/chat/completions or only a base URL.
Is n8n a replacement for an AI API gateway?
No. n8n automates workflows. An AI API gateway handles model access, routing, fallbacks, provider abstraction, and cost controls.
Related Articles
- OpenAI-Compatible API Guide 2026: SDK, Providers, Pricing
- Dify OpenAI-Compatible API 2026: Workflow Model Routing
- OpenRouter API 2026: Pricing, Models, Limits, Alternatives
- LLM API Gateway Guide: Routing, Fallbacks, Cost Control
- Unified AI API Gateway Comparison 2026
- Ollama OpenAI-Compatible API: Local Setup Guide
- SGLang OpenAI-Compatible API 2026: Server Setup Guide
Sources
- n8n OpenAI Chat Model node: https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.lmchatopenai/
- n8n AI workflow tutorial: https://docs.n8n.io/advanced-ai/intro-tutorial/
- n8n LangChain concepts: https://docs.n8n.io/advanced-ai/langchain/langchain-n8n/
- n8n HTTP Request node: https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.httprequest/
- n8n HTTP Request credentials: https://docs.n8n.io/integrations/builtin/credentials/httprequest/
- n8n GitHub issue on custom OpenAI base URL: https://github.com/n8n-io/n8n/issues/14431
- LangChain ChatOpenAI reference: https://reference.langchain.com/python/langchain-openai/chat_models/base