code_interpreter, a server-side Python sandbox) and Remote MCP (xAI’s servers connect directly to an MCP server you specify). Both are verified working on APIYI (July 13, 2026, UTC+8) with a default-group key.
Code Execution
The model writes Python and actually runs it in xAI’s server-side sandbox — ideal for exact computation and data processing. In testing we asked for 2 to the power of 100: the model executedprint(2 ** 100) and returned the exact value (big-integer math that pure language models routinely get wrong; code execution is exact):
usage.server_side_tool_usage_details.code_interpreter_calls records the execution count.
Remote MCP Tools
Declare an external MCP server in the request and xAI’s servers automatically connect, list its tools, and call them as needed — no local MCP client required. Verified connecting to a public MCP server and completing a tool call (~16 s):| Parameter | Notes |
|---|---|
server_label | Your label for distinguishing multiple MCP servers |
server_url | MCP server address (must be publicly reachable — xAI’s servers connect directly) |
require_approval | "never" calls tools automatically; the default returns approval requests requiring a second round |
Collections Search (RAG) — Not Available
xAI also offers acollections_search (knowledge-base retrieval / file_search) tool. It is not usable on APIYI: it requires files uploaded and collections built in the xAI console beforehand, and APIYI runs in key-pool mode with no upstream console access. In testing the request passes through but retrieval inevitably fails (file_search_call returns failed).
For RAG, build retrieval on your side (vector store + inject recalled content into the prompt), leveraging Grok’s 1M context and automatic caching.
FAQ
Can I declare multiple tools at once?
Can I declare multiple tools at once?
Yes. The
tools array can include web_search / x_search / code_interpreter / mcp together; the model decides which to call per task. usage.server_side_tool_usage_details counts each separately.Can the code sandbox access the network or my files?
Can the code sandbox access the network or my files?
The sandbox targets computation (Python math / data processing) and cannot access your local files. For external data, combine it with web_search or MCP tools.
Are failed tool executions billed?
Are failed tool executions billed?
Model-side reasoning tokens are billed normally. Tool call fees follow APIYI tool pricing and your actual billing statement — validate with small volumes before scaling up.
Related Docs
Web & X Search
The live-search tools on the same Responses API
Grok Overview
Model lineup, pricing, and the full capability-boundary table