Sub topic 1
Built-in tools versus function tools
Prerequisites
This chapter assumes you have:
- Basic Python and an API key for a model provider.
- Made a request to a chat or responses API and read the JSON that came back.
- Seen function calling at least once, meaning the model asks for a function and your code answers.
The examples use the OpenAI Python SDK and its Responses API. The ideas also apply to other providers, which later chapters compare.
The core difference
A tool is a capability the model can ask for during a request. The model cannot run anything itself. It produces text, and something else must act on that text. The difference between the two tool families is who does the acting.
- A function tool is one you define. You describe it with a name and a JSON schema. The model emits a call, and your code runs it and sends the result back.
- A built-in tool is one the provider hosts. You switch it on by name. The provider runs it on its own infrastructure and folds the result into the response.
Web search, code execution, and file search are built-in tools. The rest of this tutorial covers them one by one. This chapter sets up the model you need to tell them apart.
Who runs the loop
With function tools, your application owns the loop. One user question usually costs at least two API requests. The first returns a tool call. The second carries the tool result.
With built-in tools, the provider owns the loop. The model may search, read, search again, and then answer, all inside one request from your side. You receive one final response.
A function tool, end to end
This example shows the full round trip. The function is a stub, so the code runs without any other service.
import json
from openai import OpenAI
client = OpenAI()
def get_weather(city: str) -> str:
return f"It is 18 degrees C and cloudy in {city}."
tools = [
{
"type": "function",
"name": "get_weather",
"description": "Get the current weather for a city.",
"parameters": {
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"],
"additionalProperties": False,
},
"strict": True,
}
]
first = client.responses.create(
model="gpt-4.1",
tools=tools,
input="What is the weather in Oslo?",
)
outputs = []
for item in first.output:
if item.type == "function_call":
args = json.loads(item.arguments)
outputs.append(
{
"type": "function_call_output",
"call_id": item.call_id,
"output": get_weather(**args),
}
)
second = client.responses.create(
model="gpt-4.1",
tools=tools,
previous_response_id=first.id,
input=outputs,
)
print(second.output_text)Your code does four jobs here: it declares the schema, detects the call, executes it, and returns the result. If you skip the second request, the user never gets an answer.
A built-in tool, end to end
Now the same shape of task with a built-in tool. There is no schema, no executor, and no second request.
from openai import OpenAI
client = OpenAI()
response = client.responses.create(
model="gpt-4.1",
tools=[{"type": "web_search"}],
input="What are the most recent stable releases of Python?",
)
print(response.output_text)The tools entry has only a type. The provider already knows the tool's name, its parameters, and how to run it. You can tune it with extra fields, which later chapters cover.
What the response looks like
Both kinds of tool leave a trace in response.output, which is a list of typed items. The types differ.
| Aspect | Function tool | Built-in tool |
|---|---|---|
| Who defines the schema | You | Provider |
| Who executes it | Your code | Provider infrastructure |
| Requests per user question | Two or more | One |
| Item left in the output | `function_call` | `web_search_call`, `code_interpreter_call`, `file_search_call` |
| Your obligation after the call | Return a `function_call_output` | None |
| Access to your private systems | Yes, anything your code can reach | Only what you upload or configure |
| Visibility into the work | Full, you wrote it | Partial, you see call items and sources |
| Billing | Normal token cost | Token cost plus per-call or per-session fees |
The built-in call items are records of work that is already done. You do not answer them. Their status field and attached sources help you audit what happened.
for item in response.output:
print(item.type)A typical web search response prints web_search_call followed by message. A function tool response prints function_call and then waits for you.
Edge cases and common errors
- Treating a built-in call as pending. A beginner's loop that waits for a result after seeing
web_search_callwill hang or error. Onlyfunction_callitems need a reply. - Mixing both kinds in one request. You can list built-in tools and function tools together. The model may call either. Your loop must handle
function_callitems and ignore the built-in ones. - Assuming the tool ran. A tool in the list is only an option. The model decides whether to use it. If the output has no call item, no tool ran, and the answer came from the model's training data.
- Expecting your data to be reachable. A built-in tool runs on the provider's side. Code execution cannot reach your database. Web search cannot reach your intranet. If you need those, write a function tool.
- Hidden cost. One request can trigger several searches or a long code session. The token count alone understates the bill.
- Version and availability drift. Tool type names, such as Anthropic's
web_search_20250305, carry version strings. Availability varies by model and account. Check the provider's current documentation before relying on a tool.
Choosing between them
Start from where the capability lives.
- If the capability is generic and the provider offers it (searching the public web, running calculations, searching uploaded documents), try the built-in tool first. You write less code and have fewer failure points.
- If the capability touches your own systems (an internal API, a database, a payment action), use a function tool. Only your code has access.
- If you need exact control over inputs, timeouts, retries, logging, or caching, use a function tool. A built-in tool is a black box with a few settings.
- If you need the same behavior across several providers, a function tool is more portable. Built-in tool names and options differ by provider.
Many production systems combine both. A support agent might use file search over a handbook, a function tool to look up an order, and web search for shipping carrier status.
Exercise
Exercise
A request lists a websearch built-in tool and a function tool named lookuporder. The response output contains a websearchcall item, a functioncall item for lookuporder, and no message item. What must your code do next, and why does it not need to answer the websearchcall?
Show answer
Run lookuporder with the arguments from the functioncall item, then make a second request that includes a functioncalloutput with the same callid (for example with previousresponseid set). The websearchcall needs no answer because the provider already ran the search; the item only records that it happened. The functioncall is unfinished work that only your code can complete.
Exercise
A teammate says, "We added the web_search tool, so every answer is now grounded in current information." Name one way to check this claim from a response, and one reason it can still be false.
Show answer
Check whether response.output contains a websearchcall item (and url_citation annotations on the message). It can be false because listing a tool only makes it available. The model decides whether to call it, so a response with no call item came from training data alone.