Tasks API
Create Task
POST /api/tasksCreate a new task for execution.
Request Body
{
"prompt": "Analyze this contract for liability risks",
"model": "sonnet",
"queue": "default",
"systemPrompt": "You are a senior legal analyst.",
"context": {
"contractText": "...",
"jurisdiction": "New York"
},
"priority": 8,
"timeoutMs": 60000,
"tags": ["legal", "contract-review"],
"maxTokens": 4096,
"temperature": 0.3,
"callbackUrl": "https://your-app.com/webhook",
"idempotencyKey": "unique-request-id-123",
"hitl": {
"required": true,
"confidenceThreshold": 0.85,
"timeoutMs": 3600000
}
}| Field | Type | Required | Description |
|---|---|---|---|
prompt | string | Yes | The prompt to send to the model |
model | string | No | Model identifier. Default: sonnet |
queue | string | No | Task queue. Default: default |
systemPrompt | string | No | System instructions for the model |
context | object | No | Additional context key-value pairs |
priority | number | No | Priority 1-10. Default: 5 |
timeoutMs | number | No | Timeout in ms. Default: 300000 |
tags | string[] | No | Tags for filtering |
maxTokens | number | No | Maximum response tokens |
temperature | number | No | Sampling temperature (0-1) |
callbackUrl | string | No | Webhook URL for completion notification |
idempotencyKey | string | No | Prevents duplicate submissions |
hitl | object | No | HITL configuration |
Response
{
"success": true,
"data": {
"id": "dt_task_abc123",
"status": "pending",
"model": "sonnet",
"queue": "default",
"priority": 8,
"tags": ["legal", "contract-review"],
"createdAt": "2026-02-20T10:00:00Z"
}
}Status Code: 201 Created
Get Task
GET /api/tasks/:idRetrieve details of a specific task.
Response
{
"success": true,
"data": {
"id": "dt_task_abc123",
"status": "completed",
"model": "sonnet",
"queue": "default",
"priority": 8,
"prompt": "Analyze this contract...",
"tags": ["legal", "contract-review"],
"createdAt": "2026-02-20T10:00:00Z",
"startedAt": "2026-02-20T10:00:01Z",
"completedAt": "2026-02-20T10:00:04Z",
"output": "Based on the analysis of the contract...",
"usage": {
"input": 1200,
"output": 856,
"total": 2056,
"totalCost": 0.012
},
"workerId": "worker-asus-gpu",
"retryCount": 0
}
}List Tasks
GET /api/tasksList tasks with optional filtering.
Query Parameters
| Parameter | Type | Description |
|---|---|---|
status | string | Filter by status (comma-separated for multiple) |
model | string | Filter by model |
queue | string | Filter by queue |
tags | string | Filter by tags (comma-separated) |
createdAfter | string | ISO 8601 date |
createdBefore | string | ISO 8601 date |
limit | number | Max results (default: 20, max: 100) |
offset | number | Pagination offset |
orderBy | string | createdAt, completedAt, priority |
order | string | asc or desc |
Example
curl "https://devteam.marsala.dev/api/tasks?status=completed,failed&tags=legal&limit=50&orderBy=createdAt&order=desc" \
-H "Authorization: Bearer $API_KEY"Response
{
"success": true,
"data": [...],
"pagination": {
"total": 150,
"limit": 50,
"offset": 0,
"hasMore": true
}
}Cancel Task
DELETE /api/tasks/:idCancel a pending or running task.
Response
{
"success": true,
"data": {
"id": "dt_task_abc123",
"status": "cancelled",
"cancelledAt": "2026-02-20T10:00:05Z"
}
}⚠️
Cancellation is best-effort for running tasks. The DELETE method returns immediately, but the worker may take a few seconds to stop processing.
Create Batch
POST /api/tasks/batchCreate multiple tasks in a single request.
Request Body
{
"tasks": [
{ "prompt": "Summarize document A", "model": "sonnet" },
{ "prompt": "Summarize document B", "model": "sonnet" },
{ "prompt": "Summarize document C", "model": "sonnet" }
]
}Response
{
"success": true,
"data": {
"batchId": "dt_batch_xyz789",
"tasks": [
{ "id": "dt_task_001", "status": "pending" },
{ "id": "dt_task_002", "status": "pending" },
{ "id": "dt_task_003", "status": "pending" }
],
"total": 3
}
}Webhook Callback
When a task with callbackUrl completes, the API sends a POST request:
{
"event": "task.completed",
"taskId": "dt_task_abc123",
"status": "completed",
"output": "...",
"usage": { "input": 1200, "output": 856 },
"completedAt": "2026-02-20T10:00:04Z",
"signature": "sha256=abc123..."
}Verify the webhook signature:
import { createHmac } from 'crypto';
function verifyWebhook(payload: string, signature: string, secret: string): boolean {
const expected = 'sha256=' + createHmac('sha256', secret).update(payload).digest('hex');
return expected === signature;
}