Connecting Grok (xAI) to n8n: native node, API, and use cases
Published 4 August 2026 · 6 min read
FlowKit's guides for connecting an LLM to n8n already cover OpenAI and Claude, Mistral, DeepSeek, and Groq — the fast-inference host, not to be confused with today's topic. Grok, xAI's model, deserves separate treatment: it's the only one on the list that natively ships web and X search tools billed per call, which changes how you wire it into an n8n agent. This guide covers the native node, the OpenAI-compatible API fallback, picking the right model for the job, and a known bug worth knowing about before relying on Grok in production.
Why Grok changes the equation for an n8n agent
Most LLMs answer from the frozen knowledge of their training run, and an AI Agent node needs a search tool explicitly wired in before it can reach current information. Grok flips that logic: web and X search is a native API tool, billed separately per call (5 $ per 1,000 web or X search calls, 10 $ per 1,000 file attachments), which the model can trigger on its own with no extra n8n configuration.
That design choice tracks a well-documented finding in research: an LLM queried without access to external sources tends to hallucinate on recent or niche facts, while grounding on documents or search results measurably reduces that risk. That's the founding argument of Lewis and co-authors' "Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks" (NeurIPS 2020 — Google Scholar page), the paper that popularized the very principle of RAG our RAG Assistant Pack (€119) follows. Grok applies the same logic, but internally and over the open web rather than your own documents: the two approaches are complementary, not competing, in a workflow that needs to answer both from your knowledge base and from current events.
Creating xAI credentials
- Create an account on console.x.ai.
- Open the API Keys section, generate a key and copy it immediately — it won't be shown in plain text again.
- In n8n, create a credential of type xAI and paste the key in.
As with any AI provider, this credential should live exclusively in n8n's credential manager. Good storage and rotation practices are covered in our guide on securing API credentials.
Method 1: the native xAI Grok Chat Model node
n8n ships a dedicated node, xAI Grok Chat Model (n8n-nodes-langchain.lmChatXAiGrok). Like other chat models, it's a LangChain sub-node that doesn't run on its own: it plugs into the "Model" input of a parent node — AI Agent, LLM Chain, Text Classifier, or Information Extractor. If these building blocks are new to you, our guide to getting started with n8n's AI nodes covers the basics.
- Add the parent node (an AI Agent, for instance), then attach an xAI Grok Chat Model to its model input.
- Select your xAI credential.
- Pick the model from the list, loaded dynamically from the xAI API — n8n queries the live catalog, so recently added or retired models show up automatically.
This is the method to favor for any new workflow: a dedicated credential, cleanly exposed settings (temperature, max tokens, frequency penalty), no URL to hand-wire.
Method 2: the OpenAI-compatible API
xAI also exposes an API compatible with the OpenAI format, with https://api.x.ai/v1 as the base URL. Two practical uses:
- Repurposed OpenAI credential: create an OpenAI credential in n8n with your xAI key and swap the base URL for
https://api.x.ai/v1. A workflow already wired for GPT switches to Grok just by changing the model name, with no rewiring needed — handy for comparing two providers on the same setup. - HTTP Request node, for full control:
POST https://api.x.ai/v1/chat/completions
Authorization: Bearer {{ $credentials.apiKey }}
{
"model": "grok-4.3",
"messages": [
{ "role": "system", "content": "Summarize an industry news item in three factual bullet points." },
{ "role": "user", "content": "{{ $json.query }}" }
],
"temperature": 0.3
}
A third route, to keep an immediate fallback provider: go through OpenRouter, which lists Grok among its available models and makes multi-provider fallback easier if xAI is overloaded.
Choosing the right Grok model
xAI's catalog moves fast — older versions (grok-4, grok-4-fast, grok-4.1, grok-code-fast-1, grok-3) were retired on May 15, 2026, for instance. At the time of writing, three families cover most of an n8n workflow's needs:
| Model | Use case | Context | Price (input / output, per 1M tokens) |
|---|---|---|---|
| Grok 4.5 | Complex reasoning, agents on ambiguous cases | 500K tokens | $2.00 / $6.00 |
| Grok 4.3 | Everyday production work, best price-to-quality ratio | 1M tokens | $1.25 / $2.50 |
| Grok Build | Code generation and review | 256K tokens | $1.00 / $2.00 |
For most automation workflows — classification, summarization, drafting — the Grok 4.3 family is more than enough and costs noticeably less than the flagship model. Reserve Grok 4.5 for steps where deeper reasoning is genuinely needed, and keep an eye on spend using the method described in our guide to tracking AI call costs per workflow — especially since Grok's native tools (web search, X search, code execution) stack on top of the per-token cost.
The known pitfall: AI Agent, streaming, and tool calling
A bug was reported on n8n's GitHub repo (issue #14483): combining the AI Agent node, the xAI Grok Chat Model, and streaming triggered an "Argument not supported: stream_options" error, even though the same call worked fine directly via curl against the xAI API. A fix has since shipped, but the episode illustrates a broader point about tool-using agents: wiring an LLM up to external tools remains, technically, more fragile than plain text generation.
A landmark review on the topic, Patil and co-authors' "Gorilla: Large Language Model Connected with Massive APIs" (Google Scholar page), documents how often models generate malformed API calls or hallucinate parameters that don't exist — a provider-agnostic problem, but one that integration layers (like n8n's AI Agent node) can amplify or expose. In practice: always update your n8n instance to a recent version before relying on Grok in production, and test the full execution (model, memory, tools) beforehand. If the agent hangs or loops on a tool, our guide to common AI Agent node errors covers the most frequent diagnoses, across all providers.
Where Grok genuinely adds value in n8n
- Real-time monitoring and research: native web and X search avoids building your own scraping pipeline for a competitive monitoring or industry-news agent.
- A web-grounded fallback tier in a RAG chatbot: when a question falls outside your knowledge base's scope, a Grok agent with web search can take over instead of returning a flat "I don't know" — a natural complement to our RAG Assistant Pack (€119).
- Code review or generation in a development workflow: Grok Build, with its dedicated pricing, fits well as a node that reviews a diff or generates a test before a deployment.
Limitations and caution
Unstable model catalog. xAI regularly retires older versions (six models cut in a single wave in May 2026). A workflow that hardcodes a specific model name can break overnight; check the list of active models in the xAI console before deploying, and plan for a fallback model.
Native tool cost to watch. Web search, X search, and code execution are billed separately ($5 to $10 per 1,000 calls): an agent that triggers these tools on every message can see its bill climb much faster than a simple token count would suggest. The detailed tracking approach in our guide to AI API rate limits applies to this kind of variable cost too.
In summary
- Create your key on console.x.ai and store it in a dedicated xAI credential in n8n.
- Use the native xAI Grok Chat Model node for new workflows, or the
https://api.x.ai/v1base URL on an OpenAI credential to reuse an existing setup. - Default to Grok 4.3, reserve Grok 4.5 for complex cases and Grok Build for code.
- Update n8n before combining AI Agent, streaming, and Grok in production, and test the full execution.
- Watch the cost of native tools (web, X, code) on top of the per-token price.
FAQ
Frequently asked questions
Are Grok and Groq the same provider in n8n?
No, they're two distinct companies despite the near-identical name. Grok is xAI's (Elon Musk) language model, with native access to web and X search. Groq (no 'k' after the 'o') is an inference host that runs open models like Llama on dedicated hardware. n8n ships a separate node for each: xAI Grok Chat Model and Groq Chat Model — don't mix them up when picking a credential.
How do I get an xAI API key for n8n?
Create an account on console.x.ai, open the API Keys section, generate a key and copy it immediately. Then enter it in an xAI credential on the n8n side rather than in a Code node or a plain-text variable.
Does n8n's AI Agent node work correctly with Grok?
For the most part, yes, but a bug once broke the combination of the AI Agent node with streaming and Grok (an 'Argument not supported: stream_options' error), documented on n8n's GitHub repo. A fix has since shipped: update your n8n instance to a recent version before relying on this combination in production, and test the full execution — model, memory, tools — before deploying it.
Which Grok model should I pick for an n8n workflow?
Grok 4.5 for an agent that needs to reason through ambiguous cases (500K-token context, the priciest option); the Grok 4.3 family for most production tasks, with a much better price-to-quality ratio and up to 1M tokens of context; Grok Build (the dedicated coding model) for generating or reviewing code from a workflow. Always check the list of active models in the xAI console — older versions get retired regularly.
Bundle FlowKit Complet
€269