Skip to main content
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 Python SDK method reference.

Basic Usage

from valyu import Valyu

valyu = Valyu()

# Create a research task
task = valyu.deepresearch.create(
    query="What are the key differences between RAG and fine-tuning for LLMs?",
    mode="standard"
)

if task.success:
    print(f"Task created: {task.deepresearch_id}")
    
    # Wait for completion with progress updates
    result = valyu.deepresearch.wait(
        task.deepresearch_id,
        on_progress=lambda s: print(f"Status: {s.status}")
    )
    
    if result.status == "completed":
        print(result.output)
        print(f"Cost: ${result.cost}")

Research Modes

DeepResearch offers three modes optimized for different use cases:
ModeBest ForTypical Completion Time
fastQuick answers, lightweight research, simple lookups~5 minutes
standardBalanced research, deeper insights without long wait times~10-20 minutes
heavyIn-depth, long-running research tasks, complex analysisUp to ~90 minutes
The lite mode has been replaced by fast.
# Use fast mode for quick lookups
task = valyu.deepresearch.create(
    query="What is quantum computing?",
    mode="fast"
)

# Use heavy mode for complex research
task = valyu.deepresearch.create(
    query="Analyze the competitive landscape of cloud computing in 2024",
    mode="heavy"
)

Parameters

Query (Required)

ParameterTypeDescription
querystrResearch query or task description

Options (Optional)

ParameterTypeDescriptionDefault
mode"fast" | "standard" | "heavy"Research mode. For lite mode, use fast instead."standard"
brand_collection_idstrBrand collection ID to apply to deliverablesNone
output_formatslistOutput formats (see below)["markdown"]
strategystrNatural language strategy instructionsNone
searchdictSearch configuration (filters, date range)None
urlslist[str]URLs to analyze (max 10)None
fileslist[dict]File attachments (max 10)None
deliverableslist[str | Deliverable]Additional file outputs to generate (max 10)None
mcp_serverslist[dict]MCP server configurations (max 5)None
code_executionboolEnable code executionTrue
previous_reportslist[str]Previous task IDs for context (max 3)None
webhook_urlstrHTTPS URL for completion notificationNone
metadatadictCustom metadata for trackingNone

Output Formats

Markdown (Default)

task = valyu.deepresearch.create(
    query="Explain quantum computing advancements in 2024",
    output_formats=["markdown"]
)

Markdown + PDF

Request both markdown and a downloadable PDF report:
task = valyu.deepresearch.create(
    query="Write a report on renewable energy trends",
    output_formats=["markdown", "pdf"]
)

result = valyu.deepresearch.wait(task.deepresearch_id)

if result.pdf_url:
    print(f"PDF available at: {result.pdf_url}")

Structured JSON

Get research results in a custom schema using JSON Schema specification:
task = valyu.deepresearch.create(
    query="Research competitor pricing in the SaaS market",
    output_formats=[{
        "type": "object",
        "properties": {
            "competitors": {
                "type": "array",
                "items": {
                    "type": "object",
                    "properties": {
                        "name": {"type": "string"},
                        "pricing_model": {"type": "string"},
                        "price_range": {"type": "string"},
                        "key_features": {
                            "type": "array",
                            "items": {"type": "string"}
                        }
                    },
                    "required": ["name", "pricing_model"]
                }
            },
            "market_summary": {"type": "string"},
            "recommendations": {
                "type": "array",
                "items": {"type": "string"}
            }
        },
        "required": ["competitors", "market_summary"]
    }]
)

result = valyu.deepresearch.wait(task.deepresearch_id)

if result.output_type == "json":
    data = result.output
    for competitor in data["competitors"]:
        print(f"{competitor['name']}: {competitor['pricing_model']}")

TOON Format

Get research results in TOON format for structured, machine-readable deliverables. TOON format requires a JSON schema and cannot be mixed with markdown/pdf.
task = valyu.deepresearch.create(
    query="Research competitor pricing in the SaaS market",
    output_formats=[{
        "type": "object",
        "properties": {
            "competitors": {
                "type": "array",
                "items": {
                    "type": "object",
                    "properties": {
                        "name": {"type": "string"},
                        "pricing_model": {"type": "string"}
                    }
                }
            }
        },
        "required": ["competitors"]
    }]
)
You cannot mix JSON Schema with markdown/pdf formats. Use one or the other. TOON format requires a JSON schema.
The schema must be a valid JSON Schema. Use type, properties, required, items, and other standard JSON Schema keywords.

Search Configuration

