Skip to main content
POST
/
api
/
v1
/
sessions
/
{session}
/
close
Close a session
import { sessions } from "@trigger.dev/sdk";

await sessions.close(chatId, { reason: "user signed out" });
{
  "id": "session_abc123",
  "type": "chat.agent",
  "taskIdentifier": "my-chat",
  "tags": [
    "chat:1234"
  ],
  "createdAt": "2023-11-07T05:31:56Z",
  "updatedAt": "2023-11-07T05:31:56Z",
  "externalId": "chat_1234",
  "triggerConfig": {
    "basePayload": {},
    "machine": "small-1x",
    "queue": "<string>",
    "tags": [
      "<string>"
    ],
    "maxAttempts": 5,
    "maxDuration": 2,
    "lockToVersion": "20240523.1",
    "region": "<string>",
    "idleTimeoutInSeconds": 1800
  },
  "currentRunId": "run_def456",
  "metadata": {},
  "closedAt": "2023-11-07T05:31:56Z",
  "closedReason": "<string>",
  "expiresAt": "2023-11-07T05:31:56Z"
}

Authorizations

Authorization
string
header
required

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" });

Path Parameters

session
string
required

The session's friendly ID (session_…) or your externalId. The server disambiguates by the session_ prefix.

Body

application/json

Body for POST /api/v1/sessions/{session}/close. Up to 1KB.

reason
string

Optional reason recorded on the session row.

Maximum string length: 256
Example:

"user signed out"

Response

Session closed successfully. Returns the session row.

A session row.

id
string
required

The session's friendly ID, prefixed with session_.

Example:

"session_abc123"

type
string
required

The session type discriminator.

Example:

"chat.agent"

taskIdentifier
string
required

The task this session triggers runs against.

Example:

"my-chat"

tags
string[]
required

Tags on the session row.

Example:
["chat:1234"]
createdAt
string<date-time>
required
updatedAt
string<date-time>
required
externalId
string | null

Your stable identity for the session, if one was set.

Example:

"chat_1234"

triggerConfig
object

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.

currentRunId
string | null

Friendly ID of the live run for this session, if any. Prefixed with run_. Omitted on list rows.

Example:

"run_def456"

metadata
object

Arbitrary JSON metadata, or null if unset.

closedAt
string<date-time> | null

When the session was closed, or null if open.

closedReason
string | null

The optional reason recorded when the session was closed.

expiresAt
string<date-time> | null

The session's retention deadline, or null if none.