Overview
WebRun provides two ways to receive responses:REST API Response Formats
Inline Results (< 50 seconds)
Both/run-task and /send-message wait up to 50 seconds for task completion. If the task finishes in time, you get the result immediately.
Structure:
Pending Results (> 50 seconds)
For longer tasks, the response returns immediately with a poll URL. Structure:Polling Responses
PollGET /task/:sessionId/:taskId until pending: false or a final type is returned.
Still Running
Task Completed
Guardrail Triggered
Next Steps:
Respond with guardrail message via
POST /start/send-message:
Task Failed
Session Creation Response
POST /start/start-session returns session details and streaming configuration.
State Control Response
POST /start/send-message with actionType: "state", "interaction", or "guardrail" returns immediate confirmation.
WebSocket Event Formats
Connect via Socket.IO and listen formessage events:
Event: agent
Live agent thoughts and reasoning during task execution.Event: action
Browser action performed by the agent.Event: response_update
Status update during task execution.Event: task_completed
Task finished successfully.Event: guardrail_trigger
Agent needs human input to continue.
Respond with:
Event: error
Task failed with error.Connection Events
connect
Socket connected successfully.disconnect
Socket disconnected.error
Socket error occurred.end_session
Session terminated by server."completed"- Task completed"terminated"- Manually terminated"expired"- Session expired due to inactivity"terminateOnCompletion"- Auto-terminated after task"instance_lost"- Instance connection lost
instance:disconnected
Instance connection lost. Session enters grace period for reconnection.instance:reconnected
Instance connection recovered.OpenAI-Compatible Response Formats
Non-Streaming Response
POST /v1/chat/completions with stream: false (default).
Streaming Response (SSE)
POST /v1/chat/completions with stream: true returns Server-Sent Events.
Stream Format:
Handling Streams:
Error Response Format
All errors follow this standard format:
See Rate Limits for handling 429 errors.
Usage Object Structure
Theusage object appears in many responses and provides token and cost information:
Complete Event Reference Table
Next Steps
Endpoints
Complete endpoint reference
Parameters
Parameter documentation
Events & Responses
Detailed event handling guide
WebSocket Integration
WebSocket integration guide