--- title: runs.subscribeToBatch sidebarTitle: subscribeToBatch description: Subscribes to all changes for runs in a batch. --- import RunObject from "/snippets/realtime/run-object.mdx"; ```ts Example import { runs } from "@trigger.dev/sdk/v3"; for await (const run of runs.subscribeToBatch("batch_1234")) { console.log(run); } ``` 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:` - `read:runs` will provide access to all runs (not recommended for production use) To generate a public access token, use the `auth.createPublicToken` function: ```ts 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: