Adds one or more tasks to an existing batch. You can call this multiple times to add tasks incrementally.Constraints:
Maximum tasks per request: 100
Minimum tasks per request: 1
Batch must be in "open" or "processing" status
Parameters:
interface AddBatchTasksOptions { tasks: BatchTaskInput[]; // Array of 1-100 tasks}interface BatchTaskInput { id?: string; // Optional custom task identifier (for tracking) query: string; // Research query or task description (required) strategy?: string; // Deprecated: use researchStrategy instead researchStrategy?: string; // Natural language strategy to guide the research phase reportFormat?: string; // Natural language instructions for output format (highest priority) urls?: string[]; // Array of URLs to extract content from metadata?: Record<string, string | number | boolean>; // Custom metadata}
Tasks inherit mode, outputFormats, and search from the batch and cannot override them.Response:
interface AddBatchTasksResponse { success: boolean; batch_id?: string; // Batch ID added?: number; // Number of tasks successfully added tasks?: BatchTaskCreated[]; // Array of created task objects counts?: BatchCounts; // Updated task counts for the batch error?: string;}interface BatchTaskCreated { task_id?: string; // User-provided task identifier (if specified) deepresearch_id: string; // DeepResearch task ID status: string; // Task status}
Example:
const addResult = await client.batch.addTasks(batchId, { tasks: [ { query: "What are the latest developments in quantum computing?" }, { query: "Analyze the impact of AI on healthcare in 2024" }, { query: "Compare renewable energy trends across Europe", urls: ["https://example.com/report.pdf"] } ] }); if (addResult.success) { console.log(`Added ${addResult.added} tasks`); }
Lists all tasks in a batch with their individual statuses. Pass includeOutput: true to get full output, sources, images, and cost for each task.Parameters:
interface ListBatchTasksOptions { status?: string; // Filter: "completed", "failed", "cancelled", "running", "queued" limit?: number; // Results per page (default: 25, max: 50) lastKey?: string; // Pagination cursor from previous response includeOutput?: boolean; // Include full output, sources, images, and cost (default: false)}
Response:
interface ListBatchTasksResponse { success: boolean; batch_id?: string; // Batch ID tasks?: BatchTaskListItem[]; pagination?: BatchPagination; // Pagination information error?: string;}interface BatchPagination { count: number; // Number of tasks returned in this response last_key?: string; // Pagination key for fetching next page (if has_more is true) has_more: boolean; // Whether there are more tasks to fetch}interface BatchTaskListItem { task_id?: string; // User-provided task identifier deepresearch_id: string; // Task ID (use with deepresearch.status()) query: string; // The research query status: DeepResearchStatus; // Task status created_at: string; // ISO 8601 timestamp string completed_at?: string; // ISO 8601 timestamp string // Additional fields when includeOutput is true: output_type?: string; // "markdown", "pdf", "toon", "structured" output?: string; // Full research output sources?: Source[]; // Cited sources images?: string[]; // Image URLs pdf_url?: string; // PDF download URL deliverables?: any; // Deliverable outputs error?: string; // Error message (failed tasks) cost?: number; // Task cost in dollars}
By default, includeOutput is false, returning a lightweight listing with task status only. Set includeOutput: true when you need the full output, sources, images, and cost for each task.
Waits for a batch to complete by polling its status at regular intervals. This is useful for long-running batches where you want to be notified when all tasks finish.Parameters:
interface BatchWaitOptions { pollInterval?: number; // Polling interval in ms (default: 10000) maxWaitTime?: number; // Maximum wait time in ms (default: 7200000 = 2 hours) onProgress?: (batch: DeepResearchBatch) => void; // Progress callback}
Response:Returns the final DeepResearchBatch object when the batch reaches a terminal state (completed, completed_with_errors, or cancelled).Example:
Individual tasks in a batch are DeepResearch tasks. You can use the standard DeepResearch methods:
// Get detailed task resultconst result = await client.deepresearch.status(task.deepresearch_id);// Update a running taskawait client.deepresearch.update(task.deepresearch_id, "Focus on recent data");// Cancel an individual taskawait client.deepresearch.cancel(task.deepresearch_id);