TypeScript SDK: Sessions
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| Method | Endpoint | Returns |
|---|---|---|
sessions.create | POST /v1/sessions | Session |
sessions.send | POST /v1/sessions/{session_id}/events | list[SessionEvent] |
sessions.stream | GET /v1/sessions/{session_id}/stream | Iterator of SessionEvent |
sessions.events.list | GET /v1/sessions/{session_id}/events | SyncPage[SessionEvent] |
sessions.interrupt | POST /v1/sessions/{session_id}/interrupt | Session |
sessions.resources.add | POST /v1/sessions/{session_id}/resources | SessionResource |
sessions.threads.list | GET /v1/sessions/{session_id}/threads | SyncPage[SessionThread] |
sessions.archive | POST /v1/sessions/{session_id}/archive | Session |
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.