Home › OpenAI API lesson 2: Web search, JSON
OpenAI API lesson 2: Web search, JSON
Two built-in features make answers usable inside an app: the web_search tool for current information with citations, and Structured Outputs so the reply always matches your JSON schema.
Step by step
- Add tools: [{ type: "web_search" }] to a Responses API call.
- Read the url_citation annotations (URL, title, location) and show the sources to your users.
- For JSON, define a schema with Pydantic (Python) or Zod (JavaScript).
- Pass it as text_format (Python parse helper) or with zodTextFormat (JavaScript).
- Use the parsed object in your code instead of parsing free text.
Try it: examples
- Web search
What are this week's opening hours for the city library? Cite the official page.
- Structured output
Extract the event name, date and list of attendees from: “Alice and Bob are going to a science fair on Friday.”
Good to know
- New integrations should use web_search; the older web_search_preview tool lacks newer controls such as filters.
- Structured Outputs remove the need to validate or retry badly formatted replies.
Sources (official pages, read Nov 8, 2026)
Written from OpenAI's official documentation and product pages; we don't run hands-on tests. Features and limits vary by plan and country.