TypeScript SDK: Sessions

⚠️
Preview — this feature is being built; the design below is the spec.

Run agents and follow their events. The SDK adds the agents beta flag for you.

import Syntic from '@syntic/sdk'
 
const client = new Syntic() // reads SYNTIC_API_KEY
MethodEndpointReturns
sessions.createPOST /v1/sessionsSession
sessions.sendPOST /v1/sessions/{session_id}/eventslist[SessionEvent]
sessions.streamGET /v1/sessions/{session_id}/streamIterator of SessionEvent
sessions.events.listGET /v1/sessions/{session_id}/eventsSyncPage[SessionEvent]
sessions.interruptPOST /v1/sessions/{session_id}/interruptSession
sessions.resources.addPOST /v1/sessions/{session_id}/resourcesSessionResource
sessions.threads.listGET /v1/sessions/{session_id}/threadsSyncPage[SessionThread]
sessions.archivePOST /v1/sessions/{session_id}/archiveSession

Methods

sessions.create

Start a session, optionally with first events. Maps to POST /v1/sessions.

const result = await client.sessions.create({
  agent_id: "agt_01JC4R8W6Q2N9X3T5V7Y",
  input: [
    {
      type: "user.message",
      content: "Where is my refund?"
    }
  ]
})

sessions.send

Send user messages, tool results or approvals. Maps to POST /v1/sessions/{session_id}/events.

const result = await client.sessions.send("sesn_01JC7M2K4P6R8T0V2X4Z", {
  events: [
    {
      type: "user.message",
      content: "Thanks!"
    }
  ]
})

sessions.stream

Iterate live events; reconnects with Last-Event-ID automatically. Maps to GET /v1/sessions/{session_id}/stream.

for await (const item of client.sessions.stream("sesn_01JC7M2K4P6R8T0V2X4Z")) {
  console.log(item)
}

sessions.events.list

Full history, paginated. Maps to GET /v1/sessions/{session_id}/events.

for await (const item of client.sessions.events.list("sesn_01JC7M2K4P6R8T0V2X4Z", {
  limit: 100
})) {
  console.log(item)
}

sessions.interrupt

Stop the current turn. Maps to POST /v1/sessions/{session_id}/interrupt.

const result = await client.sessions.interrupt("sesn_01JC7M2K4P6R8T0V2X4Z")

sessions.resources.add

Mount a file, repository or memory store. Maps to POST /v1/sessions/{session_id}/resources.

const result = await client.sessions.resources.add("sesn_01JC7M2K4P6R8T0V2X4Z", {
  kind: "file",
  file_id: "file_01JC3D5F7H9K1M3P5R7T"
})

sessions.threads.list

Primary and delegate threads with their usage. Maps to GET /v1/sessions/{session_id}/threads.

for await (const item of client.sessions.threads.list("sesn_01JC7M2K4P6R8T0V2X4Z")) {
  console.log(item)
}

sessions.archive

Close the session. Maps to POST /v1/sessions/{session_id}/archive.

const result = await client.sessions.archive("sesn_01JC7M2K4P6R8T0V2X4Z")

Conventions

Every method accepts a final options object with headers, query, timeout, maxRetries and signal (an AbortSignal). List methods return pages that work with for await across all pages.

See the TypeScript SDK overview for installation, errors and retries.

Was this page helpful?