Grok Web Search Integration with OpenClaw via xAI
This page explains how OpenClaw uses Grok as a web search provider with xAI web-grounded responses. It covers setup, OAuth fallback, and enabling x_search for X metrics.
Read this when
- You want to use Grok for web_search
- You want to use xAI OAuth or an XAI_API_KEY for web search
OpenClaw integrates Grok as a web_search provider, relying on xAI web-grounded responses to deliver AI-generated answers backed by live search results and citations.
When an existing xAI OAuth sign-in is available, Grok web search prefers using it. Without an OAuth profile, the same xAI API key also drives the built-in x_search tool for searching X (formerly Twitter) posts and the code_execution tool. Storing the key at plugins.entries.xai.config.webSearch.apiKey additionally allows OpenClaw to use it as a fallback for the included xAI model provider.
To retrieve post-level X metrics such as reposts, replies, bookmarks, and views, use x_search with the exact post URL or status ID rather than a broad search query.
Onboarding and configure
When you choose Grok during openclaw onboard or openclaw configure --section web, OpenClaw reuses an existing xAI OAuth profile without asking for a separate web-search key. If OAuth is not available, it falls back to xAI API-key configuration.
OpenClaw then presents a follow-up step to enable x_search using the same xAI credential. This follow-up:
- appears only after you select Grok for
web_search - does not act as a separate top-level web-search provider option
- can optionally configure the
x_searchmodel within the same flow
Skip it to enable or modify x_search later through configuration.
Sign in or get an API key
Use xAI OAuth
If you already authenticated with xAI during onboarding or model authorization, select Grok as the web_search provider. No separate API key is needed:
openclaw onboard --auth-choice xai-oauth
openclaw config set tools.web.search.provider grok
Use an API key fallback
Obtain an API key from xAI when OAuth is not available or you prefer key-based web-search configuration.
Store the key
Set XAI_API_KEY in the Gateway environment, or configure it using:
openclaw configure --section web
Config
{
plugins: {
entries: {
xai: {
config: {
webSearch: {
apiKey: "xai-...", // optional if xAI OAuth or XAI_API_KEY is available
baseUrl: "https://api.x.ai/v1", // optional Responses API proxy/base URL override
},
},
},
},
},
tools: {
web: {
search: {
provider: "grok",
},
},
},
}
Credential alternatives: openclaw models auth login --provider xai --method oauth, XAI_API_KEY in the Gateway environment, or plugins.entries.xai.config.webSearch.apiKey. For a gateway installation, place environment variables in ~/.openclaw/.env.
How it works
Grok uses xAI web-grounded responses to produce answers with inline citations, much like Gemini's Google Search grounding approach.
Supported parameters
Grok search supports query. count is accepted for shared web_search compatibility, but Grok always returns a single synthesized answer with citations instead of an N-result list. Provider-specific filters are not supported.
Grok defaults to a 60 second timeout because xAI Responses web-grounded searches may take longer than the shared web_search default. Override this with tools.web.search.timeoutSeconds.
Base URL overrides
Configure plugins.entries.xai.config.webSearch.baseUrl to route Grok web search through an operator proxy or an xAI-compatible Responses endpoint. OpenClaw sends requests to <baseUrl>/responses after removing trailing slashes. x_search falls back to the same webSearch.baseUrl unless plugins.entries.xai.config.xSearch.baseUrl is set.
Related
- Web Search overview -- covers all providers and auto-detection
- x_search in Web Search -- first-class X search via xAI
- Gemini Search -- AI-synthesized answers through Google grounding