Sub topic 3
Declaring Built-in Tools in a Request
This chapter assumes you can call a responses or messages API with an API key, read JSON bodies, and know the basic idea of function calling. You will learn how to declare a built-in tool, what each provider expects, and which mistakes come up most often.
The working model
A built-in tool is declared as an entry in the request's tools list. Unlike a function tool, it carries no JSON schema for arguments. You name the tool by its type, add optional settings, and the provider supplies the behavior.
The type string selects the tool. Settings sit beside it in the same object. Which settings are allowed depends on the tool and the provider.
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 provider may run several searches before it returns. You make one call and get one final answer.
Tool-specific settings
Each tool takes its own settings.
| Tool | Declaration | Settings shown here |
|---|---|---|
| Web search (OpenAI) | `{"type": "web_search"}` | None required |
| Code execution (OpenAI) | `{"type": "code_interpreter", "container": {"type": "auto"}}` | `container` |
| File search (OpenAI) | `{"type": "file_search", "vector_store_ids": [...]}` | `vector_store_ids`, `max_num_results` |
| Web search (Anthropic) | `{"type": "web_search_20250305", "name": "web_search"}` | `name`, `max_uses` |
Two examples show the difference in how much setup a tool needs.
Code execution needs a container. Setting "type": "auto" asks the provider to create one for the request.
response = client.responses.create(
model="gpt-4.1",
tools=[{"type": "code_interpreter", "container": {"type": "auto"}}],
instructions="When a question involves arithmetic, write and run code to answer it.",
input="What is the sum of the squares of the integers from 1 to 1000?",
)
print(response.output_text)File search needs documents that are already indexed. The declaration points at a vector store by ID, so the store must exist before the request.
response = client.responses.create(
model="gpt-4.1",
tools=[
{
"type": "file_search",
"vector_store_ids": [vector_store.id],
"max_num_results": 3,
}
],
input="How many vacation days do new employees get?",
)This snippet assumes vector_store was created and filled first. A later chapter covers that setup.
Anthropic uses versioned types
Anthropic names built-in tools with a dated type and also requires a name. The date is part of the tool's identity.
import anthropic
client = anthropic.Anthropic()
message = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=1024,
tools=[
{
"type": "web_search_20250305",
"name": "web_search",
"max_uses": 3,
}
],
messages=[
{"role": "user", "content": "What are the latest developments in solid-state batteries?"}
],
)
for block in message.content:
if block.type == "text":
print(block.text)The max_uses setting caps how many searches one request can run.
Common errors
- Wrong type string. A misspelled or outdated
typeis rejected. Copy it from the provider's current documentation, and expect Anthropic's versioned strings to change. - Missing prerequisites. File search fails or returns nothing useful if the vector store is empty or its files are still processing.
- Unsupported model. Not every model supports every built-in tool. An error on a valid declaration often means the model is the cause.
- Assuming the tool ran. Declaring a tool only makes it available. The model decides whether to use it, so check the response for tool-call items.
- Mixing up tool kinds. Do not add a
parametersschema to a built-in tool. Schemas belong to function tools.
Exercise
You declare {"type": "file_search", "vector_store_ids": ["vs_123"]} and the answer ignores your documents. Name two things to check.
Show answer
First, check that the vector store exists and that its files finished indexing, because an empty or still-processing store gives the tool nothing to retrieve. Second, check the response output for a file search call item to see whether the model used the tool at all. If it did not, add instructions that tell it to search the documents. Also confirm the model supports file search.