Skip to content
Get started
TypeScript

Jobs

API reference for the Job class and .wait() method.

Every endpoint that returns a job in its response is enhanced — the job object gains a .wait() method that polls until completion.

Polls client.jobs.retrieve() until the job reaches a terminal status.

Signature

job.wait(options?: WaitOptions): Promise<Job>

Parameters

Name Type Default Description
options.intervalMs number 3000 Polling interval in milliseconds.
options.timeoutMs number 120000 Maximum wait time in milliseconds. Throws if exceeded.
options.projectId? string Override the project scope for polling requests. Defaults to the scope captured on the originating call (per-call override or client default).

Returns

Promise<Job> — A new Job instance with the terminal state. The Job object contains all standard API job fields:

Property Type Description
jobId string The job ID.
status string Terminal status: 'success', 'failure', or 'canceled'.
progress number Progress between 0 and 1.
metadata object Job metadata, including flow and assetIds for workflow jobs.
createdAt string ISO 8601 creation timestamp.
updatedAt string ISO 8601 last update timestamp.
jobType string The type of job (e.g. 'workflow', 'inference').
wait() function Can be called again (returns immediately if already terminal).

Errors

Throws Error if the job does not reach a terminal status within timeoutMs.

try {
const completed = await response.job.wait({ timeoutMs: 10_000 });
} catch (err) {
// "Job job_... did not complete within 10s"
}
import Scenario from '@scenario-labs/sdk';
const client = new Scenario({ apiKey: '...' });
const response = await client.workflows.run('wflow_...', {
body: { prompt: 'a fantasy sword' },
});
const completed = await response.job.wait();
console.log(completed.status); // 'success'
console.log(completed.metadata); // { assetIds: [...], flow: [...] }

client.jobs.retrieve(jobID) — enhanced response

Section titled “client.jobs.retrieve(jobID) — enhanced response”

client.jobs.retrieve() returns a response where response.job has .wait().

const response = await client.jobs.retrieve('job_...');
const completed = await response.job.wait();
console.log(completed.status); // 'success' | 'failure' | 'canceled'

client.jobs.triggerAction(jobID, params) — enhanced response

Section titled “client.jobs.triggerAction(jobID, params) — enhanced response”

client.jobs.triggerAction() also returns a response where response.job has .wait().

const response = await client.jobs.triggerAction('job_...', { action: 'cancel' });
const completed = await response.job.wait();

Resource Methods
client.jobs retrieve(), triggerAction()
client.workflows run(), userApproval()
client.generate caption(), describeStyle(), detect(), embed(), patch(), runModel(), translate()
client.models.train trigger()