# Tasks ## Create a task `tasks.create(**kwargs) -> Worker` **post** `/api/tasks` Run a new task against an existing worker and wait for the result. Send a `taskId` of a prior task to add a follow-up turn instead of starting a fresh task. Send `multipart/form-data` to attach files; the bytes are bootstrapped into the worker's workspace before the task starts. The task runs to completion on the server even if the connection drops; subscribe to task webhooks for long-running tasks. ### Parameters - `input: String` - `budget: :low | :standard | :high | :unlimited` Compute budget the worker is allowed to spend on the task. Defaults to `standard`. - `:low` - `:standard` - `:high` - `:unlimited` - `task_id: String` Optional client-provided task id. Reuse this id to add turns to an existing task. - `worker_id: String` Worker id the task belongs to. If omitted, a new worker is created on-the-fly using the input as instructions. ### Returns - `class Worker` - `id: String` - `created_at: Integer` - `error: nil` - `files: Array[File{ filename, media_type, url, size}]` - `filename: String` - `media_type: String` - `url: String` - `size: Integer` - `incomplete_details: nil` - `messages: Array[untyped]` - `metadata: Hash[Symbol, untyped]` - `object: :worker` - `:worker` - `output: Array[Output{ id, content, role, 2 more}]` - `id: String` - `content: Array[Content{ text, type}]` - `text: String` - `type: :output_text` - `:output_text` - `role: :assistant` - `:assistant` - `status: :completed` - `:completed` - `type: :message` - `:message` - `output_text: String` - `running: bool` - `sources: Array[Source{ id, title, type, url}]` - `id: String` - `title: String` - `type: :url` - `:url` - `url: String` - `status: :running | :completed | :pending` - `:running` - `:completed` - `:pending` - `structured_output: Hash[Symbol, untyped]` - `url: String` Web URL of the worker in the Handinger dashboard. - `usage: Usage{ credits, duration_ms}` - `credits: Integer` - `duration_ms: Integer` ### Example ```ruby require "handinger" handinger = Handinger::Client.new(api_key: "My API Key") worker = handinger.tasks.create(input: "What's the weather today in Barcelona?") puts(worker) ``` #### Response ```json { "id": "id", "created_at": 0, "error": null, "files": [ { "filename": "filename", "mediaType": "mediaType", "url": "url", "size": 0 } ], "incomplete_details": null, "messages": [ {} ], "metadata": { "foo": "bar" }, "object": "worker", "output": [ { "id": "id", "content": [ { "text": "text", "type": "output_text" } ], "role": "assistant", "status": "completed", "type": "message" } ], "output_text": "output_text", "running": true, "sources": [ { "id": "id", "title": "title", "type": "url", "url": "url" } ], "status": "running", "structured_output": { "foo": "bar" }, "url": "https://v3.handinger.com/worker/wrk_vk81XUHKHG-qr4", "usage": { "credits": 0, "durationMs": 0 } } ``` ## Retrieve a task with its turns `tasks.retrieve(task_id) -> TaskWithTurns` **get** `/api/tasks/{taskId}` Retrieve a single task and its individual turns. ### Parameters - `task_id: String` ### Returns - `class TaskWithTurns` - `task: Task` - `id: String` - `completed_at: String` - `created_at: String` - `created_by_user_id: String` - `organization_id: String` - `status: :pending | :running | :completed | 2 more` - `:pending` - `:running` - `:completed` - `:error` - `:aborted` - `title: String` - `totals: Totals{ credits, duration_ms, turn_count}` Aggregate credit spend, elapsed wall-clock, and number of turns across the task. - `credits: Integer` - `duration_ms: Integer` - `turn_count: Integer` - `triggered_by: :api | :email | :schedule | :ui` - `:api` - `:email` - `:schedule` - `:ui` - `url: String` Web URL of the task in the Handinger dashboard. - `worker_id: String` - `turns: Array[Turn{ id, completed_at, credits, 11 more}]` - `id: String` - `completed_at: String` - `credits: Integer` - `duration_ms: Integer` - `input: String` - `input_tokens: Integer` - `output_text: String` - `output_tokens: Integer` - `role: String` - `seq: Integer` - `started_at: String` - `status: String` - `structured_output: Hash[Symbol, untyped]` Structured JSON payload when the worker is configured with an output schema. `null` otherwise. - `task_id: String` ### Example ```ruby require "handinger" handinger = Handinger::Client.new(api_key: "My API Key") task_with_turns = handinger.tasks.retrieve("tsk_01HZY31W2SZJ8MJ2FQTR3M1K9D") puts(task_with_turns) ``` #### Response ```json { "task": { "id": "tsk_2Z-YWz3hFq6VlW", "completedAt": "2026-05-11T09:14:48.000Z", "createdAt": "2026-05-11T09:14:22.000Z", "createdByUserId": "usr_7yh-91XzM2nQ4", "organizationId": "org_8s1Df9aLp-1z", "status": "completed", "title": "Weather report for Barcelona", "totals": { "credits": 42, "durationMs": 25812, "turnCount": 1 }, "triggeredBy": "api", "url": "https://v3.handinger.com/worker/wrk_vk81XUHKHG-qr4/task/tsk_2Z-YWz3hFq6VlW", "workerId": "wrk_vk81XUHKHG-qr4" }, "turns": [ { "id": "trn_4Hq-9Vk2pLm8Rx", "completedAt": "2026-05-11T09:14:48.000Z", "credits": 42, "durationMs": 25812, "input": "What's the weather today in Barcelona?", "inputTokens": 1842, "outputText": "It's currently 21°C and sunny in Barcelona with a light breeze from the south-east.", "outputTokens": 312, "role": "user", "seq": 0, "startedAt": "2026-05-11T09:14:22.000Z", "status": "completed", "structuredOutput": { "temperatureCelsius": "bar", "conditions": "bar" }, "taskId": "tsk_2Z-YWz3hFq6VlW" } ] } ``` ## Archive a task `tasks.delete(task_id) -> DeleteTaskResponse` **delete** `/api/tasks/{taskId}` Archive a task so it stops appearing in `GET /tasks` results. Turns and files are retained for audit purposes. Only the worker creator can archive a task. ### Parameters - `task_id: String` ### Returns - `class DeleteTaskResponse` - `archived: bool` ### Example ```ruby require "handinger" handinger = Handinger::Client.new(api_key: "My API Key") delete_task_response = handinger.tasks.delete("tsk_01HZY31W2SZJ8MJ2FQTR3M1K9D") puts(delete_task_response) ``` #### Response ```json { "archived": true } ``` ## Domain Types ### Create Task - `class CreateTask` - `input: String` - `budget: :low | :standard | :high | :unlimited` Compute budget the worker is allowed to spend on the task. Defaults to `standard`. - `:low` - `:standard` - `:high` - `:unlimited` - `task_id: String` Optional client-provided task id. Reuse this id to add turns to an existing task. - `worker_id: String` Worker id the task belongs to. If omitted, a new worker is created on-the-fly using the input as instructions. ### Delete Task Response - `class DeleteTaskResponse` - `archived: bool` ### Task - `class Task` - `id: String` - `completed_at: String` - `created_at: String` - `created_by_user_id: String` - `organization_id: String` - `status: :pending | :running | :completed | 2 more` - `:pending` - `:running` - `:completed` - `:error` - `:aborted` - `title: String` - `totals: Totals{ credits, duration_ms, turn_count}` Aggregate credit spend, elapsed wall-clock, and number of turns across the task. - `credits: Integer` - `duration_ms: Integer` - `turn_count: Integer` - `triggered_by: :api | :email | :schedule | :ui` - `:api` - `:email` - `:schedule` - `:ui` - `url: String` Web URL of the task in the Handinger dashboard. - `worker_id: String` ### Task With Turns - `class TaskWithTurns` - `task: Task` - `id: String` - `completed_at: String` - `created_at: String` - `created_by_user_id: String` - `organization_id: String` - `status: :pending | :running | :completed | 2 more` - `:pending` - `:running` - `:completed` - `:error` - `:aborted` - `title: String` - `totals: Totals{ credits, duration_ms, turn_count}` Aggregate credit spend, elapsed wall-clock, and number of turns across the task. - `credits: Integer` - `duration_ms: Integer` - `turn_count: Integer` - `triggered_by: :api | :email | :schedule | :ui` - `:api` - `:email` - `:schedule` - `:ui` - `url: String` Web URL of the task in the Handinger dashboard. - `worker_id: String` - `turns: Array[Turn{ id, completed_at, credits, 11 more}]` - `id: String` - `completed_at: String` - `credits: Integer` - `duration_ms: Integer` - `input: String` - `input_tokens: Integer` - `output_text: String` - `output_tokens: Integer` - `role: String` - `seq: Integer` - `started_at: String` - `status: String` - `structured_output: Hash[Symbol, untyped]` Structured JSON payload when the worker is configured with an output schema. `null` otherwise. - `task_id: String`