> ## Documentation Index
> Fetch the complete documentation index at: https://docs.routeway.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Built-in Tools

> Use web search, file search, and code interpreter without defining custom schemas.

The Responses API includes built-in tools that the model can invoke automatically — no function schemas required. These tools extend the model's capabilities beyond its training data.

<Info>
  Built-in tools are handled server-side. Unlike custom function calling (where your code executes the function), built-in tools execute automatically and return results to the model within the same request.
</Info>

## Available Built-in Tools

| Tool             | Type value           | Description                                         |
| ---------------- | -------------------- | --------------------------------------------------- |
| Web Search       | `web_search_preview` | Search the internet for current information         |
| File Search      | `file_search`        | Search through uploaded files using semantic search |
| Code Interpreter | `code_interpreter`   | Execute Python code in a sandbox                    |

***

## Web Search

Enable web search to let the model look up current information that isn't in its training data.

<Tabs>
  <Tab title="Python">
    ```python theme={null}
    import os
    from openai import OpenAI

    client = OpenAI(
        base_url="https://api.routeway.ai/v1",
        api_key=os.getenv("ROUTEWAY_API_KEY")
    )

    response = client.responses.create(
        model="gpt-4o",
        tools=[{"type": "web_search_preview"}],
        input="What were the top tech news stories today?"
    )

    print(response.output_text)
    ```
  </Tab>

  <Tab title="Node.js">
    ```javascript theme={null}
    import OpenAI from "openai";

    const client = new OpenAI({
      baseURL: "https://api.routeway.ai/v1",
      apiKey: process.env.ROUTEWAY_API_KEY,
    });

    const response = await client.responses.create({
      model: "gpt-4o",
      tools: [{ type: "web_search_preview" }],
      input: "What were the top tech news stories today?",
    });

    console.log(response.output_text);
    ```
  </Tab>

  <Tab title="cURL">
    ```bash theme={null}
    curl https://api.routeway.ai/v1/responses \
      -H "Authorization: Bearer $ROUTEWAY_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{
        "model": "gpt-4o",
        "tools": [{"type": "web_search_preview"}],
        "input": "What were the top tech news stories today?"
      }'
    ```
  </Tab>
</Tabs>

When the model uses web search, the `output` array includes a `web_search_call` item showing what was searched:

```json theme={null}
{
  "output": [
    {
      "type": "web_search_call",
      "id": "ws_abc123",
      "status": "completed"
    },
    {
      "type": "message",
      "role": "assistant",
      "content": [
        {
          "type": "output_text",
          "text": "Here are today's top tech stories..."
        }
      ]
    }
  ]
}
```

<Tip>
  Web search is useful for questions about current events, recent releases, live data, or anything that may have changed since the model's training cutoff.
</Tip>

***

## Code Interpreter

Let the model write and execute Python code to solve math problems, analyze data, or generate charts.

<Tabs>
  <Tab title="Python">
    ```python theme={null}
    response = client.responses.create(
        model="gpt-4o",
        tools=[{"type": "code_interpreter"}],
        input="Calculate the first 20 Fibonacci numbers and show them in a formatted table."
    )

    print(response.output_text)
    ```
  </Tab>

  <Tab title="Node.js">
    ```javascript theme={null}
    const response = await client.responses.create({
      model: "gpt-4o",
      tools: [{ type: "code_interpreter" }],
      input: "Calculate the first 20 Fibonacci numbers and show them in a formatted table.",
    });

    console.log(response.output_text);
    ```
  </Tab>
</Tabs>

The `output` array will include a `code_interpreter_call` item with the code that was executed:

```json theme={null}
{
  "output": [
    {
      "type": "code_interpreter_call",
      "id": "ci_abc123",
      "code": "fibs = [0, 1]\nfor i in range(18):\n    fibs.append(fibs[-1] + fibs[-2])\nprint(fibs)",
      "results": [
        {
          "type": "text",
          "text": "[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181]"
        }
      ]
    },
    {
      "type": "message",
      "role": "assistant",
      "content": [...]
    }
  ]
}
```

***

## Combining Multiple Tools

You can enable multiple built-in tools in the same request. The model decides which to use based on the input.

```python theme={null}
response = client.responses.create(
    model="gpt-4o",
    tools=[
        {"type": "web_search_preview"},
        {"type": "code_interpreter"}
    ],
    input="Look up the current population of the 10 largest countries, then create a bar chart comparing them."
)

print(response.output_text)
```

The model may:

1. Use web search to find current population data
2. Use code interpreter to generate the chart
3. Return the final answer with both tool calls visible in the `output` array

***

## Mixing Built-in and Custom Tools

You can combine built-in tools with your own custom function definitions:

```python theme={null}
response = client.responses.create(
    model="gpt-4o",
    tools=[
        {"type": "web_search_preview"},
        {
            "type": "function",
            "function": {
                "name": "save_to_database",
                "description": "Save structured data to the database.",
                "parameters": {
                    "type": "object",
                    "properties": {
                        "data": {"type": "object"},
                        "collection": {"type": "string"}
                    },
                    "required": ["data", "collection"]
                }
            }
        }
    ],
    input="Find the current Bitcoin price and save it to the prices collection."
)
```

<Warning>
  Built-in tools execute automatically on the server. Custom function calls still require your code to execute the function and submit results back. See [Tool Calling](/guides/chat-completions/tool-calling) for the full custom function workflow.
</Warning>

***

## Tool Choice

Control how the model selects tools with `tool_choice`:

| Value                            | Behavior                                     |
| -------------------------------- | -------------------------------------------- |
| `"auto"`                         | Model decides whether to use tools (default) |
| `"required"`                     | Model must use at least one tool             |
| `"none"`                         | Model cannot use any tools                   |
| `{"type": "web_search_preview"}` | Force a specific tool                        |

```python theme={null}
# Force the model to search the web
response = client.responses.create(
    model="gpt-4o",
    tools=[{"type": "web_search_preview"}],
    tool_choice={"type": "web_search_preview"},
    input="What is the current weather in Tokyo?"
)
```

***

## Best Practices

<CardGroup cols={2}>
  <Card title="Be specific about when to search" icon="search">
    If your prompt clearly needs current data, enable web search. For questions answerable from training data, skip it to save latency.
  </Card>

  <Card title="Use code interpreter for computation" icon="calculator">
    Models are better at writing code than doing arithmetic. For math-heavy tasks, enable code interpreter for accurate results.
  </Card>

  <Card title="Check output items" icon="list-checks">
    Inspect the `output` array to see which tools were used and verify the model's reasoning chain.
  </Card>

  <Card title="Combine thoughtfully" icon="layers">
    Enabling too many tools can confuse the model. Enable only the tools relevant to the task at hand.
  </Card>
</CardGroup>
