Synchronous vs Asynchronous
WebRun uses a hybrid response model that combines the simplicity of synchronous APIs with the reliability of asynchronous polling:- Tasks completing in < 50 seconds: Result returned inline (synchronous)
- Tasks taking > 50 seconds: Poll URL returned for async polling
Why This Design?
Pure sync doesn’t work because HTTP timeouts (30-60s) are too short for complex browser tasks. Pure async doesn’t work because polling adds unnecessary complexity for simple tasks that finish in seconds. The hybrid approach waits up to 50 seconds. If the task finishes in time, the result comes back inline. If not, you get a poll URL. In practice, ~90% of tasks return inline.How It Works
Inline Response (< 50 seconds)
When your task completes within 50 seconds, you get the full result in the initial response: Request:type: "task_completed"
Pending Response (> 50 seconds)
For tasks that take longer than 50 seconds, you receive apollUrl immediately:
Request:
status: "pending"
You must then poll the pollUrl until the task completes.
Polling for Results
Polling Endpoint
Poll Until Completion
Poll every 2-3 seconds until you receive a final state: Still Running:Polling Best Practices
1. Poll Interval
Poll every 2-3 seconds. Faster polling wastes resources; slower polling adds unnecessary latency.2. Maximum Attempts
Set a reasonable timeout (e.g., 2 minutes = 60 attempts at 2-second intervals):3. Handle All Terminal States
Check for all possible completion states:4. Track Incremental Cost
The polling endpoint includes current cost in theusage object, allowing you to monitor spending in real-time.
Complete Polling Implementation
Unified Request Handler
Handle both inline and pending responses with a single function:WebSocket Alternative
For real-time updates without polling, use WebSocket:Response Time Distribution
Based on typical usage patterns:| Task Type | Typical Duration | Response Mode |
|---|---|---|
| Simple search | 10-20s | Inline |
| Form filling | 20-40s | Inline |
| Multi-step navigation | 40-80s | Polling |
| Complex workflow | 80-180s | Polling |
Related
Related