This function subscribes to all changes for runs in a batch. It returns an async iterator that yields the a run object whenever a run in the batch is updated. The iterator does not complete on it’s own, you must manually break the loop when you want to stop listening for updates.

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:batch:<batchId>
  • read:runs will provide access to all runs (not recommended for production use)

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: {
      batch: ["batch_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.