Skip to main content

Overview

When using the Tavily Research API, you can stream responses in real-time by setting stream: true in your request. This allows you to receive research progress updates, tool calls, and final results as they’re generated, providing a better user experience for long-running research tasks. Streaming is particularly useful for:
  • Displaying research progress to users in real-time
  • Monitoring tool calls and search queries as they execute
  • Receiving incremental updates during lengthy research operations
  • Building interactive research interfaces

Enabling Streaming

To enable streaming, set the stream parameter to true when making a request to the Research endpoint:
The API will respond with a text/event-stream content type, sending Server-Sent Events (SSE) as the research progresses.

Event Structure

Each streaming event follows a consistent structure compatible with the OpenAI chat completions format:

Core Fields

Event Types

The streaming response includes different types of events in the delta object. Here are the main event types you’ll encounter:

1. Tool Call Events

When the research agent performs actions like web searches, you’ll receive tool call events:
Tool Call Delta Fields:

2. Tool Response Events

After a tool executes, you’ll receive response events with discovered sources:
Tool Response Fields:

3. Content Events

The final research report is streamed as content chunks:
Content Field:
  • Can be a string (markdown-formatted report chunks) when no output_schema is provided
  • Can be an object (structured data) when an output_schema is specified

4. Sources Event

After the content is streamed, a sources event is emitted containing all sources used in the research:
Source Object Fields:

5. Done Event

Signals the completion of the streaming response:

Tool Types

During research, you’ll encounter the following tool types in streaming events:

Research Flow Example

A typical streaming session follows this sequence:
  1. Planning tool_call → Initializing research plan
  2. Planning tool_response → Research plan initialized
  3. WebSearch tool_call → Executing search queries (with queries array)
  4. WebSearch tool_response → Search completed (with sources array)
  5. (Pro mode) ResearchSubtopic tool_call/response cycles for deeper research
  6. Generating tool_call → Generating final report
  7. Generating tool_response → Report generated
  8. Content events → Streamed report chunks
  9. Sources event → Complete list of all sources used
  10. Done event → Stream complete

Handling Streaming Responses

Python Example

JavaScript Example

Structured Output with Streaming

When using output_schema to request structured data, the content field will contain an object instead of a string:

Error Handling

If an error occurs during streaming, you may receive an error event:
Always implement proper error handling in your streaming client to gracefully handle these cases.

Non-Streaming Alternative

If you don’t need real-time updates, set stream: false (or omit the parameter) to receive a single complete response:
You can then poll the status endpoint to check when the research is complete.