RunClient
Hierarchy
- ResourceClient
- RunClient
Index
Properties
inheritedapifyClient
inheritedbaseUrl
inheritedhttpClient
optionalinheritedid
optionalinheritedparams
inheritedpublicBaseUrl
Added in 2.17.0
inheritedresourcePath
optionalinheritedsafeId
inheritedurl
Methods
abort
Aborts the Actor run.
Parameters
options: RunAbortOptions = {}
Abort options
Returns Promise<Run>
The updated Run object with
ABORTINGorABORTEDstatus// Abort immediatelyawait client.run('run-id').abort();// Abort gracefully (allows cleanup)await client.run('run-id').abort({ gracefully: true });
charge
Charges the Actor run for a specific event.
Parameters
options: RunChargeOptions
Charge options including event name and count.
Returns Promise<ApifyResponse<Record<string, never>>>
Empty response object.
See more at https://docs.apify.com/api/v2/post-charge-run
Added in 2.11.0
dataset
Returns a client for the default dataset of this Actor run.
A 404 from this client throws an
ApifyApiError, since the run itself may be what is missing.Returns DatasetClient<Record<string | number, unknown>>
A client for accessing the run's default dataset
// Access run's datasetconst { items } = await client.run('run-id').dataset().listItems();See more at https://docs.apify.com/api/v2/actor-run-get
delete
Deletes the Actor run.
Parameters
options: TimeoutOptions = {}
Request options
Returns Promise<void>
See more at https://docs.apify.com/api/v2/actor-run-delete
Added in 2.8.1
get
Gets the Actor run object from the Apify API.
Parameters
options: RunGetOptions = {}
Get options
Returns Promise<undefined | Run>
The Run object, or
undefinedif it does not exist// Get run status immediatelyconst run = await client.run('run-id').get();console.log(`Status: ${run.status}`);// Wait up to 60 seconds for run to finishconst run = await client.run('run-id').get({ waitForFinish: 60 });See more at https://docs.apify.com/api/v2/actor-run-get
getStreamedLog
Get StreamedLog for convenient streaming of the run log and their redirection.
Parameters
options: GetStreamedLogOptions = {}
Streaming options
Returns Promise<undefined | StreamedLog>
Added in 2.20.0
iterateDatasetItems
Iterates over the items of the run's default dataset while the run is still producing them.
While the run has not finished, each poll yields the rows below the dataset's
itemCountand then waits up topollIntervalSecsfor the run to finish, so the last rows are read as soon as it does. Each page is requested with alimitthat ends atitemCount, so it covers exactly the rows it asks for, whatever the filters orunwinddo to the items.itemCountlags a few seconds behind the pushed items, so once the run reaches a terminal status, the rows past it are read a page at a time until none are left, and the iterator returns. On alastRun()client, the iterator sticks to the run that its first request resolves to.Parameters
options: RunIterateDatasetItemsOptions = {}
Iteration options
Returns AsyncGenerator<Data, void, undefined>
An async iterable of the dataset items
for await (const item of client.run('run-id').iterateDatasetItems()) {console.log(item);}See more at https://docs.apify.com/api/v2/dataset-items-get
keyValueStore
Returns a client for the default key-value store of this Actor run.
get()anddelete()throw anApifyApiErroron a 404, since the run itself may be what is missing. Record lookups such asgetRecord()read a 404 as a missing record.Returns KeyValueStoreClient
A client for accessing the run's default key-value store
// Access run's key-value storeconst output = await client.run('run-id').keyValueStore().getRecord('OUTPUT');See more at https://docs.apify.com/api/v2/actor-run-get
log
Returns a client for accessing the log of this Actor run.
A 404 from this client throws an
ApifyApiError, since the run itself may be what is missing.Returns LogClient
A client for accessing the run's log
// Get run logconst log = await client.run('run-id').log().get();console.log(log);See more at https://docs.apify.com/api/v2/actor-run-get
metamorph
Transforms the Actor run into a run of another Actor (metamorph).
This operation preserves the run ID, storages (dataset, key-value store, request queue), and resource allocation. The run effectively becomes a run of the target Actor with new input. This is useful for chaining Actor executions or implementing complex workflows.
Parameters
targetActorId: string
ID or username/name of the target Actor
optionalinput: ActorInput
Input for the target Actor: an object or array serialized to JSON, or raw bytes sent as they are. Omit it to metamorph without input.
options: RunMetamorphOptions = {}
Metamorph options
Returns Promise<Run>
The metamorphed Run object (same ID, but now running the target Actor)
// Transform current run into another Actorconst metamorphedRun = await client.run('original-run-id').metamorph('target-actor-id',{ url: 'https://example.com' });console.log(`Run ${metamorphedRun.id} is now running ${metamorphedRun.actId}`);
reboot
Reboots the Actor run.
Rebooting restarts the Actor's Docker container while preserving the run ID and storages. This can be useful to recover from certain errors or to force the Actor to restart with a fresh environment.
Parameters
options: TimeoutOptions = {}
Request options
Returns Promise<Run>
The updated Run object
const run = await client.run('run-id').reboot();Added in 2.8.0
requestQueue
Returns a client for the default Request queue of this Actor run.
get()anddelete()throw anApifyApiErroron a 404, since the run itself may be what is missing.getRequest()reads a 404 as a missing request.Returns RequestQueueClient
A client for accessing the run's default Request queue
// Access run's Request queueconst { items } = await client.run('run-id').requestQueue().listHead();See more at https://docs.apify.com/api/v2/actor-run-get
resurrect
Resurrects a finished Actor run, starting it again with the same settings.
This creates a new run with the same configuration as the original run. The original run's storages (dataset, key-value store, request queue) are preserved and reused.
Parameters
options: RunResurrectOptions = {}
Resurrection options (override original run settings)
Returns Promise<Run>
The new (resurrected) Run object
// Resurrect a failed run with more memoryconst newRun = await client.run('failed-run-id').resurrect({ memory: 2048 });console.log(`New run started: ${newRun.id}`);See more at https://docs.apify.com/api/v2/post-resurrect-run
update
Updates the Actor run with specified fields.
Parameters
newFields: RunUpdateOptions
Fields to update
options: TimeoutOptions = {}
Request options
Returns Promise<Run>
The updated Run object
// Set a status messageawait client.run('run-id').update({statusMessage: 'Processing items: 50/100'});Added in 2.6.0
waitForFinish
Waits for the Actor run to finish and returns the finished Run object.
The promise resolves when the run reaches a terminal state (
SUCCEEDED,FAILED,ABORTED, orTIMED-OUT). IfwaitSecsis provided and the timeout is reached, the promise resolves with the unfinished Run object (status will beRUNNINGorREADY). The promise is NOT rejected based on run status.Unlike the
waitForFinishparameter in get, this method can wait indefinitely by polling the run status. It uses thewaitForFinishparameter internally (max 60s per call) and continuously polls until the run finishes or the timeout is reached. Rejects with a NotFoundError if the run keeps returning 404 for 3 seconds.Parameters
options: RunWaitForFinishOptions = {}
Wait options
Returns Promise<Run>
The Run object (finished or still running if the timeout was reached)
// Wait indefinitely for run to finishconst run = await client.run('run-id').waitForFinish();console.log(`Run finished with status: ${run.status}`);// Wait up to 5 minutesconst run = await client.run('run-id').waitForFinish({ waitSecs: 300 });if (run.status === 'SUCCEEDED') {console.log('Run succeeded!');}
Client for managing a specific Actor run.
Provides methods to get run details, abort, metamorph, resurrect, wait for completion, and access the run's dataset, key-value store, request queue, and logs.