The Deep Research API uses Server-Sent Events (SSE) over HTTP to stream real-time updates. To consume the API, establish a POST connection to the /api/sse endpoint and keep it open to receive a continuous stream of events. It is highly recommended to use the @microsoft/fetch-event-source library to handle the connection and event parsing.
import { fetchEventSource } from "@microsoft/fetch-event-source";
const ctrl = new AbortController();
fetchEventSource("/api/sse", {
method: "POST",
headers: {
"Content-Type": "application/json",
// Authorization: "Bearer YOUR_ACCESS_PASSWORD",
},
body: JSON.stringify({
query: "AI trends for this year",
provider: "google",
thinkingModel: "gemini-2.0-flash-thinking-exp",
taskModel: "gemini-2.0-flash-exp",
searchProvider: "model",
language: "en-US",
maxResult: 5,
enableCitationImage: true,
enableReferences: true,
promptOverrides: {
systemInstruction: "You are an expert researcher. Keep answers concise and evidence-driven.",
},
}),
signal: ctrl.signal,
onmessage(msg) {
const msgData = JSON.parse(msg.data);
// Handle events based on msg.event type
},
onclose() {
console.log("Stream closed");
},
});