Skip to main content
The SDK provides methods to retrieve job status, cancel jobs, and list jobs for async operations.

Retrieve Job Status

// Start an async job
const jobResponse = await client.parse.runJob({ input: upload.file_id });
const jobId = jobResponse.job_id;

// Retrieve job status
const job = await client.job.get(jobId);

// Check status
if (job.status === "Completed") {
  console.log("Job completed!");
  const result = job.result; // ParseResponse, ExtractResponse, etc.
  if (result && 'chunks' in result.result) {
    console.log(`Found ${result.result.chunks.length} chunks`);
  }
} else if (job.status === "Pending") {
  console.log("Job still processing...");
  console.log(`Progress: ${job.progress || 0}%`);
} else if (job.status === "Failed") {
  console.log(`Job failed: ${job.reason}`);
}

Polling for Completion

async function waitForJob(client, jobId) {
  while (true) {
    const job = await client.job.get(jobId);
    
    if (job.status === "Completed") {
      return job.result;
    } else if (job.status === "Failed") {
      throw new Error(`Job failed: ${job.reason}`);
    }
    
    console.log(`Status: ${job.status}, Progress: ${job.progress || 0}%`);
    await new Promise(resolve => setTimeout(resolve, 2000)); // Wait 2 seconds
  }
}

// Usage
const jobResponse = await client.parse.runJob({ input: upload.file_id });
const result = await waitForJob(client, jobResponse.job_id);

Cancel a Job

// Cancel a running job
await client.job.cancel(jobId);

List All Jobs

// Get all jobs with pagination
const response = await client.job.getAll({
  limit: 50,
  exclude_configs: true  // Exclude raw_config to reduce response size
});

for (const job of response.jobs) {
  console.log(`${job.job_id}: ${job.status} (${job.type})`);
}

// Get next page
if (response.next_cursor) {
  const nextPage = await client.job.getAll({
    cursor: response.next_cursor,
    limit: 50
  });
}

Next Steps