Overview
Enigma 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 |
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:
| Field | Type | Description |
|---|---|---|
success | boolean | Request success indicator |
sessionId | string | Session identifier |
taskId | string | Task identifier |
status | string | Task status: "complete" |
result | object | Task result details |
result.type | string | Result type: "task_completed" |
result.data | object | Result data |
result.data.message | string | Task completion message |
result.data.prompt_tokens | number | Input tokens used |
result.data.completion_tokens | number | Output tokens generated |
result.data.total_tokens | number | Total tokens used |
result.data.completion_time | number | Execution time in seconds |
Pending Results (> 50 seconds)
For longer tasks, the response returns immediately with a poll URL. Structure:| Field | Type | Description |
|---|---|---|
success | boolean | Request success indicator |
sessionId | string | Session identifier |
taskId | string | Task identifier for polling |
status | string | Task status: "pending" |
pending | boolean | true when task is still running |
pollUrl | string | URL to poll for task result |
message | string | Instruction to poll for result |
Polling Responses
PollGET /task/:sessionId/:taskId until pending: false or a final type is returned.
Still Running
| Field | Type | Description |
|---|---|---|
success | boolean | Request success indicator |
status | string | "active" - task is running |
pending | boolean | true - continue polling |
usage | object | Current usage statistics |
Task Completed
| Field | Type | Description |
|---|---|---|
success | boolean | Request success indicator |
type | string | "task_completed" |
data | object | Task result data |
data.message | string | Completion message |
data.prompt_tokens | number | Total input tokens |
data.completion_tokens | number | Total output tokens |
data.total_tokens | number | Total tokens |
data.completion_time | number | Execution time in seconds |
usage | object | Final usage statistics |
completedAt | string | ISO 8601 completion timestamp |
Guardrail Triggered
| Field | Type | Description |
|---|---|---|
success | boolean | Request success indicator |
type | string | "guardrail_trigger" |
data | object | Guardrail details |
data.type | string | Guardrail type |
data.value | string | Message explaining what’s needed |
POST /start/send-message:
Task Failed
| Field | Type | Description |
|---|---|---|
success | boolean | false |
status | string | "failed" |
error | string | Error message |
code | string | Error code |
usage | object | Usage statistics up to failure |
Session Creation Response
POST /start/start-session returns session details and streaming configuration.
| Field | Type | Description |
|---|---|---|
success | boolean | Request success indicator |
sessionId | string | Unique session identifier |
socketURL | string | WebSocket connection URL |
streaming | object | Video streaming configuration |
streaming.webRTCURL | string | WebRTC WHEP endpoint |
streaming.webViewURL | string | HTTP video stream URL |
streaming.dimensions | object | Video dimensions |
initialPrompt | string | Initial task provided |
expiresIn | number | Session expiration time (ms) |
balance | number | Current account balance (USD) |
message | string | Additional information |
State Control Response
POST /start/send-message with actionType: "state", "interaction", or "guardrail" returns immediate confirmation.
| Field | Type | Description |
|---|---|---|
success | boolean | Request success indicator |
message | string | Confirmation message |
WebSocket Event Formats
Connect via Socket.IO and listen formessage events:
Event: agent
Live agent thoughts and reasoning during task execution.| Field | Type | Description |
|---|---|---|
type | string | "agent" |
content | string | Agent reasoning text |
Event: action
Browser action performed by the agent.| Field | Type | Description |
|---|---|---|
type | string | "action" |
data | object | Action details |
data.name | string | Action name |
Event: response_update
Status update during task execution.| Field | Type | Description |
|---|---|---|
type | string | "response_update" |
data | object | Update details |
data.message | string | Status message |
Event: task_completed
Task finished successfully.| Field | Type | Description |
|---|---|---|
type | string | "task_completed" |
taskId | string | Task identifier |
data | object | Completion details |
data.message | string | Completion message |
data.prompt_tokens | number | Input tokens used |
data.completion_tokens | number | Output tokens generated |
data.total_tokens | number | Total tokens used |
data.completion_time | number | Execution time (seconds) |
data.usage | object | Usage statistics |
data.usage.cost | number | Cost in USD |
Event: guardrail_trigger
Agent needs human input to continue.| Field | Type | Description |
|---|---|---|
type | string | "guardrail_trigger" |
data | object | Guardrail details |
data.type | string | Guardrail type |
data.value | string | Message explaining what’s needed |
Event: error
Task failed with error.| Field | Type | Description |
|---|---|---|
type | string | "error" |
error | string | Error message |
code | string | Error code |
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 timeout"terminateOnCompletion"- Auto-terminated after task"instance_lost"- Instance connection lost
instance:disconnected
Instance connection lost. Session enters 5-minute grace period for reconnection.instance:reconnected
Instance connection recovered.OpenAI-Compatible Response Formats
Non-Streaming Response
POST /v1/chat/completions with stream: false (default).
| Field | Type | Description |
|---|---|---|
id | string | Completion identifier |
object | string | "chat.completion" |
created | number | Unix timestamp |
model | string | Model name: "enigma-browser-1" |
choices | array | Array of completion choices |
choices[0].index | number | Choice index (always 0) |
choices[0].message | object | Assistant message |
choices[0].message.role | string | "assistant" |
choices[0].message.content | string | Response text |
choices[0].finish_reason | string | "stop" |
usage | object | Token usage statistics |
usage.prompt_tokens | number | Input tokens |
usage.completion_tokens | number | Output tokens |
usage.total_tokens | number | Total tokens |
enigma | object | Enigma-specific metadata |
enigma.sessionId | string | Session identifier |
enigma.taskId | string | Task identifier |
enigma.cost | number | Cost in USD |
Streaming Response (SSE)
POST /v1/chat/completions with stream: true returns Server-Sent Events.
Stream Format:
| Field | Type | Description |
|---|---|---|
id | string | Completion identifier |
object | string | "chat.completion.chunk" |
created | number | Unix timestamp |
model | string | "enigma-browser-1" |
choices | array | Array of delta choices |
choices[0].index | number | Choice index (always 0) |
choices[0].delta | object | Content delta |
choices[0].delta.role | string | "assistant" (first chunk only) |
choices[0].delta.content | string | Text chunk |
choices[0].finish_reason | string | null during stream, "stop" at end |
Error Response Format
All errors follow this standard format:| 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." |
Usage Object Structure
Theusage object appears in many responses and provides token and cost information:
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 |