Get Your API Key
Sign up at webrun.ai
Navigate to Settings → API Keys
Click Create API Key and save it
enig_xxxxxxxxxxxxxxxxxxxxxxxxxxxx
Sessions cost money until terminated. Set terminateOnCompletion: true on your final task or explicitly terminate when done.
Run Your First Task
The simplest approach: one API call that creates a session, runs your task, and auto-terminates.
curl -X POST https://connect.webrun.ai/start/run-task \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"taskDetails": "Go to google.com and search for Anthropic"
}'
If the task completes within 50 seconds , you get the result immediately:
{
"success" : true ,
"sessionId" : "a1b2c3" ,
"taskId" : "x9y8z7" ,
"type" : "task_completed" ,
"data" : {
"message" : "Successfully searched for Anthropic on Google"
},
"usage" : {
"prompt_tokens" : 12450 ,
"completion_tokens" : 3200 ,
"total_tokens" : 15650 ,
"completion_time" : 23.5 ,
"cost" : 0.0124
}
}
If the task takes longer , you’ll get a polling URL:
{
"success" : true ,
"sessionId" : "a1b2c3" ,
"taskId" : "x9y8z7" ,
"status" : "pending" ,
"pollUrl" : "https://connect.webrun.ai/task/a1b2c3/x9y8z7"
}
Poll the URL every 2-3 seconds until the task completes. Most tasks finish in 10-40 seconds, so faster polling wastes API quota while slower polling adds latency.
Multi-Task Sessions
For multiple tasks in sequence, create a persistent session:
1. Create the session
curl -X POST https://connect.webrun.ai/start/start-session \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"mode": "default",
"initialTask": {
"taskDetails": "Go to amazon.com",
"startingPoint": "https://amazon.com"
}
}'
2. Send follow-up tasks
curl -X POST https://connect.webrun.ai/start/send-message \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"sessionId": "SESSION_ID",
"message": {
"actionType": "newTask",
"newState": "start",
"taskDetails": "Search for wireless keyboards",
"startingPoint": "https://amazon.com"
}
}'
3. Terminate when finished
curl -X POST https://connect.webrun.ai/start/send-message \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"sessionId": "SESSION_ID",
"message": {
"actionType": "state",
"newState": "terminate"
}
}'
Alternatively, set terminateOnCompletion: true on your last task to auto-terminate the session.
Multi-task workflows guide
Polling for Results
When a task returns status: "pending", poll the URL until completion.
async function runTask ( taskDetails , apiKey ) {
// Start the task
const response = await fetch ( "https://connect.webrun.ai/start/run-task" , {
method: "POST" ,
headers: {
"Content-Type" : "application/json" ,
"Authorization" : `Bearer ${ apiKey } `
},
body: JSON . stringify ({ taskDetails })
});
const data = await response . json ();
// Return immediately if complete
if ( data . type === "task_completed" ) {
return data ;
}
// Poll if still running
if ( data . status === "pending" ) {
return await pollForResult ( data . sessionId , data . taskId , apiKey );
}
throw new Error ( data . message || "Task failed" );
}
async function pollForResult ( sessionId , taskId , apiKey ) {
const maxAttempts = 60 ; // 2 minutes
const interval = 2000 ; // Poll every 2 seconds
for ( let i = 0 ; i < maxAttempts ; i ++ ) {
const res = await fetch (
`https://connect.webrun.ai/task/ ${ sessionId } / ${ taskId } ` ,
{ headers: { "Authorization" : `Bearer ${ apiKey } ` } }
);
const data = await res . json ();
if ( data . type === "task_completed" ) return data ;
if ( data . type === "guardrail_trigger" ) return data ;
if ( ! data . success && data . type === "failed" ) {
throw new Error ( data . error );
}
await new Promise ( r => setTimeout ( r , interval ));
}
throw new Error ( "Task timeout after 2 minutes" );
}
// Usage
const result = await runTask ( "Search Google for Anthropic" , "enig_xxx" );
console . log ( result . data . message );
console . log ( `Cost: $ ${ result . usage . cost } ` );
This handles both instant and long-running tasks automatically.
Real-Time Updates with WebSocket
For live agent thoughts and action notifications, use WebSocket. This requires more setup but gives you sub-second visibility into task execution.
WebSocket integration guide
Next Steps
Multi-Task Workflows Chain multiple tasks in a session
MCP Integration Set up Claude Desktop integration
Video Streaming Watch sessions execute in real-time
Cost Optimization Reduce costs and improve efficiency
File Uploads Upload files for the agent to use in sessions