Skip to main content
When you upload a document, FlexOrch returns a Job object immediately. The job moves through a processing pipeline — OCR, extraction, PII detection, and quality scoring — before reaching a terminal state. This page shows you how to track that lifecycle and act on the results in TypeScript.

Job states

StateMeaning
queuedDocument received; waiting for a processing slot.
runningPipeline is actively processing the document.
completedAll stages finished successfully.
failedPipeline encountered an unrecoverable error.

Get a job by ID

Retrieve a job you created earlier by passing its ID to client.jobs.get().
import { FlexOrch } from "@flexorch/sdk";

const client = new FlexOrch({
  apiKey: process.env.FLEXORCH_API_KEY,
});

const job = await client.jobs.get("job_abc123");
console.log(`Status: ${job.status}`);

Wait for completion

Call job.waitUntilDone() to await the job’s terminal state (completed or failed). The SDK polls automatically with exponential back-off — you do not need to write a polling loop yourself.
let job = await client.documents.upload("report.pdf");
job = await job.waitUntilDone();

if (job.status === "completed") {
  console.log("Processing finished.");
} else {
  console.error(`Job failed: ${job.processingSummary}`);
}
waitUntilDone() rejects with a JobTimeoutError if the job has not finished within the SDK’s default timeout (300 seconds). Pass { timeout: 600 } to extend it for large files.
import { JobTimeoutError } from "@flexorch/sdk";

try {
  job = await job.waitUntilDone({ timeout: 600 });
} catch (err) {
  if (err instanceof JobTimeoutError) {
    console.warn("Job is taking longer than expected — check the dashboard.");
  } else {
    throw err;
  }
}

Access extraction results

Once a job is completed, read quality and PII data directly from the job object.
console.log(`Quality grade:       ${job.qualityGrade}`);        // "A" | "B" | "C" | "D"
console.log(`Quality score:       ${job.qualityScore}`);         // 0.0 – 1.0
console.log(`PII findings:        ${job.piiFindingsCount}`);
console.log(`Privacy applied:     ${job.privacyApplied}`);       // true if redaction ran
console.log(`Processing summary:  ${job.processingSummary}`);

Quality grades at a glance

GradeScore rangeRecommendation
A0.90 – 1.00Ready for training or retrieval as-is.
B0.75 – 0.89Good quality; minor cleanup may help.
C0.50 – 0.74Review before including in datasets.
D0.00 – 0.49Low quality; consider re-scanning source.

List jobs

client.jobs.list() returns a Promise<Job[]> containing your most recent jobs, newest first.
const jobs = await client.jobs.list();

jobs.forEach((job) => {
  console.log(`${job.id}  ${job.status}  grade=${job.qualityGrade}`);
});
Use limit and offset for pagination:
const page1 = await client.jobs.list({ limit: 25, offset: 0 });
const page2 = await client.jobs.list({ limit: 25, offset: 25 });

Filter by quality grade

Standard array methods work well for filtering:
const allJobs = await client.jobs.list({ limit: 100 });

const highQuality = allJobs.filter(
  (j) => j.qualityGrade === "A" || j.qualityGrade === "B"
);

console.log(`High-quality jobs: ${highQuality.length}`);

Submit feedback

If an extraction result is wrong or a quality grade is inaccurate, submit feedback to help improve the model:
await client.jobs.submitFeedback({
  jobId: "job_abc123",
  rating: "negative",
  issue: "wrong_fields",
});
jobId
string
required
The unique identifier of the job.
rating
string
required
"positive" or "negative".
issue
string
A short issue code describing the problem. Common values: "wrong_fields", "missed_pii", "incorrect_summary", "poor_extraction".
Feedback is aggregated across your workspace. Consistent negative feedback on specific document types triggers a re-evaluation by the FlexOrch model team.

Next steps

Build Datasets

Turn completed jobs into structured, exportable datasets.

API Reference

Full parameter and return-type reference for all job methods.