import { runs } from "@trigger.dev/sdk/v3";

for await (const run of runs.subscribeToRun("run_1234")) {
  console.log(run);
}
import { runs } from "@trigger.dev/sdk/v3";

for await (const run of runs.subscribeToRun("run_1234")) {
  console.log(run);
}
This function subscribes to all changes to a run. It returns an async iterator that yields the run object whenever the run is updated. The iterator will complete when the run is finished.

Authentication

This function supports both server-side and client-side authentication. For server-side authentication, use your API key. For client-side authentication, you must generate a public access token with one of the following scopes:
  • read:runs
  • read:runs:<runId>
To generate a public access token, use the auth.createPublicToken function:
import { auth } from "@trigger.dev/sdk/v3";

// Somewhere in your backend code
const publicToken = await auth.createPublicToken({
  scopes: {
    read: {
      runs: ["run_1234"],
    },
  },
});

Response

The AsyncIterator yields an object with the following properties:
id
string
required
The run ID.
taskIdentifier
string
required
The task identifier.
payload
object
required
The input payload for the run.
output
object
The output result of the run.
createdAt
Date
required
Timestamp when the run was created.
updatedAt
Date
required
Timestamp when the run was last updated.
number
number
required
Sequential number assigned to the run.
status
RunStatus
required
Current status of the run.
StatusDescription
WAITING_FOR_DEPLOYTask hasn’t been deployed yet but is waiting to be executed
QUEUEDRun is waiting to be executed by a worker
EXECUTINGRun is currently being executed by a worker
REATTEMPTINGRun has failed and is waiting to be retried
FROZENRun has been paused by the system, and will be resumed by the system
COMPLETEDRun has been completed successfully
CANCELEDRun has been canceled by the user
FAILEDRun has been completed with errors
CRASHEDRun has crashed and won’t be retried, most likely the worker ran out of resources, e.g. memory or storage
INTERRUPTEDRun was interrupted during execution, mostly this happens in development environments
SYSTEM_FAILURERun has failed to complete, due to an error in the system
DELAYEDRun has been scheduled to run at a specific time
EXPIREDRun has expired and won’t be executed
TIMED_OUTRun has reached it’s maxDuration and has been stopped
durationMs
number
required
Duration of the run in milliseconds.
costInCents
number
required
Total cost of the run in cents.
baseCostInCents
number
required
Base cost of the run in cents before any additional charges.
tags
string[]
required
Array of tags associated with the run.
idempotencyKey
string
Key used to ensure idempotent execution.
expiredAt
Date
Timestamp when the run expired.
ttl
string
Time-to-live duration for the run.
finishedAt
Date
Timestamp when the run finished.
startedAt
Date
Timestamp when the run started.
delayedUntil
Date
Timestamp until which the run is delayed.
queuedAt
Date
Timestamp when the run was queued.
metadata
Record<string, DeserializedJson>
Additional metadata associated with the run.
error
SerializedError
Error information if the run failed.
isTest
boolean
required
Indicates whether this is a test run.