# Tasks ## Create a task `client.Tasks.New(ctx, body) (*Worker, error)` **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 - `body TaskNewParams` - `CreateTask param.Field[CreateTask]` ### Returns - `type Worker struct{…}` - `ID string` - `CreatedAt int64` - `Error any` - `Files []WorkerFile` - `Filename string` - `MediaType string` - `URL string` - `Size int64` - `IncompleteDetails any` - `Messages []any` - `Metadata map[string, any]` - `Object Worker` - `const WorkerWorker Worker = "worker"` - `Output []WorkerOutput` - `ID string` - `Content []WorkerOutputContent` - `Text string` - `Type OutputText` - `const OutputTextOutputText OutputText = "output_text"` - `Role Assistant` - `const AssistantAssistant Assistant = "assistant"` - `Status Completed` - `const CompletedCompleted Completed = "completed"` - `Type Message` - `const MessageMessage Message = "message"` - `OutputText string` - `Running bool` - `Sources []WorkerSource` - `ID string` - `Title string` - `Type URL` - `const URLURL URL = "url"` - `URL string` - `Status WorkerStatus` - `const WorkerStatusRunning WorkerStatus = "running"` - `const WorkerStatusCompleted WorkerStatus = "completed"` - `const WorkerStatusPending WorkerStatus = "pending"` - `StructuredOutput map[string, any]` - `URL string` Web URL of the worker in the Handinger dashboard. - `Usage WorkerUsage` - `DurationMs int64` ### Example ```go package main import ( "context" "fmt" "github.com/ramensoft/handinger-go" "github.com/ramensoft/handinger-go/option" ) func main() { client := handinger.NewClient( option.WithAPIKey("My API Key"), ) worker, err := client.Tasks.New(context.TODO(), handinger.TaskNewParams{ CreateTask: handinger.CreateTaskParam{ Input: "What's the weather today in Barcelona?", }, }) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", worker.ID) } ``` #### Response ```json { "id": "id", "created_at": 0, "error": null, "files": [ { "filename": "filename", "mediaType": "mediaType", "url": "https://example.com", "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": { "durationMs": 0 } } ``` ## Retrieve a task `client.Tasks.Get(ctx, taskID) (*TaskGetResponse, error)` **get** `/api/tasks/{taskId}` Retrieve a single task. ### Parameters - `taskID string` ### Returns - `type TaskGetResponse struct{…}` - `Task Task` - `ID string` - `CompletedAt string` - `CreatedAt string` - `CreatedByUserID string` - `OrganizationID string` - `Status TaskStatus` - `const TaskStatusPending TaskStatus = "pending"` - `const TaskStatusRunning TaskStatus = "running"` - `const TaskStatusCompleted TaskStatus = "completed"` - `const TaskStatusError TaskStatus = "error"` - `const TaskStatusAborted TaskStatus = "aborted"` - `Title string` - `Totals TaskTotals` Aggregate credit spend, elapsed wall-clock, and number of turns across the task. - `Credits int64` - `DurationMs int64` - `TurnCount int64` - `TriggeredBy TaskTriggeredBy` - `const TaskTriggeredByAPI TaskTriggeredBy = "api"` - `const TaskTriggeredByEmail TaskTriggeredBy = "email"` - `const TaskTriggeredBySchedule TaskTriggeredBy = "schedule"` - `const TaskTriggeredByUi TaskTriggeredBy = "ui"` - `URL string` Web URL of the task in the Handinger dashboard. - `WorkerID string` ### Example ```go package main import ( "context" "fmt" "github.com/ramensoft/handinger-go" "github.com/ramensoft/handinger-go/option" ) func main() { client := handinger.NewClient( option.WithAPIKey("My API Key"), ) task, err := client.Tasks.Get(context.TODO(), "tsk_01HZY31W2SZJ8MJ2FQTR3M1K9D") if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", task.Task) } ``` #### 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" } } ``` ## List task turns `client.Tasks.ListTurns(ctx, taskID) (*TaskTurnList, error)` **get** `/api/tasks/{taskId}/turns` List the individual turns for a task in execution order. ### Parameters - `taskID string` ### Returns - `type TaskTurnList struct{…}` - `Items []Turn` - `ID string` - `CompletedAt string` - `Credits int64` - `DurationMs int64` - `Files []TurnFile` Files published by this turn. - `Filename string` - `MediaType string` - `URL string` - `Size int64` - `Input string` - `InputTokens int64` - `OutputText string` - `OutputTokens int64` - `Role string` - `Seq int64` - `StartedAt string` - `Status string` - `StructuredOutput map[string, any]` Structured JSON payload when the worker is configured with an output schema. `null` otherwise. - `TaskID string` - `TaskID string` ### Example ```go package main import ( "context" "fmt" "github.com/ramensoft/handinger-go" "github.com/ramensoft/handinger-go/option" ) func main() { client := handinger.NewClient( option.WithAPIKey("My API Key"), ) taskTurnList, err := client.Tasks.ListTurns(context.TODO(), "tsk_01HZY31W2SZJ8MJ2FQTR3M1K9D") if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", taskTurnList.Items) } ``` #### Response ```json { "items": [ { "id": "trn_4Hq-9Vk2pLm8Rx", "completedAt": "2026-05-11T09:14:48.000Z", "credits": 42, "durationMs": 25812, "files": [ { "filename": "filename", "mediaType": "mediaType", "url": "https://example.com", "size": 0 } ], "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": "assistant", "seq": 0, "startedAt": "2026-05-11T09:14:22.000Z", "status": "completed", "structuredOutput": { "temperatureCelsius": "bar", "conditions": "bar" }, "taskId": "tsk_2Z-YWz3hFq6VlW" } ], "taskId": "tsk_2Z-YWz3hFq6VlW" } ``` ## Archive a task `client.Tasks.Delete(ctx, taskID) (*DeleteTaskResponse, error)` **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 - `taskID string` ### Returns - `type DeleteTaskResponse struct{…}` - `Archived bool` ### Example ```go package main import ( "context" "fmt" "github.com/ramensoft/handinger-go" "github.com/ramensoft/handinger-go/option" ) func main() { client := handinger.NewClient( option.WithAPIKey("My API Key"), ) deleteTaskResponse, err := client.Tasks.Delete(context.TODO(), "tsk_01HZY31W2SZJ8MJ2FQTR3M1K9D") if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", deleteTaskResponse.Archived) } ``` #### Response ```json { "archived": true } ``` ## Domain Types ### Create Task - `type CreateTask struct{…}` - `Input string` - `Budget CreateTaskBudget` Compute budget the worker is allowed to spend on the task. Defaults to `standard`. - `const CreateTaskBudgetLow CreateTaskBudget = "low"` - `const CreateTaskBudgetStandard CreateTaskBudget = "standard"` - `const CreateTaskBudgetHigh CreateTaskBudget = "high"` - `const CreateTaskBudgetUnlimited CreateTaskBudget = "unlimited"` - `TaskID string` Optional client-provided task id. Reuse this id to add turns to an existing task. - `WorkerID 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 - `type DeleteTaskResponse struct{…}` - `Archived bool` ### Task - `type Task struct{…}` - `ID string` - `CompletedAt string` - `CreatedAt string` - `CreatedByUserID string` - `OrganizationID string` - `Status TaskStatus` - `const TaskStatusPending TaskStatus = "pending"` - `const TaskStatusRunning TaskStatus = "running"` - `const TaskStatusCompleted TaskStatus = "completed"` - `const TaskStatusError TaskStatus = "error"` - `const TaskStatusAborted TaskStatus = "aborted"` - `Title string` - `Totals TaskTotals` Aggregate credit spend, elapsed wall-clock, and number of turns across the task. - `Credits int64` - `DurationMs int64` - `TurnCount int64` - `TriggeredBy TaskTriggeredBy` - `const TaskTriggeredByAPI TaskTriggeredBy = "api"` - `const TaskTriggeredByEmail TaskTriggeredBy = "email"` - `const TaskTriggeredBySchedule TaskTriggeredBy = "schedule"` - `const TaskTriggeredByUi TaskTriggeredBy = "ui"` - `URL string` Web URL of the task in the Handinger dashboard. - `WorkerID string` ### Task Turn List - `type TaskTurnList struct{…}` - `Items []Turn` - `ID string` - `CompletedAt string` - `Credits int64` - `DurationMs int64` - `Files []TurnFile` Files published by this turn. - `Filename string` - `MediaType string` - `URL string` - `Size int64` - `Input string` - `InputTokens int64` - `OutputText string` - `OutputTokens int64` - `Role string` - `Seq int64` - `StartedAt string` - `Status string` - `StructuredOutput map[string, any]` Structured JSON payload when the worker is configured with an output schema. `null` otherwise. - `TaskID string` - `TaskID string` ### Turn - `type Turn struct{…}` - `ID string` - `CompletedAt string` - `Credits int64` - `DurationMs int64` - `Files []TurnFile` Files published by this turn. - `Filename string` - `MediaType string` - `URL string` - `Size int64` - `Input string` - `InputTokens int64` - `OutputText string` - `OutputTokens int64` - `Role string` - `Seq int64` - `StartedAt string` - `Status string` - `StructuredOutput map[string, any]` Structured JSON payload when the worker is configured with an output schema. `null` otherwise. - `TaskID string`