Notebooks
O
OpenAI
Introduction To Deep Research Api

Introduction To Deep Research Api

deep_research_apichatgptopenaigpt-4examplesopenai-apiopenai-cookbook

Introduction to the Deep Research API

Background

The Deep Research API enables you to automate complex research workflows that require reasoning, planning, and synthesis across real-world information. It is designed to take a high-level query and return a structured, citation-rich report by leveraging an agentic model capable of decomposing the task, performing web searches, and synthesizing results.

Unlike ChatGPT where this process is abstracted away, the API provides direct programmatic access. When you send a request, the model autonomously plans sub-questions, uses tools like web search and code execution, and produces a final structured response. This cookbook will provide a brief introduction to the Deep Research API and how to use it.

You can access Deep Research via the responses endpoint using the following models:

  • o3-deep-research-2025-06-26: Optimized for in-depth synthesis and higher-quality output
  • o4-mini-deep-research-2025-06-26: Lightweight and faster, ideal for latency-sensitive use cases

Setup

Install requirements

Install the latest version of the OpenAI Python SDK.

[ ]

Authenticate

Import the OpenAI client and initialize with your API key.

[ ]

Getting started

Let’s walk through an example of a Deep Research API call. Imagine we’re working at a healthcare financial services firm tasked with producing an in-depth report on the economic implications of recent medications used to treat type 2 diabetes and obesity—particularly semaglutide. Our goal is to synthesize clinical outcomes, cost-effectiveness, and regional pricing data into a structured, citation-backed analysis that could inform investment, payer strategy, or policy recommendations.

To get started, let's:

  • Put our role in the system message, outlining what type of report we'd like to generate
  • Set the summary paramter to "auto" for now for the best available summary. (If you'd like for your report to more detailed, you can set summary to detailed)
  • Include the required tool web_search_preview and optionally add code_interpreter.
  • Set the background parameter to True. Since a Deep Research task can take several minutes to execute, enabling background mode will allow you to run the request asynchronously without having to worry about timeouts or other connectivity issues.
[ ]

Parse the Response

The Deep Research API response includes a structured final answer along with inline citations, summaries of the reasoning steps, and source metadata.

Extract the Final Report Output

Here's the main text output of this report.

[ ]

Access Inline Citations and Metadata

Inline citations in the response text are annotated and linked to their corresponding source metadata. Each annotation contains:

  • start_index and end_index: the character span in the text the citation refers to
  • title: a brief title of the source
  • url: the full source URL

This structure will allow you to build a citation list or bibliography, add clickable hyperlinks in downstream apps, and highlight & trace data-backed claims in your report.

[ ]

Inspect Intermediate Steps

The Deep Research API also exposes all intermediate steps taken by the agent, including reasoning steps, web search calls, and code executions. You can use these to debug, analyze, or visualize how the final answer was constructed. Each intermediate step is stored in response.output, and the type field indicates what kind it is.

Reasoning Step

These represent internal summaries or plans generated by the model as it reasons through sub-questions.

[ ]

Web Search Call

These show what search queries were executed and can help you trace what information the model retrieved.

[ ]

Code Execution

If the model used the code interpreter (e.g. for parsing data or generating charts), those steps will appear as type "code_interpreter_call" or similar.

[ ]

Model Context Protocol (MCP)

Suppose you would like to pull in your own internal documents as part of a Deep Research task. The Deep Research models and the Responses API both support MCP-based tools, so you can extend them to query your private knowledge stores or other 3rd party services.

In the example below, we configure an MCP tool that lets Deep Research fetch your organizations internal semaglutide studies on demand. The MCP server is a proxy for the OpenAI File Storage service that automagically vectorizes your uploaded files for performant retrieval.

If you would like to see how we built this simple MCP server, refer to this related cookbook.

[ ]

Reviewing your response

First 100 characters of your Research Report, followed by Citations and MCP tool calls.

[ ]

Clarifying Questions in ChatGPT vs. the Deep Research API

If you’ve used Deep Research in ChatGPT, you may have noticed that it often asks follow-up questions after you submit a query. This is intentional: ChatGPT uses an intermediate model (like gpt-4.1) to help clarify your intent and gather more context (such as your preferences, goals, or constraints) before the research process begins. This extra step helps the system tailor its web searches and return more relevant and targeted results.

In contrast, the Deep Research API skips this clarification step. As a developer, you can configure this processing step to rewrite the user prompt or ask a set of clarifying questions, since the model expects fully-formed prompts up front and will not ask for additional context or fill in missing information; it simply starts researching based on the input it receives.

To get strong, reliable outputs from the API, you can use two approaches.

  • Use a prompt rewriter using another lightweight model (e.g., gpt-4.1) to expand or specify user queries before passing them to the research model.
  • Include all relevant details: desired scope, comparisons, metrics, regions, preferred sources, and expected output format.

This setup gives developers full control over how research tasks are framed, but also places greater responsibility on the quality of the input prompt. Here's an example of a generic rewriting_prompt to better direct the subsequent deep research query.

../../images/intro_dr.png

Here's an example of a rewriting prompt:

[ ]
[ ]
[ ]

In this instance, a user submitted a generic or open-ended query without specifying key details like travel dates, destination preferences, budget, interests, or travel companions; the rewriting prompt rewrote the query so Deep Research will attempt to generate a broad and inclusive response that anticipates common use cases.

While this behavior can be helpful in surfacing a wide range of options, it often leads to verbosity, higher latency, and increased token usage, as the model must account for many possible scenarios. This is especially true for queries that trigger complex planning or synthesis tasks (e.g. multi-destination travel itineraries, comparative research, product selection).

Instead of proceeding immediately with a broad research plan, let's trying using a lighter weight model to gently ask clarification questions from the user before generating a full answer and then using the rewriting prompt for clearer output for the model.

[ ]
[ ]
[ ]
[ ]

And there you have it! A deep research report crafted for your upcoming trip to France!

In this notebook, we explored how to use the Deep Research API to automate complex, real-world research tasks, from analyzing the economic impact of semaglutide to planning a trip to France that works for you. Deep Research shines when you need structured, citation-backed answers grounded in real-world evidence. Some standout use cases include:

  • Product comparisons and market analyses
  • Competitive intelligence and strategy reports
  • Technical literature reviews and policy synthesis

Whether you're looking to build research agents, generate structured reports, or integrate high-quality synthesis into your workflows, we hope the examples here help you get started.

What's next? Deep Research Agents