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
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:2. Tool Response Events
After a tool executes, you’ll receive response events with discovered sources: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: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:- 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: