Briefova

Home › Guides

Use any OpenAI-compatible API in n8n, and secure your intake webhook

Last checked 2026-12-05. Steps follow n8n's published documentation; where we could not run something ourselves we say so.

Short answer: any provider that offers an OpenAI-style /chat/completions endpoint works in n8n through the HTTP Request node (or the OpenAI node with a custom Base URL): set the base URL, a Bearer API key stored in a Header Auth credential, and the model name. Protect your own intake webhooks with Header Auth, Basic Auth or JWT, and validate every payload.

Two questions come up together when you add AI to an intake workflow: how do I call a free-tier model, and how do I stop strangers posting junk to my webhook? This guide answers both with the n8n features that exist for the purpose.

Part 1: calling an OpenAI-compatible API

"OpenAI-compatible" means the provider accepts the same request shape as OpenAI's chat completions API. The differences are the base URL, the key and the model names.

ProviderBase URLNotes (checked 4 Dec 2026)
Google Gemini APIhttps://generativelanguage.googleapis.com/v1beta/openaiModel e.g. gemini-3.5-flash-lite. Free tier without a card; commonly reported free limits for Flash-Lite are 15 requests/min and 500/day, but Google says limits are not guaranteed. On the free tier Google may use prompts to improve its products.
Groqhttps://api.groq.com/openai/v1Free plan with per-model request and token limits; check your console.
OpenRouterhttps://openrouter.ai/api/v1Models with a :free suffix have low daily request caps unless you add credit.
Ollama (local)http://localhost:11434/v1Runs on your machine; if n8n is in Docker use host.docker.internal instead of localhost. Any text works as the key.
OpenAI or other paidhttps://api.openai.com/v1Paid usage.

Set up with the HTTP Request node

  1. Create a credential: Header Auth, name Authorization, value Bearer YOUR_API_KEY. (Note the space after Bearer.)
  2. Add an HTTP Request node: method POST, URL {{ $json.llm_base_url }}/chat/completions or a fixed URL, Authentication Generic Credential Type > Header Auth.
  3. Send body as JSON:
{
  "model": "gemini-3.5-flash-lite",
  "temperature": 0.3,
  "messages": [
    { "role": "system", "content": "You write a two-sentence summary. Use only the facts given." },
    { "role": "user", "content": "Client goals: ..." }
  ]
}

The reply text is at choices[0].message.content. Read it in the next node with the expression {{ $json.choices[0].message.content }}.

Or use the OpenAI node

n8n's OpenAI credential has a Base URL field. Set it to a provider's base URL from the table, paste the key, and the OpenAI and chat-model nodes will talk to that provider. Compatibility varies: some providers do not implement every option (such as strict JSON response formats or tool calling), so test the exact features you use.

Make it fail safely

Part 2: securing an intake webhook

A production webhook URL is a public address. Anyone who learns it can post to it. n8n's Webhook node offers several protections:

OptionHow it worksWhen to use
Header AuthCaller must send a header such as X-Api-Key with the value you set in a credentialServer-to-server calls (your form tool, CRM, Zapier or Make)
Basic AuthUsername and password via HTTP basic authSimple tools that support basic auth. Use HTTPS
JWT AuthCaller sends a signed JSON Web Token that n8n verifiesWhen the caller can sign tokens
IP allowlist (Webhook node option)Only listed IP addresses are acceptedWhen the caller has fixed IPs

Header Auth, step by step

  1. In the Webhook node set Authentication to Header Auth and create a credential with name X-Api-Key and a long random value.
  2. Configure your calling tool to send the same header. Test: curl -X POST YOUR_PRODUCTION_URL -H "X-Api-Key: YOUR_VALUE" -H "Content-Type: application/json" -d '{"proposal_id":"P-1"}'. Without the header n8n should answer with an authorisation error.
  3. Rotate the value if it leaks, by editing the credential and your caller.

For forms you share with clients, the Form Trigger supports Basic Auth; but a public lead form usually needs to be open, so protect it with validation and rate awareness instead of a password.

Validate what arrives

Quick checklist

  1. Authentication enabled on the webhook.
  2. Key stored in an n8n credential, not in the workflow body.
  3. Payload validated and truncated.
  4. AI call with retries and a template fallback.
  5. Outputs saved as files or drafts, never sent automatically.

The kits' intake and approval workflows use these patterns: a Config node holding the model name and base URL, a switch that skips AI when it is off, fallback text when the call fails, and no auto-send. See the Proposal & Client Onboarding Kit.

Testing a provider before wiring it in

Before touching n8n, check the key and model with a single command. Replace the URL and model with the ones from the provider table:


curl https://generativelanguage.googleapis.com/v1beta/openai/chat/completions \
  -H "Authorization: Bearer YOUR_API_KEY" -H "Content-Type: application/json" \
  -d '{"model":"gemini-3.5-flash-lite","messages":[{"role":"user","content":"Say OK"}]}'

A JSON reply with choices means the key, URL and model name are right. A 401 or 403 is a key problem, a 404 is usually a wrong base URL or model name, and a 429 is a rate limit. Fixing it here is faster than debugging inside a workflow.

Common mistakes

Choosing a model for this kind of task

Drafting a short paragraph, summarising a form entry or classifying an email is well within the reach of small, fast models; you do not need the largest model for it. Pick a small model first, test it on your own sample, and move up only if it fails on your examples. Cheaper models are also less likely to hit free-tier limits. Whatever you choose, keep the AI's role narrow (wording, not facts) and keep a template fallback.

Sources

Proposal & Client Onboarding Kit

The kit below implements the workflow in this guide with test data, a setup guide and a test report.

See the kit · $24

n8n Starter Pack for Freelancers

Not ready to buy? The free starter pack has two working workflows, a scorecard and a credentials checklist so you can test n8n first.

Get the free pack

Related guides

Build an AI proposal generator in n8n

n8n workflow that collects a brief with a form, keeps prices in a rate card, uses AI only for the goals paragraph, and leaves approval to you. Includes prompt and Code.

N8n email triage: classify Gmail and draft replies

Build an n8n Gmail triage workflow with rules first, optional AI JSON classification, labels and reply drafts only. Safety rules and a no-credentials test included.

N8n client onboarding workflow for freelancers

Build an n8n workflow that turns a proposal approval into a dated kickoff checklist, a welcome email draft and a client folder. Includes webhook payload and Code node.

Frequently asked questions

What does OpenAI-compatible mean?

The provider accepts the same chat completions request shape, so you only change the base URL, API key and model name.

How do I handle a 429 from a free tier?

Enable retries with a delay and batching in the HTTP Request node, set it to continue on error, and fall back to template text.

How do I stop strangers using my webhook?

Set Authentication on the Webhook node (Header Auth, Basic Auth or JWT), validate the payload, and keep the key in an n8n credential.