The search parameter controls which data sources are queried. See the DeepResearch Guide for complete documentation of all search options.
task = valyu.deepresearch.create(
    query="Research AI trends",
    search={
        "search_type": "proprietary",
        "included_sources": ["academic", "finance"],
        "start_date": "2024-01-01",
        "end_date": "2024-12-31",
        "country_code": "US"  # Filter web results by country
    }
)

Search Parameters

ParameterTypeDescription
search_type"all" | "web" | "proprietary"Which search systems to query
included_sourceslist[str]Only search these source types
excluded_sourceslist[str]Exclude these source types
start_datestrISO date (YYYY-MM-DD) for minimum date
end_datestrISO date (YYYY-MM-DD) for maximum date
categorystrFilter by category (source-dependent)
country_codestrISO 3166-1 alpha-2 code (e.g., "US", "GB") for location-filtered web searches
Available source types: web, academic, finance, patent, transportation, politics, legal

File Attachments

Analyze documents as part of research:
import base64

# Read and encode a PDF
with open("report.pdf", "rb") as f:
    pdf_data = base64.b64encode(f.read()).decode()

task = valyu.deepresearch.create(
    query="Summarize the key findings and compare with market trends",
    model="heavy",
    files=[{
        "data": f"data:application/pdf;base64,{pdf_data}",
        "filename": "report.pdf",
        "mediaType": "application/pdf",
        "context": "Q4 2024 financial report"  # Optional context
    }]
)
Supported file types: PDFs, images (PNG, JPEG, WebP), and documents.

Deliverables

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.

Simple Deliverables

Use simple strings to describe what you need:
task = 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"
    ]
)

result = valyu.deepresearch.wait(task.deepresearch_id)

if result.deliverables:
    for deliverable in result.deliverables:
        if deliverable.status == "completed":
            print(f"✅ {deliverable.title}")
            print(f"   Download: {deliverable.url}")
            if deliverable.row_count:
                print(f"   Rows: {deliverable.row_count}")

Structured Deliverables

Use the Deliverable type for precise control:
from valyu import Deliverable

task = valyu.deepresearch.create(
    query="Analyze startup funding trends in 2024",
    deliverables=[
        Deliverable(
            type="xlsx",
            description="Startup funding data with company details",
            columns=["Company", "Funding Amount", "Date", "Investors", "Stage"],
            include_headers=True,
            sheet_name="Funding Data"
        ),
        Deliverable(
            type="pptx",
            description="Executive summary presentation",
            slides=10,
            template="modern"
        ),
        Deliverable(
            type="pdf",
            description="Detailed analysis report with charts and insights"
        )
    ]
)

result = valyu.deepresearch.wait(task.deepresearch_id)

# Access deliverables
for deliverable in result.deliverables:
    print(f"{deliverable.type.upper()}: {deliverable.title}")
    print(f"Status: {deliverable.status}")
    if deliverable.status == "completed":
        print(f"Download: {deliverable.url}")
    elif deliverable.status == "failed":
        print(f"Error: {deliverable.error}")

Deliverable Types

TypeDescriptionOptional Fields
csvComma-separated valuescolumns, include_headers
xlsxExcel spreadsheetcolumns, include_headers, sheet_name
pptxPowerPoint presentationslides, template
docxWord documenttemplate
pdfPDF documenttemplate

Deliverable Response

class DeliverableResult:
    id: str
    request: str  # Original description
    type: str  # "csv" | "xlsx" | "pptx" | "docx" | "pdf"
    status: str  # "completed" | "failed"
    title: str  # Generated filename
    url: str  # Download URL (token-signed, expires)
    s3_key: str
    row_count: int | None  # For CSV/Excel
    column_count: int | None  # For CSV/Excel
    error: str | None  # If failed
    created_at: str  # ISO 8601 timestamp string
You can request up to 10 deliverables per research task. Deliverables are generated after the research completes.

URL Extraction

Include specific URLs to analyze alongside web research:
task = valyu.deepresearch.create(
    query="Compare the approaches described in these articles",
    urls=[
        "https://example.com/article-1",
        "https://example.com/article-2"
    ]
)

Waiting for Completion

Basic Wait

result = valyu.deepresearch.wait(task.deepresearch_id)

if result.status == "completed":
    print(result.output)

With Progress Callback

Track research progress in real-time:
def on_progress(status):
    if status.progress:
        pct = (status.progress.current_step / status.progress.total_steps) * 100
        print(f"Progress: {pct:.0f}% - Step {status.progress.current_step}/{status.progress.total_steps}")
    print(f"Status: {status.status}")

result = valyu.deepresearch.wait(
    task.deepresearch_id,
    poll_interval=5,      # Check every 5 seconds
    max_wait_time=900,    # Timeout after 15 minutes (standard mode)
    on_progress=on_progress
)

