Asynchronous deep research using the Valyu TypeScript SDK
The DeepResearch API performs comprehensive research by searching multiple sources, analyzing content, and generating detailed reports. Tasks run in the background, enabling thorough multi-step research.
For conceptual overview, search configuration details, and best practices, see the DeepResearch Guide. This page focuses on TypeScript SDK method reference.
import { Valyu } from "valyu-js";const valyu = new Valyu();// Create a research taskconst task = await valyu.deepresearch.create({ query: "What are the key differences between RAG and fine-tuning for LLMs?", mode: "standard"});if (task.success) { console.log(`Task created: ${task.deepresearch_id}`); // Wait for completion with progress updates const result = await valyu.deepresearch.wait(task.deepresearch_id, { onProgress: (s) => console.log(`Status: ${s.status}`) }); if (result.status === "completed") { console.log(result.output); console.log(`Cost: $${result.cost}`); }}
Balanced research, deeper insights without long wait times
~10-20 minutes
heavy
In-depth, long-running research tasks, complex analysis
Up to ~90 minutes
max
Exhaustive research with maximum quality and fact verification
Up to ~180 minutes
The lite mode is deprecated and maps to standard.
// Use fast mode for quick lookupsconst task = await valyu.deepresearch.create({ query: "What is quantum computing?", mode: "fast"});// Use heavy mode for complex researchconst task = await valyu.deepresearch.create({ query: "Analyze the competitive landscape of cloud computing in 2024", mode: "heavy"});// Use max mode for exhaustive researchconst task = await valyu.deepresearch.create({ query: "Comprehensive analysis of AI safety research with fact verification", mode: "max"});
Get research results in TOON format for structured, machine-readable deliverables. TOON format requires a JSON schema and cannot be mixed with markdown/pdf.
The tools parameter controls which optional capabilities the research agent can use during a task. All tools are off by default and must be explicitly enabled.
Tool
Description
code_execution
Run Python code in a sandboxed environment. Required for XLSX/PPTX/DOCX deliverable generation.
screenshots
Capture visual screenshots of web pages. The agent decides when screenshots add value (charts, dashboards, infographics).
You enable tools — the agent decides when to use them. For example, enabling screenshots does not screenshot every page; the agent selects pages where visual context is valuable.
Generate additional file outputs alongside the research report. Deliverables allow you to extract structured data or create formatted documents (CSV, Excel, PowerPoint, Word, PDF) from the research.
const task = await valyu.deepresearch.create({ query: "Research the top 20 AI companies in 2024", deliverables: [ "CSV file with company names, founding year, and funding", "PowerPoint presentation with 5 slides summarizing key findings" ]});const result = await valyu.deepresearch.wait(task.deepresearch_id);if (result.deliverables) { for (const deliverable of result.deliverables) { if (deliverable.status === "completed") { console.log(`✅ ${deliverable.title}`); console.log(` Download: ${deliverable.url}`); if (deliverable.row_count) { console.log(` Rows: ${deliverable.row_count}`); } } }}
Include specific URLs to analyze alongside web research:
const task = await valyu.deepresearch.create({ query: "Compare the approaches described in these articles", urls: [ "https://example.com/article-1", "https://example.com/article-2" ]});
Retrieve authenticated assets (images, charts, deliverables, PDFs) from completed tasks. Supports both API key authentication (default) and token-based authentication.
// Using API key (default)const asset = await valyu.deepresearch.getAssets(taskId, assetId);if (asset.success && asset.data) { // asset.data is a Buffer containing the binary data // asset.contentType contains the MIME type (e.g., "image/png", "application/pdf") fs.writeFileSync("output.png", asset.data);}// Using tokenconst asset = await valyu.deepresearch.getAssets(taskId, assetId, { token: "asset-access-token"});
Add instructions to refine or adjust the scope of a running task. Instructions are collected during the research phase and incorporated when report generation begins.
Follow-up instructions can only be added before the writing phase starts. Once research completes and the writing phase begins, new instructions are rejected.
// Add first instructionconst response = await valyu.deepresearch.update( taskId, "Focus more on peer-reviewed sources from 2024");if (response.success) { console.log("Instruction added");}// Add another instructionawait valyu.deepresearch.update( taskId, "Include a comparison table of major providers");
Get notified when research completes instead of polling. See the DeepResearch Guide for complete webhook documentation including signature verification and retry behavior.
const task = await valyu.deepresearch.create({ query: "Research market trends in AI", webhookUrl: "https://your-app.com/webhooks/deepresearch"});// IMPORTANT: Save the secret immediately - it's only returned onceconst webhookSecret = task.webhook_secret;
The webhook_secret is only returned once. Store it securely—you cannot retrieve it later.