[Feature]: xai support for responses and native tools: x_search, web_search, code_exec
Summary
I know this issues has been brought up multiple times before and PRs have been suggested but all have been shut down so far.
Grok 4.1 Fast feels artificially handicapped as compared to the Grok app use. Quite possible because openclaw does not allow configuring the xAI API to use responses API and native server side tools:
- web_search - parallel and much faster than client side brave search. Brave index does not keep up with API docs. Try for example asking Brave to search for Resend inbound email polling API. It keeps insisting that it does not exist (only webhook option). Grok chat app instantly spawns multiple search queries and finds the new emails/receiving API using its own native web search backend.
- x_search - real time, up to date information - super helpful for fast moving openclaw with constant stream of x updates. No client side library can possibly match up to the minute native X search from Grok.
- sandboxed code exec - very useful for grounding calculations, timeseries research , charts/visualisation , etc.
On top of being a very powerful model it is also practically Free ($0.2/1M output tokens + input caching) and has a massive 2M context. Grok 4.2 is about to be released and its already SOTA for market trading and other benchmarks.
Proposed solution
Ideally enable native xAI provider via Vercel's AI SDK, which is referenced in the official xAI docs.
Alternatives considered
If not, then allow the extra config options in the openclaw.json schema for /responses end point and native tools via existing OpenRouter and Vercel Providers.
Additional context
This is a prompt-style PR as requested by Peter in his podcast appearances.
What this PR does
Extends support for xAI/Grok (building on existing partial integrations like Grok as web_search provider) by adding Responses API usage to the xAI provider config. This enables Grok models (e.g., grok-4.1-fast) to use native server-side tools (web_search, x_search, code_execution, etc.) with autonomous multi-step loops handled by xAI servers.
It keeps everything under a single "xai" provider entry in openclaw.json β no new top-level provider type. Adds config flags to toggle Responses mode and hybrid behavior, so users can opt into native server-side while still using OpenClaw's client-side tools/skills (browser, canvas, nodes, cron, sessions, ClawHub, etc.) when needed.
Why this is useful
- Builds incrementally on current xAI/Grok usage (OpenAI-compat + recent search provider additions) instead of forking provider logic.
- Unlocks full Grok agentic power (low-latency native tools, 2M context) without breaking existing setups or requiring a separate provider.
- Enables hybrid workflows: native server-side for research/code β client-side OpenClaw tools for local actions β back to Grok.
- Improves Grok reliability on agentic tasks (vs. pure client-side limitations) while preserving local ecosystem.
- Backward compatible: standard xAI calls unchanged; Responses is opt-in.
How to test
- Update/add to
~/.openclaw/openclaw.json(example below). - Native-only test:
openclaw agent --model xai/grok-4.1-fast "Search recent X posts about OpenClaw and run code to count mentions"β uses native x_search + code_execution. - Hybrid test:
"Search web for latest OpenClaw skills, install one via ClawHub, then list sessions"β native web_search β client-side ClawHub/sessions tools. - Disable Responses: set
"useResponsesApi": falseβ falls back to standard chat/completions + full client-side tools.
Config example (under "models.providers"):
"xai": {
"provider": "xai", // or "openai" compat if preferred
"apiKey": "xai-YourKeyHere",
"baseUrl": "https://api.x.ai/v1", // or Vercel proxy: https://gateway.ai.vercel.com/v1/xai
"models": {
"default": "grok-4.1-fast",
"reasoning": "grok-4.1-fast-reasoning"
},
"useResponsesApi": true, // toggle for native server-side mode
"tools": {
"native": { // xAI natives (only active when useResponsesApi: true)
"web_search": { "allowedDomains": [] },
"x_search": { "allowedXHandles": [] },
"code_execution": true
},
"clientSide": ["browser", "canvas", "nodes", "cron", "sessions_list", "clawhub_install"] // exposed as custom tools
},
"reasoningEffort": "high", // optional Responses flag
"hybrid": true // opt-in for mixing
}
Changes overview
- Detect
"useResponsesApi": truein xAI provider config β switch to Responses API endpoint via Vercel AI SDK (@ai-sdk/xai). Install:pnpm add @ai-sdk/xai ai. - Wrapper logic (e.g., extend existing xAI/OpenAI compat handler or add to
src/providers/xai.js): usexai.responses(model)+generateText/streamTextwhen enabled. - Pass native tool configs + custom client-side schemas (from OpenClaw's tool registry/TOOLS.md).
- Hybrid loop: If Responses returns client-side tool calls β execute locally via agent runtime β feed results back (continue Responses or fallback).
- Prioritize native tools for speed; fallback/delegate to OpenClaw skills when matched or hybrid disabled.
- Security: allowlists for natives and client tools; no auto-enable.
- Fallback: when
"useResponsesApi": false, use standard/chat/completionspath.
Testing status
- Lightly tested: native tools work via direct xAI; hybrid prototype (native search β client browser) succeeds manually.
- Not battle-tested in multi-agent/high-load β feedback appreciated on edges.
- Verified macOS/Linux; no regressions to existing providers/tools.
AI-assisted notes
- This PR / plan was vibe-coded / assisted by Grok 4.1 (xAI).
- Prompt logs / reasoning available on request (based on xAI docs + Vercel SDK examples).
- I understand the changes: toggles within existing provider, adds SDK integration, secure hybrid mapping, preserves fallbacks.
Related issues / motivation
- Builds on recent PRs like feat(tools): add Grok (xAI) as web_search provider.
- No core issue for full Responses/hybrid yet (repo search: "grok", "xai", "responses").
- Community demand (Discord/X) for better Grok beyond compat mode.
- Refs: xAI Responses docs (https://docs.x.ai/docs/responses-api), Vercel AI SDK xAI provider, Advanced mixing server/client tools.
Happy to iterate β mark as draft if needed. Let's make xAI/Grok shine natively in OpenClaw! π¦π€
Yes! We need grok powering more openclaw bots! Here are some thoughts on this: X Post
Yes, this is VERY much needed!! Please!!
Would love this as well. Grok 4.2 coming out soon too
Yes please,
this is what I need.
Yes, this is VERY much needed!! Please!!
add support
Add Support please !!!
we needed this like a week ago =) still need a lot! Please π
please also support openrouter grok variants model! i am using grok model via openrouter, and its model name is openrouter/x-ai/grok-4.1-fast:online, however, openclaw cannot parse the β:onlineββ¦ which makes the grok model lose its capability to do web search or x search! this is really really frustrating. not just me, lots of people having this same issue
Proposal: xAI Responses API mode for native tools (x_search first-class)
Goal: Enable Grok models in OpenClaw to use xAI's server-side toolchain (especially x_search) by adding an opt-in Responses API mode to the existing xai provider.
Problem
Today Grok in OpenClaw typically runs via chat/completions-style calls. That works for text, but it does not unlock the "Grok app" behavior:
- server-side agent loops
- native tools like
x_search(real-time X search), plusweb_search,code_execution
This makes Grok feel artificially limited vs the official app, and users resort to brittle workarounds.
Proposed solution (MVP, safe + minimal)
- Add a provider-level switch (OFF by default), e.g.
models.providers.xai.mode = "chat_completions" | "responses"- or
models.providers.xai.useResponsesApi: true
- or
- When
mode="responses":
- call xAI Responses API endpoint
- allow xAI server-side tools to be used by the model (tool calls + tool results handled by xAI)
- normalize the response back into OpenClaw's internal message format so sessions/UI behave normally
- Tool collision policy (important):
- In Responses mode, disable client-side tools that collide with xAI server-side tools (at minimum
web_search) to avoid double-search / inconsistent behavior. - Keep OpenClaw local tools (browser/canvas/nodes/exec) available, but avoid auto-injecting anything that shadows xAI tool names.
- Scope (MVP):
x_search(primary)web_searchcode_execution
- Test plan (MVP):
- smoke test: prompt that triggers
x_searchβ verifies tool call + results returned - regression: default mode unchanged
- guard: no duplicated
web_searchwhen using xAI server-side tools
Why this is worth it
x_searchis uniquely valuable (real-time, high-signal)- closes the perceived gap between Grok in OpenClaw and Grok in the native app
- keeps changes opt-in and low risk
If maintainers are OK with the direction, I'm happy to submit a minimal PR implementing the config switch + adapter plumbing first, then a follow-up for tool enablement + tests.
It's been over a month... Is OpenAI putting its finger on the scale to intentionally suppress support for competitive cloud providers?
As a workaround I am using nanobot , which uses litellm for model routing. Works fine. Quick setup. Openclaw has a new rule to ask nanobot to do deep research. We will see over time how the balance of workloads shifts between openclaw and nanobot.
add support this, as grok ai seems very handicapped in using server side tools eg. save files , open files, sometimes not working.
bump. yes please add xAI native tool support :3
Looks like the openclaw dev team / OpenAI are not particularly interested in this improvement. In the meanwhile, I've been able to successfully use xai Grok 4.20 with native + local tools via a custom skill. The main SKILL.md follows. Not including scripts for safety concerns. Just ask your openclaw to add the scripts for direct integration via xai's python SDK:
SKILL.md
---
name: deep-research
description: Deep research and audit skill using Grok 4.20 with native xAI tools (web search, X search, code execution) combined with OpenClaw read-only local tools.
version: 1.0.3
trigger: research|audit|analyze|search|deep research|x search|twitter|x twitter
requires:
env:
- XAI_API_KEY
run_location: main
metadata:
user-invocable: true
disable-model-invocation: false
---
# Deep Research Skill
Research and audit using Grok 4.20 with native xAI tools + OpenClaw local tools.
## Triggers
- `research <topic>` β Deep research mode (web + X + code)
- `x search <topic>` β X/Twitter search only (using xAI's native x_search)
- `twitter <topic>` β Same as x search
- `analyze <topic>` β Quick analysis
- `audit <target>` β Security/compliance audit
- `search <topic>` β General search (web + X)
- `deep research skill` β Show help
## Why X Search via xAI?
xAI's native `x_search` tool is the best way to search X/Twitter because:
- Direct API access to X data
- Semantic search capability
- User search, keyword search, thread fetching
- No rate limits or authentication issues
## Tools
### xAI Native Tools
| Tool | Purpose |
|------|---------|
| `web_search` | Real-time web search + browsing |
| `x_search` | X/Twitter post search (user, keyword, semantic, threads) |
| `code_execution` | Python sandbox for data analysis |
### OpenClaw Local Tools (read-only)
| Tool | Purpose |
|------|---------|
| `read` | Read file contents |
| `exec` | Read-only shell (ls, find, grep, tree, stat) |
| `web_fetch` | URL content extraction |
| `browser` | Interactive web browsing |
## Workflow
### X Search Mode (for x search / twitter triggers)
1. Parse topic
2. Use xAI's x_search tool
- x_semantic_search for topic understanding
- x_keyword_search for exact matches
- x_user_search for user-specific posts
- x_thread_fetch for thread details
3. Compile findings with sentiment analysis
### Research Mode
1. Parse topic, determine scope
2. Web search for latest info
3. X search for social sentiment
4. Code execution for data analysis
5. File/directory exploration if needed
6. Compile findings with citations
### Audit Mode
1. Target identification (URL, repo, code, docs)
2. Security/compliance web search
3. Code analysis via file reads
4. Generate audit report
## Output
- Structured research report with citations
- X/Twitter analysis with post examples
- Audit findings with severity ratings
## Requirements
- `XAI_API_KEY` β xAI API key (required)
- Virtual environment at `skills/deep-research/venv/`
## Installation
Run the setup script to create the virtual environment and install dependencies:
```bash
cd skills/deep-research
./setup.sh
Or manually:
cd skills/deep-research
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
Execution (IMPORTANT)
Must run in MAIN AGENT, NOT subagent β subagents don't get access to xAI's native x_search tool.
How it Works
The skill uses xai-sdk directly (not OpenClaw model switching) to call xAI's API with native tools. It streams results back to the user in real-time.
How to Run
- Activate venv:
source skills/deep-research/venv/bin/activate - Run research.py with your query:
python scripts/research.py "<your topic>" - For streaming support, use client.py's
chat_complete_with_streaming()method
Invocation
When user says "x search
- Recognize trigger
- Run the Python script in main agent with streaming
- Stream results to user in real-time
Never spawn a subagent for this skill β it needs direct xai-sdk access.