Polling Parameters

ParameterTypeDescriptionDefault
poll_intervalintSeconds between status checks5
max_wait_timeintMaximum wait time in seconds3600
on_progressCallableCallback for progress updatesNone

Response Format

class DeepResearchStatusResponse:
    success: bool
    deepresearch_id: str
    status: str  # "queued" | "running" | "completed" | "failed" | "cancelled"
    query: str
    mode: str  # "fast" | "standard" | "heavy"
    output_type: str  # "markdown" | "json" | "toon"
    output: str | dict  # Research output
    sources: list[DeepResearchSource]  # Sources used
    cost: float  # Fixed cost for the task
    created_at: str  # ISO 8601 timestamp string
    completed_at: str | None  # ISO 8601 timestamp string
    pdf_url: str | None  # PDF download URL
    images: list[ImageMetadata]  # Generated images
    deliverables: list[DeliverableResult]  # Generated deliverable files
    batch_id: str | None  # Batch ID if task belongs to a batch
    batch_task_id: str | None  # Batch task identifier if task belongs to a batch
    error: str | None  # Error message if failed

Source Object

class DeepResearchSource:
    title: str
    url: str
    snippet: str
    source: str  # web, pubmed, arxiv, etc.
    word_count: int
    doi: str | None  # For academic papers

Cost

The cost field contains the fixed price for the research task based on the mode:
  • fast: $0.10
  • standard: $0.50
  • heavy: $1.50

Task Management

Check Status

status = valyu.deepresearch.status(task_id)

print(f"Status: {status.status}")
if status.progress:
    print(f"Step {status.progress.current_step}/{status.progress.total_steps}")

Get Assets

Retrieve authenticated assets (images, charts, deliverables, PDFs) from completed tasks. Supports both API key authentication (default) and token-based authentication.
# Using API key (default)
asset_data = valyu.deepresearch.get_assets(task_id, asset_id)

if asset_data:
    # asset_data is bytes containing the binary data
    with open("output.png", "wb") as f:
        f.write(asset_data)

# Using token
asset_data = valyu.deepresearch.get_assets(
    task_id,
    asset_id,
    token="asset-access-token"
)
Returns: bytes - Binary asset data, or None if the asset is not found.

Add Follow-up Instructions

Add instructions to refine or adjust the scope of a running task to guide the research and report generation process.
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 instruction
response = valyu.deepresearch.update(
    task_id,
    instruction="Focus more on peer-reviewed sources from 2024"
)

if response.success:
    print("Instruction added")

# Add another instruction
response = valyu.deepresearch.update(
    task_id,
    instruction="Include a comparison table of major providers"
)

Cancel a Task

response = valyu.deepresearch.cancel(task_id)

if response.success:
    print("Task cancelled")

Delete a Task

response = valyu.deepresearch.delete(task_id)

if response.success:
    print("Task deleted")

List All Tasks

tasks = valyu.deepresearch.list(
    api_key_id="your-api-key-id",
    limit=50
)

for task in tasks.data:
    print(f"{task['query'][:50]}... - {task['status']}")

Webhooks

Get notified when research completes instead of polling. See the DeepResearch Guide for complete webhook documentation including signature verification and retry behavior.
task = valyu.deepresearch.create(
    query="Research market trends in AI",
    webhook_url="https://your-app.com/webhooks/deepresearch"
)

# IMPORTANT: Save the secret immediately - it's only returned once
webhook_secret = task.webhook_secret
The webhook_secret is only returned once. Store it securely—you cannot retrieve it later.

Error Handling

task = valyu.deepresearch.create(query="Research query")

if not task.success:
    print(f"Failed to create task: {task.error}")
    return

try:
    result = valyu.deepresearch.wait(
        task.deepresearch_id,
        max_wait_time=1800  # 30 minutes for standard, use 7200 for heavy
    )
    
    if result.status == "completed":
        print(result.output)
    elif result.status == "failed":
        print(f"Research failed: {result.error}")
        
except TimeoutError:
    print("Task timed out - cancelling")
    valyu.deepresearch.cancel(task.deepresearch_id)
    
except ValueError as e:
    print(f"Task error: {e}")

Best Practices

See the DeepResearch Guide for comprehensive best practices including polling strategies, timeouts, and research quality tips.
ModeRecommended Poll IntervalRecommended Timeout
fast2-5 seconds10 minutes
standard5-10 seconds30 minutes
heavy10-30 seconds120 minutes
# Production: use webhooks instead of polling
task = valyu.deepresearch.create(
    query="Research query",
    webhook_url="https://your-app.com/webhooks"
)

See Also