Overview
When using the Tavily Research API, you can stream responses in real-time by settingstream: 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 thestream parameter to true when making a request to the Research endpoint:
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
| Field | Type | Description |
|---|---|---|
id | string | Unique identifier for the stream event |
object | string | Always "chat.completion.chunk" for streaming events |
model | string | The research model being used ("mini" or "pro") |
created | integer | Unix timestamp when the event was created |
choices | array | Array containing the delta with event details |
Event Types
The streaming response includes different types of events in thedelta 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:| Field | Type | Description |
|---|---|---|
type | string | Either "tool_call" or "tool_response" |
tool_call | array | Details about the tool being invoked |
name | string | Name of the tool (see Tool Types below) |
id | string | Unique identifier for the tool call |
arguments | string | Description of the action being performed |
queries | array | (WebSearch only) The search queries being executed |
parent_tool_call_id | string | (Pro mode only) ID of the parent tool call for nested operations |
2. Tool Response Events
After a tool executes, you’ll receive response events with discovered sources:| Field | Type | Description |
|---|---|---|
name | string | Name of the tool that completed |
id | string | Unique identifier matching the original tool call |
arguments | string | Completion status message |
sources | array | Sources discovered by the tool (with url, title, favicon) |
parent_tool_call_id | string | (Pro mode only) ID of the parent tool call |
3. Content Events
The final research report is streamed as content chunks:- Can be a string (markdown-formatted report chunks) when no
output_schemais provided - Can be an object (structured data) when an
output_schemais specified
4. Sources Event
After the content is streamed, a sources event is emitted containing all sources used in the research:| Field | Type | Description |
|---|---|---|
url | string | The URL of the source |
title | string | The title of the source page |
favicon | string | URL to the source’s favicon |
5. Done Event
Signals the completion of the streaming response:Tool Types
During research, you’ll encounter the following tool types in streaming events:| Tool Name | Description | Model |
|---|---|---|
Planning | Initializes the research plan based on the input query | Both |
Generating | Generates the final research report from collected information | Both |
WebSearch | Executes web searches to gather information | Both |
ResearchSubtopic | Conducts deep research on specific subtopics | Pro only |
Research Flow Example
A typical streaming session follows this sequence:- Planning tool_call → Initializing research plan
- Planning tool_response → Research plan initialized
- WebSearch tool_call → Executing search queries (with
queriesarray) - WebSearch tool_response → Search completed (with
sourcesarray) - (Pro mode) ResearchSubtopic tool_call/response cycles for deeper research
- Generating tool_call → Generating final report
- Generating tool_response → Report generated
- Content events → Streamed report chunks
- Sources event → Complete list of all sources used
- Done event → Stream complete
Handling Streaming Responses
Python Example
JavaScript Example
Structured Output with Streaming
When usingoutput_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:Non-Streaming Alternative
If you don’t need real-time updates, setstream: false (or omit the parameter) to receive a single complete response: