When to use this
- You want live agent output as the prompt executes (not just the final result)
- You are building a UI that displays tool calls, file changes, or streaming text
- You want to monitor an agent’s progress in real time from your terminal, a local script, or a backend service
POST /api/sessions/{id}/prompt endpoint with GET /api/sessions/{id}/events (SSE) instead.
Prerequisites
- An API key with
sessions:promptscope - A running session (state:
running) - A WebSocket client library (
websocketsfor Python, nativeWebSocketfor JS/browsers)
Connection flow
The Prompt WebSocket uses a three-step flow: mint a token, connect, send the prompt.Step 1: Mint a token
WebSocket connections cannot carryAuthorization headers in the browser, so you exchange your API key for a short-lived, single-purpose token over HTTPS:
Tokens are short-lived and single-use. Mint a new one for every WebSocket connection. Never reuse tokens.
Step 2: Connect
Open the WebSocket using the token as a query parameter:Step 3: Send the prompt
After the connection is accepted, send exactly one JSON text frame within 10 seconds:Event types
After the prompt is accepted, the server streams events until a terminaldone or error frame. Here are the event types in the order you will typically see them:
Full example
Resume a conversation
To continue a prior conversation on the same tab, reuse the sametab_id and set resume: true:
tab_id each time you reconnect.
Close codes
If the connection closes unexpectedly, check the close code:Next steps
Handle long-running prompts
Cancel, rewind, and replay prompt history.
Manage sessions at scale
Lifecycle management, polling, and error recovery.
WebSocket reference
Terminal, prompt, and collaboration WebSocket specs.
Token Exchange reference
Full token-exchange endpoint specification.