Create session
Create a Session and trigger its first run in one atomic call. A Session is the durable identity for a bi-directional stream of records (the .in and .out channels) that survives across the runs processing it.
Idempotent on externalId within an environment. Calling create again with an externalId that already maps to an open session returns the existing session with isCached: true and 201 becomes 200. Reusing an externalId whose session is already closed or expired returns 409.
Authorize with a secret key, or a public token carrying write:sessions for the session you are creating.
Authorizations
Use your project-specific Secret API key. Will start with tr_dev_, tr_prod, tr_stg, etc.
You can find your Secret API key in the API Keys section of your Trigger.dev project dashboard.
Our TypeScript SDK will default to using the value of the TRIGGER_SECRET_KEY environment variable if it is set. If you are using the SDK in a different environment, you can set the key using the configure function.
import { configure } from "@trigger.dev/sdk";
configure({ accessToken: "tr_dev_1234" });
Body
Body for POST /api/v1/sessions. The whole body must be 32KB or smaller.
Free-form discriminator for the session, e.g. chat.agent. Not validated against an enum.
1 - 64"chat.agent"
The task this session triggers runs against.
1 - 128"my-chat"
Trigger options applied to every run a session schedules. basePayload is the wire payload merged into each run; the remaining fields map onto the standard trigger options.
Your stable identity for the session, unique per environment. Cannot start with the reserved session_ prefix. Reusing an externalId makes create idempotent; reusing one whose session is closed or expired returns 409.
1 - 256"chat_1234"
Up to 10 tags on the session row, for dashboard filtering.
10128Arbitrary JSON metadata.
Absolute expiry timestamp for retention.
Response
An open session already existed for this externalId. The existing session is returned with isCached: true.
A session row.
The session's friendly ID, prefixed with session_.
"session_abc123"
The session type discriminator.
"chat.agent"
The task this session triggers runs against.
"my-chat"
Tags on the session row.
["chat:1234"]
Friendly ID of the first run triggered alongside the session.
"run_def456"
Session-scoped public access token carrying read:sessions:{key} and write:sessions:{key}. Default TTL is 1 hour. Safe to pass to frontend clients.
true if an open session already existed for this externalId (idempotent upsert), false if newly created.
Your stable identity for the session, if one was set.
"chat_1234"
Trigger options applied to every run a session schedules. basePayload is the wire payload merged into each run; the remaining fields map onto the standard trigger options.
Friendly ID of the live run for this session, if any. Prefixed with run_. Omitted on list rows.
"run_def456"
Arbitrary JSON metadata, or null if unset.
When the session was closed, or null if open.
The optional reason recorded when the session was closed.
The session's retention deadline, or null if none.

