Synchronous vs Asynchronous
Enigma 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?
The Problem with Pure Sync
Typical HTTP timeouts (30-60 seconds) are too short for complex browser tasks. Forcing all requests to be synchronous would cause frequent timeouts.The Problem with Pure Async
Always requiring polling adds complexity and latency for simple tasks that complete in seconds.The Enigma Solution
Wait up to 50 seconds for task completion. If it finishes in time, return the result immediately. Otherwise, return a poll URL. Result: 90% of tasks get instant responses, 10% use polling only when needed.How It Works
Inline Response (< 50 seconds)
When your task completes within 50 seconds, you get the full result in the initial response: Request:status: "complete"
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 |