Tools
Overview
The xAI API supports tool calling, enabling Grok to perform actions beyond generating text—like searching the web, executing code, querying your data, or calling your own custom functions. Tools extend what's possible with the API and let you build powerful, interactive applications.
Types of Tools
The xAI API offers two categories of tools:
| Type | Description | Examples |
|---|---|---|
| Built-in Tools | Server-side tools managed by xAI that execute automatically | Web Search, X Search, Code Interpreter, Image Generation, Collections Search |
| Function Calling | Custom functions you define that the model can invoke | Database queries, API calls, custom business logic |
Built-in tools run on xAI's servers—you provide the tool configuration, and the API handles execution and returns results. Function calling lets you define your own tools that the model can request, giving you full control over what happens when they're invoked.
Pricing
Tool requests are priced based on two components: token usage and tool invocations. Since the model may call multiple tools to answer a query, costs scale with complexity.
For more details on Tools pricing, please check out the pricing page.
How It Works
When you provide tools to a request, the xAI API can use them to gather information or perform actions:
Analyzes the query and determines what information or actions are needed
Decides what to do next: Make a tool call, or provide a final answer
Executes the tool (for built-in tools) or returns a tool call request (for function calling)
Processes results and continues until sufficient information is gathered
Returns the final response with citations where applicable
Quick Start
curl https://api.x.ai/v1/responses \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $XAI_API_KEY" \
-d '{
"model": "grok-4.7",
"stream": true,
"input": [
{
"role": "user",
"content": "What are the latest updates from xAI?"
}
],
"tools": [
{ "type": "web_search" },
{ "type": "x_search" },
{ "type": "code_interpreter" }
]
}'Citations
The API automatically returns source URLs for information gathered via tools. See Citations for details on accessing and using citation data.
Next Steps
Function Calling - Define custom tools the model can call
Web Search - Search the web and browse pages
X Search - Search X posts, users, and threads
Code Execution - Execute Python code in a sandbox
Image Generation - Generate and edit images in a conversation
Collections Search - Query your uploaded documents
Citations - Access source URLs and inline citations
Last updated:July 13, 2026