Skip to main content
Lesson 9 of 16 · Responses API: Primary Endpoint

Built-in Tools for the Responses API

Lesson 9 of 16 Updated July 30, 2026 Developer
On this page
  1. Adding Capabilities to the Model
  2. The 4 Tool Types
  3. Combining Multiple Tools
  4. Server-Side vs. Client-Side Tools
  5. Key Takeaways

Adding Capabilities to the Model

Grok models aren’t limited to text generation. Using the tools parameter, you can give them access to tools that significantly extend their capabilities: real-time web search, search on X (formerly Twitter), Python code execution, and your own custom functions.

web_search
Real-time web search
x_search
Search on X
code
Python Interpreter
function
Custom functions

The 4 Tool Types

Lets the model search for information on the web in real time:

{
  "model": "grok-4.20-0309-reasoning",
  "input": "What's the latest news on AI in Europe?",
  "tools": [{"type": "web_search"}]
}

The model automatically decides when to perform a search. Results are integrated into its response with citations.

Searches for posts on X (formerly Twitter):

{
  "model": "grok-4.20-0309-reasoning",
  "input": "What is the tech community saying about the latest iPhone?",
  "tools": [{"type": "x_search"}]
}

Particularly useful for capturing public opinion, trends, and real-time reactions.

code_interpreter

Executes Python code server-side for calculations, data analysis, or creating charts:

{
  "model": "grok-4.20-0309-reasoning",
  "input": "Calculate the mean and standard deviation of these values: 12, 15, 18, 22, 9, 31",
  "tools": [{"type": "code_interpreter"}]
}

The model writes Python code, executes it on xAI servers, and integrates the results into its response.

function

Your own functions that the model can call. The model generates the arguments, but your code executes the function:

{
  "model": "grok-4.20-0309-reasoning",
  "input": "What's the weather in Paris?",
  "tools": [{
    "type": "function",
    "name": "get_weather",
    "description": "Retrieves the weather for a given city",
    "parameters": {
      "type": "object",
      "properties": {
        "city": {"type": "string", "description": "City name"},
        "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}
      },
      "required": ["city"]
    }
  }]
}

Combining Multiple Tools

You can pass up to 128 tools in a single request. The model chooses the one (or ones) that fit:

{
  "model": "grok-4.20-0309-reasoning",
  "input": "Search for the latest Ligue 1 results and create a scoreboard.",
  "tools": [
    {"type": "web_search"},
    {"type": "code_interpreter"}
  ]
}

In this example, the model might first use web_search to find the results, then code_interpreter to format them into a table.

Server-Side vs. Client-Side Tools

The distinction is fundamental:

  • Server-side tools (web_search, x_search, code_interpreter): Automatically executed by xAI servers. You don’t have to do anything—the model launches the search or code, retrieves the result, and integrates it into its response.

  • Client-side tools (function): The model generates a function call with arguments, then pauses generation. Your code executes the function, and you send the result back in a new request.

This difference directly impacts your application architecture, as you’ll see in the following lessons.

Key Takeaways

  • Four tool types: web_search, x_search, code_interpreter, function
  • The first three run server-side—no infrastructure required on your part
  • function tools run client-side—your code handles execution
  • You can combine up to 128 tools per request
  • The model automatically decides when and which tools to use