Skip to content

Commit 6910cd4

Browse files
isshaddadTrigger.dev RepoOps
authored andcommitted
docs: fix inaccuracies in management API guides
Corrects the management API guides where they had drifted from the SDK and API. - Authentication: examples and prose use `accessToken` (with `secretKey` noted as a deprecated alias), the documented key prefixes match what the dashboard issues, and personal access tokens are passed as `accessToken`. - Errors and retries: the SDK import is `ApiError`, the error body is `error.error`, and the retry defaults (5 attempts, 1 to 30 second backoff, which statuses retry) match the client. - Pagination, overview and multiple clients: fixes the `runs.list` example, the auto-pagination intro, environment names, and the `previewBranch` option. - Session channels: documents the `session-closed` and `pending-version` control records, the append response (`seq`, `pendingVersion`), the closed and expired session errors, and the stream format. - Batches: the error schema uses `error`, and the create-batch request documents `taskIdentifiers` and the 1,000 item cap. Fixes to endpoint reference pages generated from the main API spec will follow in a separate PR. Mono-RevId: 3fe0d3a3ef8937f32890b553d60708793aaa0adf
1 parent 414e5e0 commit 6910cd4

7 files changed

Lines changed: 41 additions & 47 deletions

File tree

‎docs/management/authentication.mdx‎

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,42 +4,42 @@ sidebarTitle: Authentication
44
description: Authenticating with the Trigger.dev management API
55
---
66

7-
There are two methods of authenticating with the management API: using a named API key associated with a specific environment in a project (`secretKey`), or using a personal access token (`personalAccessToken`). Use both methods only on a backend server. An environment API key's access is limited by the preset and task restrictions selected when you create it.
7+
There are two methods of authenticating with the management API: using a named API key associated with a specific environment in a project, or using a personal access token (PAT). Pass either one as the `accessToken` option (`secretKey` is a deprecated alias). Use both methods only on a backend server. An environment API key's access is limited by the preset and task restrictions selected when you create it.
88

99
<Note>
1010
There is a separate authentication strategy when making requests from your frontend application.
1111
See the [Realtime guide](/realtime/overview) for more information. This guide is for backend usage
1212
only.
1313
</Note>
1414

15-
Certain API functions work with both authentication methods, but require different arguments depending on the method used. For example, the `runs.list` function can be called using either a `secretKey` or a `personalAccessToken`, but the `projectRef` argument is required when using a `personalAccessToken`:
15+
Certain API functions work with both authentication methods, but require different arguments depending on the method used. For example, the `runs.list` function can be called using either an environment API key or a personal access token, but the `projectRef` argument is required when using a personal access token:
1616

