Documentation Index Fetch the complete documentation index at: https://docs.webrun.ai/llms.txt
Use this file to discover all available pages before exploring further.
Overview
WebRun provides two ways to receive responses:
Method How It Works Best For REST Results returned inline if task completes within 50s, otherwise poll Stateless, serverless, simple integrations WebSocket Real-time events pushed as they occur Real-time UIs, live monitoring
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:
{
"success" : true ,
"sessionId" : "a1b2c3d4e5f6" ,
"taskId" : "x9y8z7w6v5u4" ,
"type" : "task_completed" ,
"data" : {
"message" : "Successfully completed the search" ,
"files" : [
{
"source" : "https://example.com/report.zip" ,
"downloadUrl" : "https://blobs.webrun.ai/files/report.zip" ,
"filename" : "report.zip" ,
"timestamp" : 1771138379108
}
],
"network" : [
{
"id" : "tevo9" ,
"taskId" : "x9y8z7w6v5u4" ,
"urls" : [
{
"url" : "https://example.com/api/data" ,
"timestamp" : 1771138379087.646
}
]
}
]
},
"usage" : {
"prompt_tokens" : 12450 ,
"completion_tokens" : 3200 ,
"total_tokens" : 15650 ,
"completion_time" : 23.5 ,
"cost" : 0.0124
}
}
Response Fields:
Field Type Description successboolean Request success indicator sessionIdstring Session identifier taskIdstring Task identifier typestring Result type: "task_completed" dataobject Task result data data.messagestring Task completion message data.filesarray Files downloaded during task execution (optional) data.files[].sourcestring Original URL the file was downloaded from data.files[].downloadUrlstring WebRun-hosted URL to download the file data.files[].filenamestring Name of the downloaded file data.files[].timestampnumber Unix timestamp (ms) when the file was downloaded data.networkarray Network requests captured during task execution (optional) data.network[].idstring Unique identifier for the network entry data.network[].taskIdstring Task that generated the network activity data.network[].urlsarray URLs requested in this network entry data.network[].urls[].urlstring Full URL of the network request data.network[].urls[].timestampnumber Unix timestamp (ms) of the request usageobject Usage and billing information usage.prompt_tokensnumber Input tokens used usage.completion_tokensnumber Output tokens generated usage.total_tokensnumber Total tokens used usage.completion_timenumber Execution time in seconds usage.costnumber Cost in USD
Pending Results (> 50 seconds)
For longer tasks, the response returns immediately with a poll URL.
Structure:
{
"success" : true ,
"sessionId" : "a1b2c3d4e5f6" ,
"taskId" : "x9y8z7w6v5u4" ,
"status" : "pending" ,
"pending" : true ,
"pollUrl" : "https://connect.webrun.ai/task/a1b2c3d4e5f6/x9y8z7w6v5u4" ,
"message" : "Task still running. Poll GET /task/:sessionId/:taskId for result."
}
Response Fields:
Field Type Description successboolean Request success indicator sessionIdstring Session identifier taskIdstring Task identifier for polling statusstring Task status: "pending" pendingboolean true when task is still runningpollUrlstring URL to poll for task result messagestring Instruction to poll for result
Polling Responses
Poll GET /task/:sessionId/:taskId until pending: false or a final type is returned.
Still Running
{
"success" : true ,
"sessionId" : "a1b2c3d4e5f6" ,
"taskId" : "x9y8z7w6v5u4" ,
"status" : "running" ,
"usage" : {
"prompt_tokens" : 8000 ,
"completion_tokens" : 2100 ,
"total_tokens" : 10100 ,
"completion_time" : 12.3 ,
"cost" : 0.0067
}
}
Response Fields:
Field Type Description successboolean Request success indicator sessionIdstring Session identifier taskIdstring Task identifier statusstring "running" - task is executingusageobject Current usage statistics (updates in real-time)
Task Completed
{
"success" : true ,
"sessionId" : "a1b2c3d4e5f6" ,
"taskId" : "x9y8z7w6v5u4" ,
"type" : "task_completed" ,
"data" : {
"message" : "Task finished successfully" ,
"files" : [
{
"source" : "https://example.com/report.zip" ,
"downloadUrl" : "https://blobs.webrun.ai/files/report.zip" ,
"filename" : "report.zip" ,
"timestamp" : 1771138379108
}
],
"network" : [
{
"id" : "tevo9" ,
"taskId" : "x9y8z7w6v5u4" ,
"urls" : [
{
"url" : "https://example.com/api/data" ,
"timestamp" : 1771138379087.646
}
]
}
]
},
"usage" : {
"prompt_tokens" : 12450 ,
"completion_tokens" : 3200 ,
"total_tokens" : 15650 ,
"completion_time" : 23.5 ,
"cost" : 0.0124
},
"completedAt" : "2024-01-15T10:30:00Z"
}
Response Fields:
Field Type Description successboolean Request success indicator sessionIdstring Session identifier taskIdstring Task identifier typestring "task_completed"dataobject Task result data data.messagestring Completion message data.filesarray Files downloaded during task execution (optional) data.files[].sourcestring Original URL the file was downloaded from data.files[].downloadUrlstring WebRun-hosted URL to download the file data.files[].filenamestring Name of the downloaded file data.files[].timestampnumber Unix timestamp (ms) when the file was downloaded data.networkarray Network requests captured during task execution (optional) data.network[].idstring Unique identifier for the network entry data.network[].taskIdstring Task that generated the network activity data.network[].urlsarray URLs requested in this network entry data.network[].urls[].urlstring Full URL of the network request data.network[].urls[].timestampnumber Unix timestamp (ms) of the request usageobject Final usage statistics usage.prompt_tokensnumber Total input tokens usage.completion_tokensnumber Total output tokens usage.total_tokensnumber Total tokens usage.completion_timenumber Execution time in seconds usage.costnumber Cost in USD completedAtstring ISO 8601 completion timestamp
Guardrail Triggered
{
"success" : true ,
"type" : "guardrail_trigger" ,
"data" : {
"type" : "human_input_needed" ,
"value" : "I need login credentials to proceed"
}
}
Response Fields:
Field Type Description successboolean Request success indicator typestring "guardrail_trigger"dataobject Guardrail details data.typestring Guardrail type data.valuestring Message explaining what’s needed
Next Steps:
Respond with guardrail message via POST /start/send-message:
{
"sessionId" : "a1b2c3d4e5f6" ,
"message" : {
"actionType" : "guardrail" ,
"prompt" : "Username: user@example.com, Password: pass123" ,
"newState" : "resume"
}
}
Task Failed
{
"success" : false ,
"sessionId" : "a1b2c3d4e5f6" ,
"taskId" : "x9y8z7w6v5u4" ,
"status" : "failed" ,
"error" : "Navigation timeout after 30 seconds" ,
"code" : "NAVIGATION_TIMEOUT" ,
"usage" : {
"prompt_tokens" : 5000 ,
"completion_tokens" : 1200 ,
"total_tokens" : 6200 ,
"completion_time" : 30.0 ,
"cost" : 0.0045
}
}
Response Fields:
Field Type Description successboolean falsestatusstring "failed"errorstring Error message codestring Error code usageobject Usage statistics up to failure
Session Creation Response
POST /start/start-session returns session details and streaming configuration.
{
"success" : true ,
"sessionId" : "a1b2c3d4e5f6" ,
"socketURL" : "https://connect.webrun.ai" ,
"streaming" : {
"webRTCURL" : "https://74.235.190.31:8889/a1b2c3d4e5f6/whep" ,
"webViewURL" : "https://74.235.190.31:8889/a1b2c3d4e5f6" ,
"dimensions" : {
"width" : 1024 ,
"height" : 600
}
},
"initialPrompt" : "Go to amazon.com" ,
"expiresIn" : 300000 ,
"balance" : 12.50 ,
"message" : "Connect to instance using sessionId in auth"
}
Response Fields:
Field Type Description successboolean Request success indicator sessionIdstring Unique session identifier socketURLstring WebSocket connection URL streamingobject Video streaming configuration streaming.webRTCURLstring WebRTC WHEP endpoint streaming.webViewURLstring HTTP video stream URL streaming.dimensionsobject Video dimensions initialPromptstring Initial task provided expiresInnumber Session expiration time (ms) balancenumber Current account balance (USD) messagestring Additional information
State Control Response
POST /start/send-message with actionType: "state", "interaction", or "guardrail" returns immediate confirmation.
{
"success" : true ,
"message" : "Message sent successfully"
}
Response Fields:
Field Type Description successboolean Request success indicator messagestring Confirmation message
Connect via Socket.IO and listen for message events:
socket . on ( "message" , ( data ) => {
console . log ( data . type , data );
});
Event: agent
Live agent thoughts and reasoning during task execution.
{
"type" : "agent" ,
"content" : "I'll navigate to the search box and enter the query..."
}
Fields:
Field Type Description typestring "agent"contentstring Agent reasoning text
Event: action
Browser action performed by the agent.
{
"type" : "action" ,
"data" : {
"name" : "click_element"
}
}
Fields:
Field Type Description typestring "action"dataobject Action details data.namestring Action name
Event: response_update
Status update during task execution.
{
"type" : "response_update" ,
"data" : {
"message" : "Starting task... Browsing the web now."
}
}
Fields:
Field Type Description typestring "response_update"dataobject Update details data.messagestring Status message
Event: task_completed
Task finished successfully.
{
"type" : "task_completed" ,
"sessionId" : "a1b2c3d4e5f6" ,
"taskId" : "x9y8z7w6v5u4" ,
"data" : {
"message" : "Task completed successfully" ,
"files" : [
{
"source" : "https://example.com/report.zip" ,
"downloadUrl" : "https://blobs.webrun.ai/files/report.zip" ,
"filename" : "report.zip" ,
"timestamp" : 1771138379108
}
],
"network" : [
{
"id" : "tevo9" ,
"taskId" : "x9y8z7w6v5u4" ,
"urls" : [
{
"url" : "https://example.com/api/data" ,
"timestamp" : 1771138379087.646
}
]
}
]
},
"usage" : {
"prompt_tokens" : 15420 ,
"completion_tokens" : 8230 ,
"total_tokens" : 23650 ,
"completion_time" : 45.3 ,
"cost" : 0.0234
}
}
Fields:
Field Type Description typestring "task_completed"sessionIdstring Session identifier taskIdstring Task identifier dataobject Completion details data.messagestring Completion message data.filesarray Files downloaded during task execution (optional) data.files[].sourcestring Original URL the file was downloaded from data.files[].downloadUrlstring WebRun-hosted URL to download the file data.files[].filenamestring Name of the downloaded file data.files[].timestampnumber Unix timestamp (ms) when the file was downloaded data.networkarray Network requests captured during task execution (optional) data.network[].idstring Unique identifier for the network entry data.network[].taskIdstring Task that generated the network activity data.network[].urlsarray URLs requested in this network entry data.network[].urls[].urlstring Full URL of the network request data.network[].urls[].timestampnumber Unix timestamp (ms) of the request usageobject Usage statistics usage.prompt_tokensnumber Input tokens used usage.completion_tokensnumber Output tokens generated usage.total_tokensnumber Total tokens used usage.completion_timenumber Execution time (seconds) usage.costnumber Cost in USD
Event: guardrail_trigger
Agent needs human input to continue.
{
"type" : "guardrail_trigger" ,
"data" : {
"type" : "human_input_needed" ,
"value" : "I need login credentials to proceed"
}
}
Fields:
Field Type Description typestring "guardrail_trigger"dataobject Guardrail details data.typestring Guardrail type data.valuestring Message explaining what’s needed
Respond with:
socket . emit ( "message" , {
actionType: "guardrail" ,
prompt: "Username: demo@example.com, Password: demo123" ,
newState: "resume"
});
Event: error
Task failed with error.
{
"type" : "error" ,
"error" : "Navigation timeout after 30 seconds" ,
"code" : "NAVIGATION_TIMEOUT"
}
Fields:
Field Type Description typestring "error"errorstring Error message codestring Error code
Connection Events
connect
Socket connected successfully.
socket . on ( "connect" , () => {
console . log ( "Connected to session" );
});
disconnect
Socket disconnected.
socket . on ( "disconnect" , () => {
console . log ( "Disconnected from session" );
});
error
Socket error occurred.
socket . on ( "error" , ( err ) => {
console . error ( "Socket error:" , err );
});
end_session
Session terminated by server.
{
"reason" : "completed"
}
Possible Reasons:
"completed" - Task completed
"terminated" - Manually terminated
"expired" - Session expired due to inactivity
"terminateOnCompletion" - Auto-terminated after task
"instance_lost" - Instance connection lost
socket . on ( "end_session" , ( data ) => {
console . log ( "Session ended:" , data . reason );
});
instance:disconnected
Instance connection lost. Session enters grace period for reconnection.
{
"gracePeriod" : 300000
}
socket . on ( "instance:disconnected" , ( data ) => {
console . log ( "Instance lost, waiting for reconnection..." );
console . log ( "Grace period:" , data . gracePeriod , "ms" );
});
instance:reconnected
Instance connection recovered.
socket . on ( "instance:reconnected" , ( data ) => {
console . log ( "Instance reconnected" );
});
Non-Streaming Response
POST /v1/chat/completions with stream: false (default).
{
"id" : "chatcmpl-a1b2c3d4e5f6" ,
"object" : "chat.completion" ,
"created" : 1704067200 ,
"model" : "enigma-browser-1" ,
"choices" : [
{
"index" : 0 ,
"message" : {
"role" : "assistant" ,
"content" : "I found 5 headings on example.com: \n 1. Example Domain \n 2. More Information \n 3. Contact \n 4. About \n 5. Privacy Policy"
},
"finish_reason" : "stop"
}
],
"usage" : {
"prompt_tokens" : 8450 ,
"completion_tokens" : 2100 ,
"total_tokens" : 10550
},
"webrun" : {
"sessionId" : "a1b2c3d4e5f6" ,
"taskId" : "x9y8z7w6v5u4" ,
"cost" : 0.0089
}
}
Response Fields:
Field Type Description idstring Completion identifier objectstring "chat.completion"creatednumber Unix timestamp modelstring Model name: "enigma-browser-1" choicesarray Array of completion choices choices[0].indexnumber Choice index (always 0) choices[0].messageobject Assistant message choices[0].message.rolestring "assistant"choices[0].message.contentstring Response text choices[0].finish_reasonstring "stop"usageobject Token usage statistics usage.prompt_tokensnumber Input tokens usage.completion_tokensnumber Output tokens usage.total_tokensnumber Total tokens webrunobject WebRun-specific metadata webrun.sessionIdstring Session identifier webrun.taskIdstring Task identifier webrun.costnumber Cost in USD
Streaming Response (SSE)
POST /v1/chat/completions with stream: true returns Server-Sent Events.
Stream Format:
data: {"id":"chatcmpl-a1b2c3","object":"chat.completion.chunk","created":1704067200,"model":"enigma-browser-1","choices":[{"index":0,"delta":{"role":"assistant","content":"I"},"finish_reason":null}]}
data: {"id":"chatcmpl-a1b2c3","object":"chat.completion.chunk","created":1704067200,"model":"enigma-browser-1","choices":[{"index":0,"delta":{"content":" found"},"finish_reason":null}]}
data: {"id":"chatcmpl-a1b2c3","object":"chat.completion.chunk","created":1704067200,"model":"enigma-browser-1","choices":[{"index":0,"delta":{"content":" 5"},"finish_reason":null}]}
data: {"id":"chatcmpl-a1b2c3","object":"chat.completion.chunk","created":1704067200,"model":"enigma-browser-1","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}
data: [DONE]
Chunk Structure:
Field Type Description idstring Completion identifier objectstring "chat.completion.chunk"creatednumber Unix timestamp modelstring "enigma-browser-1"choicesarray Array of delta choices choices[0].indexnumber Choice index (always 0) choices[0].deltaobject Content delta choices[0].delta.rolestring "assistant" (first chunk only)choices[0].delta.contentstring Text chunk choices[0].finish_reasonstring null during stream, "stop" at end
Handling Streams:
import OpenAI from 'openai' ;
const client = new OpenAI ({
baseURL: 'https://connect.webrun.ai/v1' ,
apiKey: 'YOUR_API_KEY'
});
const stream = await client . chat . completions . create ({
model: 'enigma-browser-1' ,
messages: [{ role: 'user' , content: 'Go to example.com' }],
stream: true
});
for await ( const chunk of stream ) {
const content = chunk . choices [ 0 ]?. delta ?. content || '' ;
process . stdout . write ( content );
}
All errors follow this standard format:
{
"success" : false ,
"message" : "Human-readable error message"
}
Common HTTP Status Codes:
Status Meaning Example Message 200 Success - 400 Bad request "sessionId and message are required"401 Unauthorized "Invalid or revoked API key"402 Payment required "Insufficient balance."403 Forbidden "Account is deactivated"404 Not found "Session not found"429 Too many requests "Rate limit exceeded. Please try again later."500 Internal server error "Internal server error"503 Service unavailable "No available instances."
See Rate Limits for handling 429 errors.
Usage Object Structure
The usage object appears in many responses and provides token and cost information:
interface Usage {
prompt_tokens : number ; // Number of input tokens used
completion_tokens : number ; // Number of output tokens generated
total_tokens : number ; // Total tokens (prompt + completion)
completion_time : number ; // Execution time in seconds
cost : number ; // Cost in USD
}
Example:
{
"usage" : {
"prompt_tokens" : 12450 ,
"completion_tokens" : 3200 ,
"total_tokens" : 15650 ,
"completion_time" : 23.5 ,
"cost" : 0.0124
}
}
Complete Event Reference Table
Event Type REST WebSocket Description agent✗ ✓ Live agent reasoning action✗ ✓ Browser action performed response_update✗ ✓ Status updates task_completed✓ (poll) ✓ Task finished successfully guardrail_trigger✓ (poll) ✓ Human input needed error✓ (poll) ✓ Task failed end_session✗ ✓ Session terminated instance:disconnected✗ ✓ Instance connection lost instance:reconnected✗ ✓ Instance recovered
Next Steps
Endpoints Complete endpoint reference
Parameters Parameter documentation
Events & Responses Detailed event handling guide
WebSocket Integration WebSocket integration guide