When to use this
- You need to cancel a prompt that is taking too long or going off track
- You want to undo file changes the agent made during a prompt
- You lost a WebSocket connection and need to recover the agent’s output
- You are choosing between REST polling and WebSocket streaming for your integration
Prerequisites
- An API key with
sessions:promptscope (andsessions:writefor rewind) - A running session with at least one prompt already submitted
Check prompt status
The session object includes alast_prompt field with the status of the most recent prompt:
Cancel a running prompt
POST /api/sessions/{id}/prompt/cancel interrupts the current prompt. The agent task is stopped, the running flag is cleared, and any event streams receive their final events.
Canceling stops the agent, but file changes already written to disk are not reverted. Use rewind (below) to undo file changes.
Rewind file changes
POST /api/sessions/{id}/prompt/rewind restores the filesystem to a checkpoint captured during a prior prompt. The conversation history is preserved - only file contents are reverted.
result events) and in prompt history. Use rewind when:
- The agent made destructive changes you want to undo
- You want to try a different approach from the same starting point
- A prompt went off track and you want to restore the workspace
Replay prompt history
GET /api/sessions/{id}/history returns the full parsed conversation for an agent session. Use this to reconstruct the conversation after a disconnect or to audit what the agent did.
user, assistant_text, tool_use, tool_result, and completion.
REST vs WebSocket: choosing the right approach
Use REST + SSE when:
- You want simplicity and do not need to display streaming events in a UI
- Your integration is a local script, coding agent, or CI pipeline
- You only need the final result
- You are building a UI that shows live agent output
- You want structured event types (tool calls, file edits, text deltas) as they happen
- You need the lowest-latency path from agent to client
Common patterns
Submit → wait → collect
The simplest REST pattern: submit a prompt, poll until done, read the result.Python
Guard against concurrent prompts
Only one prompt runs per session. If you submit while one is running, you get202 with status: "already_running". Guard against this:
Python
Next steps
Stream prompts over WebSockets
Full WebSocket connection flow with code samples.
Work with session files
Read, write, and download files from the sandbox.
Run Prompt reference
REST endpoint specification for submitting prompts.
Prompt History reference
Replay parsed conversation history.