Sessions API
Sessions represent conversations with agents. They store conversation history, resources, and variables.
All session endpoints require an API key with the Sessions permission.
Create Session
Create a new agent session.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
agentId | string | Yes | Agent ID (the id field, not slug) |
input | object | No | Input variables for the agent |
Response
Example
Get Session
Retrieve session state. Returns UI-ready messages for active sessions, or expiration info for expired sessions.
Query Parameters
| Parameter | Type | Description |
|---|---|---|
format | string | Optional. Use format=ui for UI-ready messages only |
Response (Active Session)
When the session is active, the response includes UIMessage objects:
Response (Expired Session)
When the session has expired, the response indicates the expiration status:
Use the Restore Session endpoint to restore an expired session from stored messages.
Restore Session
Restore an expired session from stored messages. This allows you to continue a conversation after the server-side state has expired.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
messages | UIMessage[] | Yes | Previously stored chat history |
input | object | No | Session input for system prompt interpolation (same as create) |
Response
| Field | Type | Description |
|---|---|---|
sessionId | string | The session ID |
restored | boolean | true if restored from messages, false if session was already active |
Example
Note: Store the UIMessage[] array after each interaction to enable restoration. The restore endpoint reconstructs the conversation state from these messages.
Clear Session
Clear session state, transitioning it to expired status. The session can be restored afterwards with the Restore Session endpoint.
This is idempotent — clearing an already expired session succeeds without error.
Response
Example
Trigger Session
Execute a trigger on a session. Returns a Server-Sent Events stream.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
triggerName | string | Yes | Name of the trigger to execute |
input | object | No | Input variables for the trigger |
toolResults | array | No | Tool results for continuation (handled by SDK) |
Response
Returns text/event-stream with SSE events:
Event Types
| Event | Description |
|---|---|
start | Stream started |
finish | Execution complete |
error | Error occurred |
block-start | Execution block started |
block-end | Execution block completed |
text-start | Text generation started |
text-delta | Incremental text content |
text-end | Text generation ended |
reasoning-start | Extended reasoning started |
reasoning-delta | Reasoning content |
reasoning-end | Extended reasoning ended |
tool-input-start | Tool call initiated |
tool-input-delta | Tool arguments streaming |
tool-input-end | Tool arguments streaming ended |
tool-input-available | Tool input complete |
tool-output-available | Tool completed with result |
tool-output-error | Tool failed |
tool-request | Platform requesting tool execution |
file-available | File ready for display/download |
resource-update | Resource value changed |
Example
Tool Continuation
When the agent calls external tools, you'll receive a tool-request event. Execute the tools and send results back:
The Server SDK handles this continuation pattern automatically.
Upload URLs
Get presigned URLs for file uploads. Files are uploaded directly to S3.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
sessionId | string | Yes | Session ID to associate files with |
files | array | Yes | Array of file metadata (1-20 files) |
files[].filename | string | Yes | Original filename |
files[].mediaType | string | Yes | MIME type (e.g., image/png) |
files[].size | number | Yes | File size in bytes |
Response
Upload Flow
- Request upload URLs from the platform
- PUT file content to
uploadUrlwithContent-Typeheader - Use
downloadUrlas theurlinFileReference - Include
FileReferencein trigger input
Supported Types
| Category | Media Types |
|---|---|
| Images | image/jpeg, image/png, image/gif, image/webp |
| Documents | application/pdf, text/plain, text/markdown, application/json |
Limits
| Limit | Value |
|---|---|
| Max file size | 10 MB |
| Max total per request | 50 MB |
| Max files per request | 20 |
| Upload URL expiry | 15 minutes |
| Download URL expiry | 24 hours |