Sessions
client.sessions reads and deletes stored Sessions and handles pending Tool approvals. Create or resume a Session with client.chat(), not this resource.
Overview
Session and transcript lists use opaque cursors. Both list limits default to 50 and accept 1–200. Transcript cursor walks older pages; after polls forward from latestCursor. They are mutually exclusive.
Methods
list()
list(agentId: string, options?: { cursor?: string; limit?: number; userId?: string }): Promise<SessionsListResponse> — GET .../sessions. Omit userId for all or pass "" for tenant-level Sessions. limit defaults to 50 and accepts 1–200.
messages()
messages(agentId: string, sessionId: string, options?: { after?: string; cursor?: string; limit?: number }): Promise<SessionMessagesResponse> — GET .../messages. Returns data, nextCursor, and latestCursor; limit defaults to 50 and accepts 1–200.
delete()
delete(agentId: string, sessionId: string): Promise<void> — DELETE .../sessions/:sessionId.
toolApprovals()
toolApprovals(agentId: string, sessionId: string): Promise<ToolApprovalsResponse> — GET .../tool-approvals. Returns pending and decided calls plus an optional continuation.
decideToolApproval()
decideToolApproval(agentId: string, sessionId: string, approvalId: string, decision: { approved: boolean; reason?: string }, options?: { signal?: AbortSignal }): Promise<ToolApprovalDecisionResponse> — POST .../tool-approvals/:approvalId. The response supplies a continuationId and continuation state.
joinToolApprovalContinuation()
joinToolApprovalContinuation(agentId: string, sessionId: string, continuationId: string, options?: { signal?: AbortSignal }): Promise<TerminalStreamResult> — GET .../tool-approval-continuations/:continuationId. The returned terminal stream exposes one-shot toResponse() or toUIMessageStream().
Types
SessionListItem includes the Session ID, resolved Agent Version, counts, preview, Attribution, and timestamps. Transcript data uses the shared AI SDK-compatible message shape. Tool approval responses include exact tool-call input, decision, reason, and continuation state. See objects and schemas, pagination, and streaming.
Errors
Passing both cursor and after is invalid_request. Deleting or deciding an approval while the Session is executing can return SESSION_BUSY. Starting a Tool-approval continuation for a disabled Agent returns AGENT_DISABLED. A missing Session or approval is not_found; aborts are network_error; a malformed continuation stream is stream_error. See errors.
Example
import { BlazingAgents } from "@blazing-agents/sdk";
const client = new BlazingAgents({ apiKey: process.env.BLAZING_AGENTS_API_KEY! });
const agentId = "ag_0123456789abcdef";
const chat = await client.chat({
agentId,
message: { id: crypto.randomUUID(), role: "user", parts: [{ type: "text", text: "Hello" }] },
});
const sessionId = await chat.sessionId;
await chat.toResponse().text();
await client.sessions.list(agentId, { limit: 25 });
const page = await client.sessions.messages(agentId, sessionId, { limit: 25 });
const approvals = await client.sessions.toolApprovals(agentId, sessionId);
const pending = approvals.data.find((item) => item.decision === "pending");
if (pending) {
const decision = await client.sessions.decideToolApproval(
agentId, sessionId, pending.approvalId, { approved: true },
);
const stream = await client.sessions.joinToolApprovalContinuation(
agentId, sessionId, decision.continuationId,
);
await stream.toResponse().text();
}
console.log(page.latestCursor);
await client.sessions.delete(agentId, sessionId);Use list() to discover Sessions and delete() when their stored history is no longer needed.