## 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 } } ```