You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 6910cd4
Browse filesBrowse the repository at this point in the historyBrowse files
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
Copy file name to clipboardExpand all lines: docs/management/authentication.mdx
+16-17Lines changed: 16 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,42 +4,42 @@ sidebarTitle: Authentication
4
4
description: Authenticating with the Trigger.dev management API
5
5
---
6
6
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.
8
8
9
9
<Note>
10
10
There is a separate authentication strategy when making requests from your frontend application.
11
11
See the [Realtime guide](/realtime/overview) for more information. This guide is for backend usage
12
12
only.
13
13
</Note>
14
14
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:
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_)
23
23
});
24
24
25
-
functionsecretKeyExample() {
25
+
functionaccessTokenExample() {
26
26
returnruns.list({
27
27
limit: 10,
28
28
status: ["COMPLETED"],
29
29
});
30
30
}
31
31
32
-
// Using personalAccessToken authentication
32
+
// Using personal access token authentication
33
33
configure({
34
-
secretKey: process.env["TRIGGER_ACCESS_TOKEN"], // starts with tr_pat_
34
+
accessToken: process.env["TRIGGER_ACCESS_TOKEN"], // starts with tr_pat_
35
35
});
36
36
37
37
function personalAccessTokenExample() {
38
-
// Notice the projectRef argument is required when using a personalAccessToken
39
-
returnruns.list("prof_1234", {
38
+
// Notice the projectRef argument is required when using a personal access token
39
+
returnruns.list("proj_1234", {
40
40
limit: 10,
41
41
status: ["COMPLETED"],
42
-
projectRef: "tr_proj_1234567890",
42
+
env: "prod",
43
43
});
44
44
}
45
45
```
@@ -73,7 +73,7 @@ function personalAccessTokenExample() {
73
73
74
74
### Environment API key
75
75
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.
77
77
78
78
### Personal Access Token (PAT)
79
79
@@ -85,7 +85,7 @@ For example, when uploading environment variables using a PAT, you must provide
secretKey: process.env["TRIGGER_ACCESS_TOKEN"], // starts with tr_pat_
111
+
accessToken: process.env["TRIGGER_ACCESS_TOKEN"], // starts with tr_pat_
112
112
previewBranch: "feature-xyz",
113
113
});
114
114
@@ -137,8 +137,7 @@ curl --request PUT \
137
137
This will set the `DATABASE_URL` environment variable specifically for the `feature-xyz` preview branch.
138
138
139
139
<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`
142
141
environments.
143
142
</Note>
144
143
@@ -150,7 +149,7 @@ When using the SDK to manage preview branch environment variables, the branch ta
`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.
223
222
224
223
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.
Copy file name to clipboardExpand all lines: docs/management/errors-and-retries.mdx
+4-9Lines changed: 4 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,14 +9,14 @@ description: Handling errors and retries with the Trigger.dev management API
9
9
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:
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.
30
30
31
31
You can customize the retry behavior by passing a `requestOptions` option to the `configure` function:
32
32
@@ -58,9 +58,4 @@ async function main() {
58
58
},
59
59
});
60
60
}
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.
|`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`|
31
31
|`baseURL`| Override the Trigger.dev API URL. Defaults to `https://api.trigger.dev`. |`TRIGGER_API_URL`|
32
32
|`requestOptions`| Request-level options (retry policy, additional headers, etc.) — see the `ApiRequestOptions` type. | — |
Copy file name to clipboardExpand all lines: docs/management/sessions/channels.mdx
+10-16Lines changed: 10 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -25,9 +25,9 @@ curl -X POST "https://api.trigger.dev/realtime/v1/sessions/{session}/in/append"
25
25
--data '{"type":"user-message","text":"hello"}'
26
26
```
27
27
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`.
29
29
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"`).
31
31
32
32
<Warning>
33
33
Appending to `.out` requires a **secret key**. A session public token (even one with
|`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. |
52
52
|`Timeout-Seconds`| request | How long the server holds the stream open with no new records before closing, `1`–`600`. |
53
53
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).
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.
63
55
64
56
### Control records
65
57
66
58
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:
67
59
68
60
| Subtype | Meaning |
69
61
| --- | --- |
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. |
71
63
|`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. |
72
66
73
67
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`.
74
68
@@ -86,12 +80,12 @@ Pass `afterEventId` to return only records after that sequence number; omit it t
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`.
95
89
96
90
## Authorization
97
91
@@ -127,4 +121,4 @@ for await (const chunk of stream) {
127
121
}
128
122
```
129
123
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.
Copy file name to clipboardExpand all lines: docs/openapi.yml
+8-2Lines changed: 8 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -201,7 +201,7 @@ components:
201
201
Error:
202
202
type: object
203
203
properties:
204
-
message:
204
+
error:
205
205
type: string
206
206
EventRequest:
207
207
type: object
@@ -291,7 +291,13 @@ components:
291
291
runCount:
292
292
type: integer
293
293
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.
295
301
parentRunId:
296
302
type: string
297
303
description: Parent run ID (friendly ID) for batchTriggerAndWait.
0 commit comments