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.

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.