Skip to main content

SSE Streaming Format

Agent execution and live session monitoring use Server-Sent Events (SSE) for real-time streaming.

Agent Execution Stream

When executing an agent via POST /api/v2/agents/:agent_id/stream, the response is an SSE stream with the following event types:

event: metadata
data: {"request_id":"uuid","agent_id":"uuid","session_id":null,"tenant_id":"uuid"}

event: status
data: {"phase":"STARTING","timestamp":"2026-01-13T19:00:00.000Z"}

event: phase
data: {"phase":"EXECUTE"}

event: tool
data: {"tool":"zigma_list_contracts","call_id":"uuid","success":true,"result_summary":"5 contracts found"}

event: thinking
data: {"thought":"Processing data..."}

event: response
data: {"content":"Found 5 active contracts...","sources":[]}

event: metrics
data: {"usage":{"input_tokens":150,"output_tokens":200,"total_tokens":350,"cost_usd":0.001},"iterations":2,"execution_time_ms":3500}

data: [DONE]

Event Types

EventDescriptionKey Fields
metadataRequest informationrequest_id, agent_id, session_id, tenant_id
statusInitial status or processing phasephase, timestamp
attachmentsAttachment processing resultsprocessed, errors
phasePhase changephase: STARTING, PROCESSING_ATTACHMENTS, EXECUTE, RESPOND
toolTool call executedtool, call_id, success, result_summary
thinkingAgent reasoningthought
responseFinal responsecontent, sources
metricsExecution metricsusage, iterations, execution_time_ms
warningNon-fatal warningmessage
errorExecution errorcode, message

Live Session Stream

Monitor agent executions in real-time via GET /api/v1/sessions/:executionId/live.

Events

EventDescriptionKey Fields
snapshotCurrent state on connectexecutionId, phase, agentId, startedAt
session:startSession startedtenantId, agentId, userId, source
session:phasePhase changephase: PREPROCESSING, EXECUTE, RESPOND
session:toolTool executiontool, success, result
session:thinkingAgent reasoningthought
session:linkedPersistent session ID resolvedsessionId
session:completeExecution completedcontentPreview, usage, iterations, executionTimeMs
session:errorExecution errorerror
Live to Detail Navigation

When you receive the session:linked event, you get the persistent sessionId that can be used to navigate to the session detail view. Before this event, sessionId is null.

Timeout: The SSE stream closes automatically after 5 minutes or when the session finishes.


Consuming SSE in Code

JavaScript (Browser):

const eventSource = new EventSource('/api/v1/sessions/exec-123/live', {
headers: { 'Authorization': 'Bearer <jwt>' }
});

eventSource.addEventListener('session:tool', (e) => {
const data = JSON.parse(e.data);
console.log(`Tool ${data.tool}: ${data.success ? 'OK' : 'FAILED'}`);
});

eventSource.addEventListener('session:complete', (e) => {
const data = JSON.parse(e.data);
console.log(`Done in ${data.executionTimeMs}ms`);
eventSource.close();
});

cURL:

curl -N "https://llm.zihin.ai/api/v2/agents/AGENT_ID/stream" \
-H "X-Api-Key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"message": "List active contracts"}'