1717
```ts
1818
import { configure, runs } from "@trigger.dev/sdk";
1919

20-
// Using secretKey authentication
20+
// Using accessToken authentication
2121
configure({
22-
secretKey: process.env["TRIGGER_SECRET_KEY"], // starts with tr_dev_sk_, tr_prod_sk_, or tr_preview_sk_
22+
accessToken: process.env["TRIGGER_SECRET_KEY"], // starts with tr_dev_, tr_stg_, tr_prod_, or tr_preview_ (named keys add sk_)
2323
});
2424

25-
function secretKeyExample() {
25+
function accessTokenExample() {
2626
return runs.list({
2727
limit: 10,
2828
status: ["COMPLETED"],
2929
});
3030
}
3131

32-
// Using personalAccessToken authentication
32+
// Using personal access token authentication
3333
configure({
34-
secretKey: process.env["TRIGGER_ACCESS_TOKEN"], // starts with tr_pat_
34+
accessToken: process.env["TRIGGER_ACCESS_TOKEN"], // starts with tr_pat_
3535
});
3636

3737
function personalAccessTokenExample() {
38-
// Notice the projectRef argument is required when using a personalAccessToken
39-
return runs.list("prof_1234", {
38+
// Notice the projectRef argument is required when using a personal access token
39+
return runs.list("proj_1234", {
4040
limit: 10,
4141
status: ["COMPLETED"],
42-
projectRef: "tr_proj_1234567890",
42+
env: "prod",
4343
});
4444
}
4545
```
@@ -73,7 +73,7 @@ function personalAccessTokenExample() {
7373

7474
### Environment API key
7575

76-
Create a named environment API key with the narrowest access preset that supports your integration. Pass it through the `secretKey` option or `TRIGGER_SECRET_KEY` environment variable. Read the [API Keys guide](/apikeys) for available presets and task restrictions.
76+
Create a named environment API key with the narrowest access preset that supports your integration. Pass it through the `accessToken` option or `TRIGGER_SECRET_KEY` environment variable. Read the [API Keys guide](/apikeys) for available presets and task restrictions.
7777

7878
### Personal Access Token (PAT)
7979

@@ -85,7 +85,7 @@ For example, when uploading environment variables using a PAT, you must provide
8585
import { configure, envvars } from "@trigger.dev/sdk";
8686

8787
configure({
88-
secretKey: process.env["TRIGGER_ACCESS_TOKEN"], // starts with tr_pat_
88+
accessToken: process.env["TRIGGER_ACCESS_TOKEN"], // starts with tr_pat_
8989
});
9090

9191
await envvars.upload("proj_1234", "dev", {
@@ -108,7 +108,7 @@ When working with preview branches, you may need to target a specific branch whe
108108
import { configure, envvars } from "@trigger.dev/sdk";
109109

110110
configure({
111-
secretKey: process.env["TRIGGER_ACCESS_TOKEN"], // starts with tr_pat_
111+
accessToken: process.env["TRIGGER_ACCESS_TOKEN"], // starts with tr_pat_
112112
previewBranch: "feature-xyz",
113113
});
114114

@@ -137,8 +137,7 @@ curl --request PUT \
137137
This will set the `DATABASE_URL` environment variable specifically for the `feature-xyz` preview branch.
138138

139139
<Note>
140-
The `x-trigger-branch` header is only relevant when working with the `preview` or `dev` environments (`{env}
141-
` parameter set to `preview` or `development`). It has no effect when working with `staging`, or `prod`
140+
The `x-trigger-branch` header is only relevant when working with the `preview` or `dev` environments (`{env}` parameter set to `preview` or `dev`). It has no effect when working with `staging`, or `prod`
142141
environments.
143142
</Note>
144143

@@ -150,7 +149,7 @@ When using the SDK to manage preview branch environment variables, the branch ta
150149
import { configure, envvars } from "@trigger.dev/sdk";
151150

152151
configure({
153-
secretKey: process.env["TRIGGER_ACCESS_TOKEN"], // starts with tr_pat_
152+
accessToken: process.env["TRIGGER_ACCESS_TOKEN"], // starts with tr_pat_
154153
previewBranch: "feature-xyz", // Optional: specify the branch
155154
});
156155

@@ -219,7 +218,7 @@ const publicToken = await auth.createPublicToken({
219218
});
220219
```
221220

222-
`sessions` accepts a single ID or an array. The default token TTL is 1 hour. One token authorizes **both** URL forms — pass either your `externalId` or the `session_…` ID in the path.
221+
`sessions` accepts a single ID or an array. When you mint the token with `auth.createPublicToken()`, the default TTL is 15 minutes (pass `expirationTime` to change it). Tokens returned by `sessions.start()` default to 1 hour. One token authorizes **both** URL forms — pass either your `externalId` or the `session_…` ID in the path.
223222

224223
The `publicAccessToken` returned by [`sessions.start()`](/management/sessions/create) already carries both scopes for the session it created, so you usually don't mint one by hand for the create flow.
225224

‎docs/management/auto-pagination.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ sidebarTitle: Auto-pagination
44
description: Using auto-pagination with the Trigger.dev management API
55
---
66

7-
All list endpoints in the management API support auto-pagination.
7+
Paginated list methods in the management API (`runs`, `schedules`, `queues`, `deployments`, and others) support auto-pagination.
88
You can use `for await … of` syntax to iterate through items across all pages:
99

1010
```ts

‎docs/management/errors-and-retries.mdx‎

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ description: Handling errors and retries with the Trigger.dev management API
99
When the SDK method is unable to connect to the API server, or the API server returns a non-successful response, the SDK will throw an `ApiError` that you can catch and handle:
1010

1111
```ts
12-
import { runs, APIError } from "@trigger.dev/sdk";
12+
import { runs, ApiError } from "@trigger.dev/sdk";
1313

1414
async function main() {
1515
try {
1616
const run = await runs.retrieve("run_1234");
1717
} catch (error) {
1818
if (error instanceof ApiError) {
19-
console.error(`API error: ${error.status}, ${error.headers}, ${error.body}`);
19+
console.error(`API error: ${error.status} ${error.message}`, error.error);
2020
} else {
2121
console.error(`Unknown error: ${error.message}`);
2222
}
@@ -26,7 +26,7 @@ async function main() {
2626

2727
## Retries
2828

29-
The SDK will automatically retry requests that fail due to network errors or server errors. By default, the SDK will retry requests up to 3 times, with an exponential backoff delay between retries.
29+
The SDK will automatically retry requests that fail due to network errors, `5xx` responses, and `408`, `409` and `429` responses. By default, the SDK makes up to 5 attempts per request (`maxAttempts: 5`, so up to 4 retries) with exponential backoff (`minTimeoutInMs` 1000, `maxTimeoutInMs` 30000, `factor` 1.6, `randomize` false). Any retry fields you pass are merged over these defaults.
3030

3131
You can customize the retry behavior by passing a `requestOptions` option to the `configure` function:
3232

@@ -58,9 +58,4 @@ async function main() {
5858
},
5959
});
6060
}
61-
```
62-
63-
<Note>
64-
When running inside a task, the SDK ignores customized retry options for certain functions (e.g.,
65-
`task.trigger`, `task.batchTrigger`), and uses retry settings optimized for task execution.
66-
</Note>
61+
```

‎docs/management/multiple-clients.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ await preview.runs.list({ status: ["COMPLETED"] });
2727
| Field | Description | Env-var fallback |
2828
| --------------- | -------------------------------------------------------------------------------------------------------- | ------------------------------------------------- |
2929
| `accessToken` | Environment API key (`tr_dev_sk_*`, `tr_prod_sk_*`, `tr_preview_sk_*`) or personal access token (`tr_pat_*`). | `TRIGGER_SECRET_KEY`, then `TRIGGER_ACCESS_TOKEN` |
30-
| `previewBranch` | Preview branch name when using a `tr_preview_sk_*` key. | `TRIGGER_PREVIEW_BRANCH`, then `VERCEL_GIT_COMMIT_REF` |
30+
| `previewBranch` | Preview branch name when using a `tr_preview_sk_*` key, or dev branch name for a dev environment. | `TRIGGER_PREVIEW_BRANCH`, then `VERCEL_GIT_COMMIT_REF`, then `TRIGGER_DEV_BRANCH` |
3131
| `baseURL` | Override the Trigger.dev API URL. Defaults to `https://api.trigger.dev`. | `TRIGGER_API_URL` |
3232
| `requestOptions`| Request-level options (retry policy, additional headers, etc.) — see the `ApiRequestOptions` type. | — |
3333

‎docs/management/overview.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import { configure, runs } from "@trigger.dev/sdk";
3333

3434
configure({
3535
// this is the default and if the `TRIGGER_SECRET_KEY` environment variable is set, can omit calling configure
36-
secretKey: process.env["TRIGGER_SECRET_KEY"],
36+
accessToken: process.env["TRIGGER_SECRET_KEY"],
3737
});
3838

3939
async function main() {

‎docs/management/sessions/channels.mdx‎

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ curl -X POST "https://api.trigger.dev/realtime/v1/sessions/{session}/in/append"
2525
--data '{"type":"user-message","text":"hello"}'
2626
```
2727

28-
The body is the raw record — any text up to 1MiB (records over the per-record cap return `413`). The response is `{ "ok": true }`.
28+
The body is the raw record — any text up to 1MiB (records over the per-record cap return `413`). The response is `{ "ok": true, "seq": <number> }`, where `seq` is the sequence number of the appended record. `seq` is omitted when no new record was written, for example when a retry reuses an `X-Part-Id` that was already appended. When the session's run is parked awaiting its deployment, the response also includes `"pendingVersion": true`.
2929

30-
Set the `X-Part-Id` header to a unique value per record to make the append idempotent: replaying the same `X-Part-Id` does not duplicate the record. Appending to a closed or expired session returns `400`.
30+
Set the `X-Part-Id` header to a unique value per record to make the append idempotent: replaying the same `X-Part-Id` does not duplicate the record. Appending to a closed session returns `409` (`code: "session_closed"`); appending to an expired session returns `400` (`code: "session_expired"`).
3131

3232
<Warning>
3333
Appending to `.out` requires a **secret key**. A session public token (even one with
@@ -48,27 +48,21 @@ curl -N "https://api.trigger.dev/realtime/v1/sessions/{session}/out" \
4848

4949
| Header | Direction | Description |
5050
| --- | --- | --- |
51-
| `Last-Event-ID` | request | Resume after this sequence number. Set it to the last `id:` you received to pick up exactly where you left off after a disconnect. |
51+
| `Last-Event-ID` | request | Resume after this sequence number. Set it to the `seq_num` of the last record you processed. |
5252
| `Timeout-Seconds` | request | How long the server holds the stream open with no new records before closing, `1`–`600`. |
5353

54-
Each SSE event carries:
55-
56-
- `id:` — the record's sequence number. Use the most recent one as `Last-Event-ID` to resume.
57-
- `data:` — a JSON record `{ "data": <record>, "id": <id> }`. For `.out` on a `chat.agent` session, `data` is a UI message chunk (text, reasoning, tool call, or a custom data part).
58-
59-
```text
60-
id: 42
61-
data: {"data":{"type":"text","text":"echo: hello"},"id":42}
62-
```
54+
The stream is passed through from S2. Events are `batch` (records), `ping` (keepalive) and a final `data: [DONE]`. The `id:` line is an internal S2 cursor (`startSeq,endSeq,byteOffset`); do not parse it. Each `batch` event has `data: {"records":[{"seq_num":42,"timestamp":1712150400000,"body":"{\"data\":<record>,\"id\":\"<partId>\"}","headers":[...]}],"tail":{...}}`, where `body` is a JSON string (empty for control records). See the [stream format](/ai-chat/client-protocol#stream-format-s2) for details.
6355

6456
### Control records
6557

6658
Some `.out` events are **control records** rather than data. A control record has an empty body and carries a `trigger-control` header naming its subtype:
6759

6860
| Subtype | Meaning |
6961
| --- | --- |
70-
| `turn-complete` | The current turn finished. Carries sibling headers `public-access-token` (a refreshed session token), `session-in-event-id`, and `last-event-id`. |
62+
| `turn-complete` | The current turn finished. Can carry sibling headers `public-access-token` (a refreshed session token), `session-in-event-id`, and `session-in-consumed-id`. It also carries a `session-closed` header (and `session-closed-reason`, when a reason was given) when the session was closed during that turn. |
7163
| `upgrade-required` | The session needs to hand off to a run on a newer deployed version. |
64+
| `session-closed` | The session was closed. Carries a `session-closed-reason` header when a reason was given. |
65+
| `pending-version` | The session's run is waiting for its deployment to land. |
7266

7367
Route control records by their subtype instead of treating them as message content. The TypeScript SDK does this for you — `session.out.read` filters control records out of the chunk stream and surfaces them through `onControl`.
7468

@@ -86,12 +80,12 @@ Pass `afterEventId` to return only records after that sequence number; omit it t
8680
```json
8781
{
8882
"records": [
89-
{ "data": { "type": "text", "text": "echo: hello" }, "id": 43, "seqNum": 43 }
83+
{ "data": "{\"type\":\"text\",\"text\":\"echo: hello\"}", "id": "a1b2c3d", "seqNum": 43 }
9084
]
9185
}
9286
```
9387

94-
Each record carries `data`, `id`, `seqNum`, and an optional `headers` array (present on control records). Page forward by passing the highest `seqNum` you received as the next `afterEventId`.
88+
Each record carries `data` (the appended record body as a string), `id` (the part ID: the `X-Part-Id` you sent on append, otherwise a generated ID; empty string on control records), `seqNum` (the sequence number), and an optional `headers` array. Page forward by passing the highest `seqNum` you received as the next `afterEventId`.
9589

9690
## Authorization
9791

@@ -127,4 +121,4 @@ for await (const chunk of stream) {
127121
}
128122
```
129123

130-
See [`session.in`](/ai-chat/sessions#session-in-—-clients-→-task) and [`session.out`](/ai-chat/sessions#session-out-—-task-→-clients) for the full handle API.
124+
See [`session.in`](/ai-chat/sessions) and [`session.out`](/ai-chat/sessions) for the full handle API.

‎docs/openapi.yml‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ components:
201201
Error:
202202
type: object
203203
properties:
204-
message:
204+
error:
205205
type: string
206206
EventRequest:
207207
type: object
@@ -291,7 +291,13 @@ components:
291291
runCount:
292292
type: integer
293293
minimum: 1
294-
description: Expected number of items in the batch. Must be a positive integer.
294+
description: Expected number of items in the batch. Must be a positive integer, up to the server's maximum batch size (1,000 by default; self-hosted instances can configure it). Requests above the maximum return a 400.
295+
taskIdentifiers:
296+
type: array
297+
minItems: 1
298+
items:
299+
type: string
300+
description: Distinct task identifiers of the items in the batch. Used to authorize tokens scoped to specific tasks. If omitted, only credentials with broad task access are accepted.
295301
parentRunId:
296302
type: string
297303
description: Parent run ID (friendly ID) for batchTriggerAndWait.

0 commit comments

Comments
 (0)