Text size
Dark mode
RecallRunGuides & benchmarks
Learn to build real systemsGuides•Benchmarks•Experiments•Community
Search the site/Free checklist

Guides/OpenAI SDK

OpenAI SDK: Built-in tools

Function tools (part 07) run in your code. Built-in (hosted) tools run on OpenAI's side within the same request: web search , file search over your uploaded…

In this post

What this post covers
  1. 1. The catalogue
  2. 2. Web search with citations
  3. 3. Code interpreter: let the model compute
  4. 4. Remote MCP servers
  5. 5. Hosted, function, or both?
  6. Recap

Function tools (part 07) run in your code. Built-in (hosted) tools run on OpenAI’s side within the same request: web search, file search over your uploaded documents, a code interpreter sandbox, image generation, and remote MCP servers. You enable them with one line, and the response contains items showing what the tool did. They save a lot of plumbing, at the cost of control and extra tool fees.

1. The catalogue

typeWhat it doesKey options
web_searchsearches the web and answers with cited sourcessearch_context_size, user_location, domain filters
file_searchsemantic + keyword search over files in your vector storesvector_store_ids, max_num_results, metadata filters (part 14)
code_interpreterruns Python in a sandbox container: analysis, charts, file conversionscontainer (e.g. {"type": "auto"})
image_generationcreates or edits images inside a conversationsize, quality, background
mcpcalls tools on a remote MCP server (see the AI Engineering guide)server_label, server_url, allowed_tools, require_approval

Type names come from the installed SDK’s type definitions (openai 2.44). Availability and pricing vary by model, so check the tools guide for yours.

2. Web search with citations

real API

from openai import OpenAI

client = OpenAI()
response = client.responses.create(
    model="gpt-5.6-luna",
    tools=[{"type": "web_search"}],
    input="What changed in the latest Python release? Cite sources.",
)
print(response.output_text)

for item in response.output:
    if item.type == "web_search_call":
        print("searched:", item.status)
    elif item.type == "message":
        for part in item.content:
            for ann in getattr(part, "annotations", []):
                if ann.type == "url_citation":
                    print("source:", ann.title, ann.url)
Show the sources

Answers from web search should display their url_citation annotations to users. That is both good practice and required by OpenAI's usage guidelines for this tool. Citations are also your main defence against confident-but-wrong answers: users can check.

3. Code interpreter: let the model compute

real API

response = client.responses.create(
    model="gpt-5.6-luna",
    tools=[{"type": "code_interpreter", "container": {"type": "auto"}}],
    instructions="Use Python for any arithmetic. Show the final numbers only.",
    input="Monthly revenue: 120, 135, 128, 160, 171, 190 (lakh). What is the average month-on-month growth rate?",
)
print(response.output_text)          # the maths was executed, not predicted token by token

Language models are poor calculators. Letting them write and run code turns arithmetic, statistics and data wrangling into something reliable. Containers are billed separately from tokens and expire after a period of inactivity.

4. Remote MCP servers

real API — a hosted MCP server's tools become available to the model

response = client.responses.create(
    model="gpt-5.6-luna",
    tools=[{
        "type": "mcp",
        "server_label": "docs",
        "server_url": "https://example.com/mcp",       # an MCP server you trust
        "allowed_tools": ["search_docs"],              # expose only what you need
        "require_approval": "always",                  # your code approves each call (safer default)
    }],
    input="How do I rotate an API key? Search our docs.",
)
for item in response.output:
    print(item.type)        # mcp_list_tools, mcp_approval_request, mcp_call, message …

With require_approval, the response contains an mcp_approval_request item. You reply with an approval item to let the call proceed. The AI Engineering guide builds an MCP server (parts 12–14) and explains why a third-party MCP server deserves the same scrutiny as any other code that can act on your behalf.

5. Hosted, function, or both?

Hosted tools when…

The capability is generic (web search, sandboxed Python, document search) and you are happy for it to run on OpenAI's infrastructure. Least code, fastest to ship.

Function tools when…

It touches your systems, data or money; you need your own permissions, logging, caching or retries; or you might switch model provider later.

They combine freely: one request can offer web search, file search and your own functions, and the model picks per step.

Recap

  • Hosted tools run inside the request: web_search, file_search, code_interpreter, image_generation, mcp.
  • Their activity appears as output items; citations appear as annotations.
  • Show sources, restrict MCP tools, require approval for anything that acts.
  • Function tools for your own systems; mix both as needed.

Get the free RAG production checklist

25 checks to run before real users see your RAG feature: exact-match misses, invented citations, prompt injection through documents, quality that slips after a prompt change. Confirm your email and the PDF comes with the welcome email, plus each new experiment.

One email to confirm. Unsubscribe any time. What's in it · Privacy

Want the production version of this? See ShipRAG: A production RAG + MCP starter kit for FastAPI: hybrid search, validated citations, evals in CI, Docker, 32 tests.

Written by

Alby Tomy

Python/FastAPI Engineer | Data Engineer | AI Engineer building RAG and MCP systems.

X · GitHub · Contact & enquiries