{
  "openapi": "3.0.3",
  "info": {
    "title": "Tasks API",
    "version": "1.0.0",
    "description": "Run tasks with an agent, follow them and fetch their outputs, upload the files they work on, and select workflows for a case. Every operation needs a task API key that carries the capability it names."
  },
  "servers": [
    {
      "url": "https://{deployment}/api/v1",
      "description": "Your Context deployment",
      "variables": {
        "deployment": {
          "default": "context.example.com",
          "description": "The host your organization signs in to"
        }
      }
    }
  ],
  "security": [
    {
      "TaskApiKey": []
    }
  ],
  "tags": [
    {
      "name": "Tasks",
      "description": "Start a task, send it more prompts, follow its status, and fetch its result, share link and output files."
    },
    {
      "name": "Task roots",
      "description": "Read, rename and cancel top-level tasks, including tasks started in the app rather than through this API."
    },
    {
      "name": "Files",
      "description": "Upload a file for a task to work on, then check that the upload finished before you attach it to a prompt or task."
    },
    {
      "name": "Workflow selection",
      "description": "Ask which saved workflows fit a case, with the results grouped by workspace."
    }
  ],
  "components": {
    "securitySchemes": {
      "TaskApiKey": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "tsk_<prefix>_<secret>",
        "description": "Task API key carrying the capability named on each operation. Create keys from Settings → API → Task keys."
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "string",
            "description": "Human-readable error message"
          },
          "code": {
            "type": "string",
            "description": "Optional machine-readable error code"
          },
          "details": {
            "description": "Optional per-field validation details"
          }
        }
      }
    }
  },
  "paths": {
    "/files": {
      "post": {
        "tags": [
          "Files"
        ],
        "summary": "Start a file upload",
        "description": "Returns a `PUT` URL that expires at `upload.expiresAt`. Upload the file's bytes there with no other credentials, then poll `GET /files/{fileId}` until its status is `uploaded`; pass the `fileId` to a prompt or task to attach it. The file is stored in the key owner's Drive.",
        "operationId": "createFileUpload",
        "parameters": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "namespace": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 128,
                    "description": "Optional namespace override; defaults from key scope"
                  },
                  "ownerUserId": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Optional execution owner override by user ID. Service keys may set this. Mutually exclusive with ownerUserEmail."
                  },
                  "ownerUserEmail": {
                    "type": "string",
                    "format": "email",
                    "description": "Optional execution owner override by user email; resolved within the task key's organization. Service keys may set this. Mutually exclusive with ownerUserId."
                  },
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 512,
                    "description": "Original filename"
                  },
                  "contentType": {
                    "type": "string",
                    "minLength": 1,
                    "description": "MIME type for upload signing"
                  },
                  "sizeBytes": {
                    "type": "integer",
                    "exclusiveMinimum": true,
                    "minimum": 0,
                    "description": "Optional expected size in bytes"
                  }
                },
                "required": [
                  "name"
                ],
                "additionalProperties": false,
                "description": "Input for task file upload initialization"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "The file record and its upload URL.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "fileId": {
                      "type": "string",
                      "minLength": 1,
                      "description": "Opaque task file identifier"
                    },
                    "namespace": {
                      "type": "string",
                      "minLength": 1,
                      "description": "Resolved namespace"
                    },
                    "status": {
                      "type": "string",
                      "enum": [
                        "pending",
                        "uploaded",
                        "failed"
                      ],
                      "description": "Task file upload status"
                    },
                    "upload": {
                      "type": "object",
                      "properties": {
                        "method": {
                          "type": "string",
                          "enum": [
                            "PUT"
                          ]
                        },
                        "url": {
                          "type": "string",
                          "format": "uri"
                        },
                        "expiresAt": {
                          "type": "string",
                          "format": "date-time"
                        }
                      },
                      "required": [
                        "method",
                        "url",
                        "expiresAt"
                      ],
                      "additionalProperties": false
                    }
                  },
                  "required": [
                    "fileId",
                    "namespace",
                    "status",
                    "upload"
                  ],
                  "additionalProperties": false,
                  "description": "Task file upload initialization result"
                }
              }
            }
          },
          "400": {
            "description": "The request is invalid: a field failed validation (`details` lists the issues), or it was refused as a client error (`code` names the refusal where the route reports one).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "No valid task API key. Send `Authorization: Bearer tsk_…`.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The key lacks the `files:write` capability, or its principal may not act on this resource.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found in the key's organization.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "The resource is in a state that refuses this request (`code` names the conflict where the route reports one).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unexpected server error (`code` is `TASK_API_INTERNAL_ERROR`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Open work has not caught up yet; retry shortly (`code` is `NATIVE_OPEN_WORK_NOT_CAUGHT_UP`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/files/{fileId}": {
      "get": {
        "tags": [
          "Files"
        ],
        "summary": "Get a file's upload status",
        "description": "Returns the metadata of a file uploaded with `POST /files`, with its upload status. A key reads files it created and files owned by the person it acts for.",
        "operationId": "getFileStatus",
        "parameters": [
          {
            "in": "path",
            "name": "fileId",
            "required": true,
            "description": "The file's id.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The file's metadata and upload status.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "fileId": {
                      "type": "string",
                      "minLength": 1
                    },
                    "namespace": {
                      "type": "string",
                      "minLength": 1
                    },
                    "name": {
                      "type": "string",
                      "minLength": 1
                    },
                    "contentType": {
                      "type": "string",
                      "nullable": true
                    },
                    "sizeBytes": {
                      "type": "integer",
                      "minimum": 0,
                      "nullable": true
                    },
                    "status": {
                      "type": "string",
                      "enum": [
                        "pending",
                        "uploaded",
                        "failed"
                      ],
                      "description": "Task file upload status"
                    },
                    "drivePath": {
                      "type": "string",
                      "minLength": 1
                    },
                    "createdAt": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "updatedAt": {
                      "type": "string",
                      "format": "date-time"
                    }
                  },
                  "required": [
                    "fileId",
                    "namespace",
                    "name",
                    "contentType",
                    "sizeBytes",
                    "status",
                    "drivePath",
                    "createdAt",
                    "updatedAt"
                  ],
                  "additionalProperties": false,
                  "description": "Task file metadata and upload status"
                }
              }
            }
          },
          "400": {
            "description": "The request is invalid: a field failed validation (`details` lists the issues), or it was refused as a client error (`code` names the refusal where the route reports one).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "No valid task API key. Send `Authorization: Bearer tsk_…`.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The key lacks the `files:read` capability, or its principal may not act on this resource.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found in the key's organization.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "The resource is in a state that refuses this request (`code` names the conflict where the route reports one).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unexpected server error (`code` is `TASK_API_INTERNAL_ERROR`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Open work has not caught up yet; retry shortly (`code` is `NATIVE_OPEN_WORK_NOT_CAUGHT_UP`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/tasks": {
      "post": {
        "tags": [
          "Tasks"
        ],
        "summary": "Create a task",
        "description": "Send a unique `Idempotency-Key` header: repeating the request with the same key returns the task it already created (200) instead of creating another (202).",
        "operationId": "createTask",
        "parameters": [
          {
            "in": "header",
            "name": "Idempotency-Key",
            "required": true,
            "description": "A unique key for this create. A repeat with the same key returns the task already created.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "namespace": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 128,
                    "description": "Optional namespace; defaults from task key scope"
                  },
                  "ownerUserId": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Optional execution owner override by user ID. Service keys may set this. Mutually exclusive with ownerUserEmail."
                  },
                  "ownerUserEmail": {
                    "type": "string",
                    "format": "email",
                    "description": "Optional execution owner override by user email; resolved within the task key's organization. Service keys may set this. Mutually exclusive with ownerUserId."
                  },
                  "agentId": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Target agent ID"
                  },
                  "title": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 280,
                    "description": "Optional user-facing task title to preserve on root task creation"
                  },
                  "skillInlineContent": {
                    "type": "object",
                    "properties": {
                      "skillId": {
                        "type": "string",
                        "minLength": 1,
                        "description": "Skill whose content is being overridden for this dispatch"
                      },
                      "content": {
                        "type": "string",
                        "description": "Inline skill markdown that replaces the storagePath lookup for skillId"
                      }
                    },
                    "required": [
                      "skillId",
                      "content"
                    ],
                    "additionalProperties": false,
                    "description": "Service-principal-only override that supplies skill markdown inline. Rejected on user-typed task keys."
                  },
                  "outputSchema": {
                    "description": "JSON Schema (draft-07 subset) the task's answer must satisfy. YOU declare it, because you are the one who will parse the result — the agent never chooses its own output shape. The schema is rendered into the agent's context, and the agent submits its answer with `context-cli task submit-output`; the server validates it and hands back per-field errors the agent corrects inside the same turn. The validated document comes back as `output.structured`. A task that declares this and finishes without an accepted submission is reported as FAILED with TASK_STRUCTURED_OUTPUT_MISSING — never as a success with a null answer. Unsupported in this subset (rejected at declaration time with guidance): $ref/$defs, pattern, format, and allOf/anyOf/oneOf/not/if. Use `type: [\"string\", \"null\"]` for nullable fields."
                  },
                  "workspaceId": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Optional workspace context that the task run should inherit when known"
                  },
                  "delivery": {
                    "type": "object",
                    "properties": {
                      "type": {
                        "type": "string",
                        "enum": [
                          "webhook"
                        ]
                      },
                      "config": {
                        "type": "object",
                        "properties": {
                          "endpoint": {
                            "type": "string",
                            "format": "uri",
                            "description": "Webhook URL that receives terminal task updates"
                          },
                          "signingSecret": {
                            "type": "string",
                            "minLength": 16,
                            "description": "HMAC signing secret used for webhook signatures"
                          },
                          "frequency": {
                            "type": "string",
                            "enum": [
                              "on_finish"
                            ],
                            "default": "on_finish",
                            "description": "Delivery trigger frequency"
                          }
                        },
                        "required": [
                          "endpoint",
                          "signingSecret"
                        ],
                        "additionalProperties": false,
                        "description": "Webhook delivery configuration"
                      }
                    },
                    "required": [
                      "type",
                      "config"
                    ],
                    "additionalProperties": false
                  },
                  "input": {
                    "type": "object",
                    "properties": {
                      "type": {
                        "type": "string",
                        "enum": [
                          "chat"
                        ]
                      },
                      "prompt": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 100000
                      },
                      "fileIds": {
                        "type": "array",
                        "items": {
                          "type": "string",
                          "minLength": 1
                        },
                        "default": []
                      },
                      "skills": {
                        "type": "array",
                        "items": {
                          "type": "object",
                          "properties": {
                            "skillId": {
                              "type": "string",
                              "minLength": 1,
                              "description": "Skill identifier"
                            },
                            "versionId": {
                              "type": "string",
                              "minLength": 1,
                              "nullable": true,
                              "description": "Optional skill version ID to pin for deterministic behavior"
                            }
                          },
                          "required": [
                            "skillId"
                          ],
                          "additionalProperties": false,
                          "description": "Skill reference used by a task"
                        },
                        "default": []
                      },
                      "model": {
                        "type": "object",
                        "properties": {
                          "providerID": {
                            "type": "string",
                            "minLength": 1,
                            "description": "Configured provider identifier from the agent config"
                          },
                          "modelID": {
                            "type": "string",
                            "minLength": 1,
                            "description": "Configured model identifier within the selected provider"
                          }
                        },
                        "required": [
                          "providerID",
                          "modelID"
                        ],
                        "additionalProperties": false,
                        "description": "Explicit provider/model override for prompt execution",
                        "nullable": true,
                        "default": null
                      },
                      "variant": {
                        "type": "string",
                        "minLength": 1,
                        "description": "Optional configured model variant override",
                        "nullable": true,
                        "default": null
                      },
                      "sessionId": {
                        "type": "string",
                        "minLength": 1,
                        "description": "Optional existing task-runtime-managed session for follow-up"
                      }
                    },
                    "required": [
                      "type",
                      "prompt"
                    ],
                    "additionalProperties": false,
                    "description": "Task prompt input payload"
                  }
                },
                "required": [
                  "agentId",
                  "delivery",
                  "input"
                ],
                "additionalProperties": false,
                "description": "Task creation request payload"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Idempotent replay: the task this `Idempotency-Key` already created.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "taskId": {
                      "type": "string",
                      "format": "uuid",
                      "description": "Created task identifier"
                    },
                    "taskDispatchRunId": {
                      "type": "string",
                      "minLength": 1,
                      "description": "Canonical Task API dispatch-run identifier for this task request"
                    },
                    "namespace": {
                      "type": "string",
                      "minLength": 1
                    },
                    "status": {
                      "type": "string",
                      "enum": [
                        "queued",
                        "running",
                        "succeeded",
                        "failed",
                        "cancelled"
                      ],
                      "description": "Task dispatch run lifecycle status"
                    },
                    "createdAt": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "location": {
                      "type": "string",
                      "minLength": 1,
                      "description": "Relative URL for polling task state"
                    }
                  },
                  "required": [
                    "taskId",
                    "namespace",
                    "status",
                    "createdAt",
                    "location"
                  ],
                  "additionalProperties": false,
                  "description": "Task creation response"
                }
              }
            }
          },
          "202": {
            "description": "The task was created and is being dispatched.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "taskId": {
                      "type": "string",
                      "format": "uuid",
                      "description": "Created task identifier"
                    },
                    "taskDispatchRunId": {
                      "type": "string",
                      "minLength": 1,
                      "description": "Canonical Task API dispatch-run identifier for this task request"
                    },
                    "namespace": {
                      "type": "string",
                      "minLength": 1
                    },
                    "status": {
                      "type": "string",
                      "enum": [
                        "queued",
                        "running",
                        "succeeded",
                        "failed",
                        "cancelled"
                      ],
                      "description": "Task dispatch run lifecycle status"
                    },
                    "createdAt": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "location": {
                      "type": "string",
                      "minLength": 1,
                      "description": "Relative URL for polling task state"
                    }
                  },
                  "required": [
                    "taskId",
                    "namespace",
                    "status",
                    "createdAt",
                    "location"
                  ],
                  "additionalProperties": false,
                  "description": "Task creation response"
                }
              }
            }
          },
          "400": {
            "description": "The request is invalid: the `Idempotency-Key` header is missing, or a field failed validation (`details` lists the issues).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "No valid task API key. Send `Authorization: Bearer tsk_…`.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The key lacks the `tasks:create` capability, or its principal may not act on this resource.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found in the key's organization.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "The resource is in a state that refuses this request (`code` names the conflict where the route reports one).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unexpected server error (`code` is `TASK_API_INTERNAL_ERROR`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Open work has not caught up yet; retry shortly (`code` is `NATIVE_OPEN_WORK_NOT_CAUGHT_UP`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "get": {
        "tags": [
          "Tasks"
        ],
        "summary": "List tasks",
        "description": "Pages through the key's tasks. Pass the returned cursor back as `cursor` for the next page; a cursor that no longer reads answers 400 with `code` `TASK_LIST_CURSOR_INVALID` (restart without it).",
        "operationId": "listTasks",
        "parameters": [
          {
            "in": "query",
            "name": "cursor",
            "required": false,
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "Opaque keyset cursor from the previous page's nextCursor"
            }
          },
          {
            "in": "query",
            "name": "limit",
            "required": false,
            "schema": {
              "type": "integer",
              "exclusiveMinimum": true,
              "minimum": 0,
              "maximum": 100,
              "description": "Page size (default 50, max 100)"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "A page of tasks.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "taskId": {
                            "type": "string",
                            "format": "uuid"
                          },
                          "taskDispatchRunId": {
                            "type": "string",
                            "minLength": 1,
                            "description": "Canonical Task API dispatch-run identifier"
                          },
                          "taskRunId": {
                            "type": "string",
                            "minLength": 1,
                            "nullable": true,
                            "description": "Runtime task-run identifier when the task has reached runtime execution"
                          },
                          "runtimeTaskId": {
                            "type": "string",
                            "minLength": 1,
                            "nullable": true,
                            "description": "Runtime task-tree task identifier when the task has reached runtime execution"
                          },
                          "rootTaskId": {
                            "type": "string",
                            "minLength": 1,
                            "nullable": true,
                            "description": "Root runtime task identifier used to correlate a whole task tree"
                          },
                          "orgId": {
                            "type": "string",
                            "minLength": 1
                          },
                          "namespace": {
                            "type": "string",
                            "minLength": 1
                          },
                          "title": {
                            "type": "string",
                            "nullable": true,
                            "description": "Human-facing task title, read through from the linked task row and falling back to the dispatch row's stored title"
                          },
                          "agentId": {
                            "type": "string",
                            "minLength": 1
                          },
                          "sessionId": {
                            "type": "string",
                            "nullable": true
                          },
                          "taskOpencodeBranchId": {
                            "type": "string",
                            "nullable": true,
                            "description": "Stable OpenCode branch ID backing the task conversation"
                          },
                          "taskLink": {
                            "type": "string",
                            "nullable": true,
                            "description": "Relative browser path for opening the task conversation in the workspace UI"
                          },
                          "status": {
                            "type": "string",
                            "enum": [
                              "queued",
                              "running",
                              "succeeded",
                              "failed",
                              "cancelled"
                            ],
                            "description": "Task dispatch run lifecycle status"
                          },
                          "createdAt": {
                            "type": "string",
                            "format": "date-time"
                          },
                          "startedAt": {
                            "type": "string",
                            "format": "date-time",
                            "nullable": true
                          },
                          "completedAt": {
                            "type": "string",
                            "format": "date-time",
                            "nullable": true
                          },
                          "costUsd": {
                            "type": "number",
                            "minimum": 0,
                            "nullable": true,
                            "description": "Model spend of the whole run this task ran on (its turns, follow-ups and sub-agents), from the billing ledger. Null until the run's calls have ended and the ledger is final past them, or when the spend cannot be stated; costUnknownReason says which. A run that settles after it parked reads null again until the ledger is final past the settle. A later LiteLLM re-rate (a signed correction row) can still move a final figure, down as well as up."
                          },
                          "costUnknownReason": {
                            "type": "string",
                            "enum": [
                              "ledger_not_final",
                              "device_calls_unbounded",
                              "no_rows",
                              "unrated_rows",
                              "run_live",
                              "run_resumable",
                              "run_shared_by_dispatches",
                              "unbound",
                              "ledger_net_negative"
                            ],
                            "description": "Why costUsd is null. ledger_not_final: the billing ledger has not yet recorded every call that started before the run's calls ended. no_rows: the billing ledger holds no model call for the run. unrated_rows: a model call of the run carries no price. run_live: a model call can still be made on the run. run_resumable: the run is paused and its next start resumes it, so its spend can still grow. device_calls_unbounded: This task ran on a paired machine; its cost is still counting and isn't shown as final yet. run_shared_by_dispatches: more than one task is bound to the run, so no one task's share can be stated; the run-level spend is a separate follow-up (issue #6604). unbound: the task is bound to no run (it never started, or it ran on a paired machine without one). ledger_net_negative: the billing ledger's corrections leave the run below zero, which is a ledger fault."
                          },
                          "output": {
                            "type": "object",
                            "properties": {
                              "text": {
                                "type": "string",
                                "description": "Task textual output"
                              },
                              "files": {
                                "type": "array",
                                "items": {
                                  "type": "object",
                                  "properties": {
                                    "id": {
                                      "type": "string",
                                      "minLength": 1,
                                      "description": "Stable output file identifier within the task run"
                                    },
                                    "uri": {
                                      "type": "string",
                                      "pattern": "^org\\_drive\\:\\/\\/",
                                      "description": "Canonical org Drive URI for this file"
                                    },
                                    "name": {
                                      "type": "string",
                                      "minLength": 1,
                                      "description": "Display filename"
                                    },
                                    "source": {
                                      "type": "string",
                                      "enum": [
                                        "input",
                                        "generated"
                                      ],
                                      "description": "Whether the file was attached as input or generated by the task run"
                                    },
                                    "contentType": {
                                      "type": "string",
                                      "nullable": true,
                                      "description": "MIME type"
                                    },
                                    "sizeBytes": {
                                      "type": "integer",
                                      "minimum": 0,
                                      "nullable": true,
                                      "description": "File size in bytes"
                                    }
                                  },
                                  "required": [
                                    "id",
                                    "uri",
                                    "name",
                                    "source",
                                    "contentType",
                                    "sizeBytes"
                                  ],
                                  "additionalProperties": false,
                                  "description": "File reference returned as task output context"
                                },
                                "description": "Referenced or generated file references"
                              },
                              "appliedSkills": {
                                "type": "array",
                                "items": {
                                  "type": "object",
                                  "properties": {
                                    "skillId": {
                                      "type": "string",
                                      "minLength": 1,
                                      "description": "Skill identifier"
                                    },
                                    "versionId": {
                                      "type": "string",
                                      "minLength": 1,
                                      "nullable": true,
                                      "description": "Optional skill version ID to pin for deterministic behavior"
                                    }
                                  },
                                  "required": [
                                    "skillId"
                                  ],
                                  "additionalProperties": false,
                                  "description": "Skill reference used by a task"
                                },
                                "description": "Skills this run used, as recorded from its tool calls; a skill only requested or listed is not here"
                              },
                              "structured": {
                                "description": "Validated structured answer; present only when the request declared an outputSchema"
                              }
                            },
                            "required": [
                              "text",
                              "files",
                              "appliedSkills"
                            ],
                            "additionalProperties": false,
                            "description": "Task success result payload"
                          },
                          "error": {
                            "type": "object",
                            "properties": {
                              "code": {
                                "type": "string",
                                "minLength": 1,
                                "description": "Machine-readable error code"
                              },
                              "message": {
                                "type": "string",
                                "minLength": 1,
                                "description": "Human-readable error message"
                              }
                            },
                            "required": [
                              "code",
                              "message"
                            ],
                            "additionalProperties": false,
                            "description": "Task failure payload"
                          },
                          "postTurnScript": {
                            "anyOf": [
                              {
                                "type": "object",
                                "properties": {
                                  "status": {
                                    "type": "string",
                                    "enum": [
                                      "not_registered"
                                    ]
                                  }
                                },
                                "required": [
                                  "status"
                                ],
                                "additionalProperties": false
                              },
                              {
                                "type": "object",
                                "properties": {
                                  "status": {
                                    "type": "string",
                                    "enum": [
                                      "pending",
                                      "running"
                                    ]
                                  }
                                },
                                "required": [
                                  "status"
                                ],
                                "additionalProperties": false
                              },
                              {
                                "type": "object",
                                "properties": {
                                  "status": {
                                    "type": "string",
                                    "enum": [
                                      "completed"
                                    ]
                                  },
                                  "process": {
                                    "anyOf": [
                                      {
                                        "type": "object",
                                        "properties": {
                                          "version": {
                                            "type": "number",
                                            "enum": [
                                              1
                                            ]
                                          },
                                          "stdout": {
                                            "type": "string",
                                            "maxLength": 8192
                                          },
                                          "stderr": {
                                            "type": "string",
                                            "maxLength": 8192
                                          },
                                          "stdoutTruncated": {
                                            "type": "boolean",
                                            "description": "The machine-result stream exceeded its 8 KiB capture limit"
                                          },
                                          "stderrTruncated": {
                                            "type": "boolean",
                                            "description": "Diagnostics exceeded their 2 KiB capture limit; does not imply the machine result was truncated"
                                          },
                                          "status": {
                                            "type": "string",
                                            "enum": [
                                              "exited"
                                            ]
                                          },
                                          "exitCode": {
                                            "type": "integer",
                                            "minimum": 0,
                                            "maximum": 255
                                          }
                                        },
                                        "required": [
                                          "version",
                                          "stdout",
                                          "stderr",
                                          "stdoutTruncated",
                                          "stderrTruncated",
                                          "status",
                                          "exitCode"
                                        ],
                                        "additionalProperties": false
                                      },
                                      {
                                        "type": "object",
                                        "properties": {
                                          "version": {
                                            "type": "number",
                                            "enum": [
                                              1
                                            ]
                                          },
                                          "stdout": {
                                            "type": "string",
                                            "maxLength": 8192
                                          },
                                          "stderr": {
                                            "type": "string",
                                            "maxLength": 8192
                                          },
                                          "stdoutTruncated": {
                                            "type": "boolean",
                                            "description": "The machine-result stream exceeded its 8 KiB capture limit"
                                          },
                                          "stderrTruncated": {
                                            "type": "boolean",
                                            "description": "Diagnostics exceeded their 2 KiB capture limit; does not imply the machine result was truncated"
                                          },
                                          "status": {
                                            "type": "string",
                                            "enum": [
                                              "signalled"
                                            ]
                                          },
                                          "signal": {
                                            "type": "string",
                                            "minLength": 1,
                                            "maxLength": 32
                                          }
                                        },
                                        "required": [
                                          "version",
                                          "stdout",
                                          "stderr",
                                          "stdoutTruncated",
                                          "stderrTruncated",
                                          "status",
                                          "signal"
                                        ],
                                        "additionalProperties": false
                                      },
                                      {
                                        "type": "object",
                                        "properties": {
                                          "version": {
                                            "type": "number",
                                            "enum": [
                                              1
                                            ]
                                          },
                                          "stdout": {
                                            "type": "string",
                                            "maxLength": 8192
                                          },
                                          "stderr": {
                                            "type": "string",
                                            "maxLength": 8192
                                          },
                                          "stdoutTruncated": {
                                            "type": "boolean",
                                            "description": "The machine-result stream exceeded its 8 KiB capture limit"
                                          },
                                          "stderrTruncated": {
                                            "type": "boolean",
                                            "description": "Diagnostics exceeded their 2 KiB capture limit; does not imply the machine result was truncated"
                                          },
                                          "status": {
                                            "type": "string",
                                            "enum": [
                                              "timed_out"
                                            ]
                                          }
                                        },
                                        "required": [
                                          "version",
                                          "stdout",
                                          "stderr",
                                          "stdoutTruncated",
                                          "stderrTruncated",
                                          "status"
                                        ],
                                        "additionalProperties": false
                                      },
                                      {
                                        "type": "object",
                                        "properties": {
                                          "version": {
                                            "type": "number",
                                            "enum": [
                                              1
                                            ]
                                          },
                                          "stdout": {
                                            "type": "string",
                                            "maxLength": 8192
                                          },
                                          "stderr": {
                                            "type": "string",
                                            "maxLength": 8192
                                          },
                                          "stdoutTruncated": {
                                            "type": "boolean",
                                            "description": "The machine-result stream exceeded its 8 KiB capture limit"
                                          },
                                          "stderrTruncated": {
                                            "type": "boolean",
                                            "description": "Diagnostics exceeded their 2 KiB capture limit; does not imply the machine result was truncated"
                                          },
                                          "status": {
                                            "type": "string",
                                            "enum": [
                                              "cancelled"
                                            ]
                                          }
                                        },
                                        "required": [
                                          "version",
                                          "stdout",
                                          "stderr",
                                          "stdoutTruncated",
                                          "stderrTruncated",
                                          "status"
                                        ],
                                        "additionalProperties": false
                                      },
                                      {
                                        "type": "object",
                                        "properties": {
                                          "version": {
                                            "type": "number",
                                            "enum": [
                                              1
                                            ]
                                          },
                                          "stdout": {
                                            "type": "string",
                                            "maxLength": 8192
                                          },
                                          "stderr": {
                                            "type": "string",
                                            "maxLength": 8192
                                          },
                                          "stdoutTruncated": {
                                            "type": "boolean",
                                            "description": "The machine-result stream exceeded its 8 KiB capture limit"
                                          },
                                          "stderrTruncated": {
                                            "type": "boolean",
                                            "description": "Diagnostics exceeded their 2 KiB capture limit; does not imply the machine result was truncated"
                                          },
                                          "status": {
                                            "type": "string",
                                            "enum": [
                                              "launch_failed"
                                            ]
                                          },
                                          "message": {
                                            "type": "string",
                                            "maxLength": 1024
                                          }
                                        },
                                        "required": [
                                          "version",
                                          "stdout",
                                          "stderr",
                                          "stdoutTruncated",
                                          "stderrTruncated",
                                          "status",
                                          "message"
                                        ],
                                        "additionalProperties": false
                                      }
                                    ]
                                  }
                                },
                                "required": [
                                  "status",
                                  "process"
                                ],
                                "additionalProperties": false
                              },
                              {
                                "type": "object",
                                "properties": {
                                  "status": {
                                    "type": "string",
                                    "enum": [
                                      "failed"
                                    ]
                                  },
                                  "reason": {
                                    "type": "string",
                                    "minLength": 1
                                  },
                                  "code": {
                                    "type": "string",
                                    "enum": [
                                      "job_still_running"
                                    ],
                                    "description": "Present when the check was not run for a typed reason: `job_still_running`, a background job the task started outlived the check's wait"
                                  }
                                },
                                "required": [
                                  "status",
                                  "reason"
                                ],
                                "additionalProperties": false
                              }
                            ],
                            "description": "Present only for a registered post-turn script. Its status and process output are independent of the subject task's status."
                          }
                        },
                        "required": [
                          "taskId",
                          "orgId",
                          "namespace",
                          "agentId",
                          "sessionId",
                          "taskOpencodeBranchId",
                          "taskLink",
                          "status",
                          "createdAt",
                          "startedAt",
                          "completedAt"
                        ],
                        "additionalProperties": false,
                        "description": "Task polling response"
                      },
                      "description": "Tasks newest-first, in the same shape GET /api/v1/tasks/:taskId returns"
                    },
                    "nextCursor": {
                      "type": "string",
                      "nullable": true,
                      "description": "Cursor for the next page, or null on the last page"
                    }
                  },
                  "required": [
                    "items",
                    "nextCursor"
                  ],
                  "additionalProperties": false,
                  "description": "Key-scoped page of tasks"
                }
              }
            }
          },
          "400": {
            "description": "The request is invalid: a field failed validation (`details` lists the issues), or it was refused as a client error (`code` names the refusal where the route reports one).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "No valid task API key. Send `Authorization: Bearer tsk_…`.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The key lacks the `tasks:read` capability, or its principal may not act on this resource.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found in the key's organization.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "The resource is in a state that refuses this request (`code` names the conflict where the route reports one).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unexpected server error (`code` is `TASK_API_INTERNAL_ERROR`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Open work has not caught up yet; retry shortly (`code` is `NATIVE_OPEN_WORK_NOT_CAUGHT_UP`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/tasks/roots": {
      "get": {
        "tags": [
          "Task roots"
        ],
        "summary": "List root conversations",
        "description": "Pages through the top-level tasks the key can read, most recently updated first, without their subtasks. Pass the returned cursor back as `cursor` for the next page.",
        "operationId": "listTaskRoots",
        "parameters": [
          {
            "in": "query",
            "name": "cursor",
            "required": false,
            "schema": {
              "type": "string",
              "minLength": 1
            }
          },
          {
            "in": "query",
            "name": "limit",
            "required": false,
            "schema": {
              "type": "integer",
              "exclusiveMinimum": true,
              "minimum": 0,
              "maximum": 100,
              "default": 50
            }
          }
        ],
        "responses": {
          "200": {
            "description": "A page of root conversations.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "taskId": {
                            "type": "string",
                            "minLength": 1,
                            "description": "Root task.id, never a dispatch or runtime run ID"
                          },
                          "title": {
                            "type": "string",
                            "nullable": true
                          },
                          "orgId": {
                            "type": "string",
                            "minLength": 1
                          },
                          "agentId": {
                            "type": "string",
                            "minLength": 1,
                            "nullable": true
                          },
                          "workspaceId": {
                            "type": "string",
                            "minLength": 1,
                            "nullable": true
                          },
                          "workspaceName": {
                            "type": "string",
                            "nullable": true,
                            "description": "The workspace's display name; null when the task is in no workspace"
                          },
                          "status": {
                            "type": "string",
                            "enum": [
                              "planned",
                              "active",
                              "completed",
                              "failed",
                              "archived"
                            ],
                            "description": "Persisted root lifecycle status, not runtime execution status"
                          },
                          "createdAt": {
                            "type": "string",
                            "format": "date-time"
                          },
                          "updatedAt": {
                            "type": "string",
                            "format": "date-time"
                          }
                        },
                        "required": [
                          "taskId",
                          "title",
                          "orgId",
                          "agentId",
                          "workspaceId",
                          "workspaceName",
                          "status",
                          "createdAt",
                          "updatedAt"
                        ],
                        "additionalProperties": false,
                        "description": "Root task metadata"
                      }
                    },
                    "nextCursor": {
                      "type": "string",
                      "nullable": true
                    }
                  },
                  "required": [
                    "items",
                    "nextCursor"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "400": {
            "description": "The request is invalid: a field failed validation (`details` lists the issues), or it was refused as a client error (`code` names the refusal where the route reports one).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "No valid task API key. Send `Authorization: Bearer tsk_…`.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The key lacks the `tasks:read` capability, or its principal may not act on this resource.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found in the key's organization.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "The resource is in a state that refuses this request (`code` names the conflict where the route reports one).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unexpected server error (`code` is `TASK_API_INTERNAL_ERROR`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Open work has not caught up yet; retry shortly (`code` is `NATIVE_OPEN_WORK_NOT_CAUGHT_UP`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/tasks/roots/{taskId}": {
      "get": {
        "tags": [
          "Task roots"
        ],
        "summary": "Get a root conversation",
        "description": "Returns the metadata of one top-level task: its title, agent, workspace and lifecycle status. A subtask or a task the key cannot read answers 404.",
        "operationId": "getTaskRoot",
        "parameters": [
          {
            "in": "path",
            "name": "taskId",
            "required": true,
            "description": "The task's id.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The root conversation.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "taskId": {
                      "type": "string",
                      "minLength": 1,
                      "description": "Root task.id, never a dispatch or runtime run ID"
                    },
                    "title": {
                      "type": "string",
                      "nullable": true
                    },
                    "orgId": {
                      "type": "string",
                      "minLength": 1
                    },
                    "agentId": {
                      "type": "string",
                      "minLength": 1,
                      "nullable": true
                    },
                    "workspaceId": {
                      "type": "string",
                      "minLength": 1,
                      "nullable": true
                    },
                    "workspaceName": {
                      "type": "string",
                      "nullable": true,
                      "description": "The workspace's display name; null when the task is in no workspace"
                    },
                    "status": {
                      "type": "string",
                      "enum": [
                        "planned",
                        "active",
                        "completed",
                        "failed",
                        "archived"
                      ],
                      "description": "Persisted root lifecycle status, not runtime execution status"
                    },
                    "createdAt": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "updatedAt": {
                      "type": "string",
                      "format": "date-time"
                    }
                  },
                  "required": [
                    "taskId",
                    "title",
                    "orgId",
                    "agentId",
                    "workspaceId",
                    "workspaceName",
                    "status",
                    "createdAt",
                    "updatedAt"
                  ],
                  "additionalProperties": false,
                  "description": "Root task metadata"
                }
              }
            }
          },
          "400": {
            "description": "The request is invalid: a field failed validation (`details` lists the issues), or it was refused as a client error (`code` names the refusal where the route reports one).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "No valid task API key. Send `Authorization: Bearer tsk_…`.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The key lacks the `tasks:read` capability, or its principal may not act on this resource.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found in the key's organization.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "The resource is in a state that refuses this request (`code` names the conflict where the route reports one).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unexpected server error (`code` is `TASK_API_INTERNAL_ERROR`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Open work has not caught up yet; retry shortly (`code` is `NATIVE_OPEN_WORK_NOT_CAUGHT_UP`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "patch": {
        "tags": [
          "Task roots"
        ],
        "summary": "Update a root conversation",
        "description": "Renames a top-level task, or clears its title with `null`. The key must act as the task's owner; a service account key names the owner with `ownerUserId` or `ownerUserEmail`.",
        "operationId": "updateTaskRoot",
        "parameters": [
          {
            "in": "path",
            "name": "taskId",
            "required": true,
            "description": "The task's id.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "title": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 280,
                    "nullable": true
                  },
                  "ownerUserId": {
                    "type": "string",
                    "minLength": 1
                  },
                  "ownerUserEmail": {
                    "type": "string",
                    "format": "email"
                  }
                },
                "required": [
                  "title"
                ],
                "additionalProperties": false,
                "description": "Rename or clear a root title; explicit service-key owner delegation is authorized separately"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The updated root conversation.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "taskId": {
                      "type": "string",
                      "minLength": 1,
                      "description": "Root task.id, never a dispatch or runtime run ID"
                    },
                    "title": {
                      "type": "string",
                      "nullable": true
                    },
                    "orgId": {
                      "type": "string",
                      "minLength": 1
                    },
                    "agentId": {
                      "type": "string",
                      "minLength": 1,
                      "nullable": true
                    },
                    "workspaceId": {
                      "type": "string",
                      "minLength": 1,
                      "nullable": true
                    },
                    "workspaceName": {
                      "type": "string",
                      "nullable": true,
                      "description": "The workspace's display name; null when the task is in no workspace"
                    },
                    "status": {
                      "type": "string",
                      "enum": [
                        "planned",
                        "active",
                        "completed",
                        "failed",
                        "archived"
                      ],
                      "description": "Persisted root lifecycle status, not runtime execution status"
                    },
                    "createdAt": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "updatedAt": {
                      "type": "string",
                      "format": "date-time"
                    }
                  },
                  "required": [
                    "taskId",
                    "title",
                    "orgId",
                    "agentId",
                    "workspaceId",
                    "workspaceName",
                    "status",
                    "createdAt",
                    "updatedAt"
                  ],
                  "additionalProperties": false,
                  "description": "Root task metadata"
                }
              }
            }
          },
          "400": {
            "description": "The request is invalid: a field failed validation (`details` lists the issues), or it was refused as a client error (`code` names the refusal where the route reports one).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "No valid task API key. Send `Authorization: Bearer tsk_…`.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The key lacks the `tasks:create` capability, or its principal may not act on this resource.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found in the key's organization.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "The resource is in a state that refuses this request (`code` names the conflict where the route reports one).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unexpected server error (`code` is `TASK_API_INTERNAL_ERROR`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Open work has not caught up yet; retry shortly (`code` is `NATIVE_OPEN_WORK_NOT_CAUGHT_UP`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/tasks/roots/{taskId}/cancel": {
      "post": {
        "tags": [
          "Task roots"
        ],
        "summary": "Cancel a root conversation",
        "description": "The body is optional.",
        "operationId": "cancelTaskRoot",
        "parameters": [
          {
            "in": "path",
            "name": "taskId",
            "required": true,
            "description": "The task's id.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "ownerUserId": {
                    "type": "string",
                    "minLength": 1
                  },
                  "ownerUserEmail": {
                    "type": "string",
                    "format": "email"
                  }
                },
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "What the cancellation did (`outcome`).",
            "content": {
              "application/json": {
                "schema": {
                  "anyOf": [
                    {
                      "type": "object",
                      "properties": {
                        "taskId": {
                          "type": "string",
                          "minLength": 1
                        },
                        "dispatchRunId": {
                          "type": "string",
                          "minLength": 1
                        },
                        "taskRunId": {
                          "type": "string",
                          "minLength": 1
                        },
                        "outcome": {
                          "type": "string",
                          "enum": [
                            "cancelled-before-execution"
                          ]
                        }
                      },
                      "required": [
                        "taskId",
                        "dispatchRunId",
                        "outcome"
                      ],
                      "additionalProperties": false
                    },
                    {
                      "type": "object",
                      "properties": {
                        "taskId": {
                          "type": "string",
                          "minLength": 1
                        },
                        "dispatchRunId": {
                          "type": "string",
                          "minLength": 1
                        },
                        "taskRunId": {
                          "type": "string",
                          "minLength": 1
                        },
                        "outcome": {
                          "type": "string",
                          "enum": [
                            "already-terminal"
                          ]
                        },
                        "status": {
                          "type": "string",
                          "enum": [
                            "succeeded",
                            "failed",
                            "cancelled"
                          ],
                          "description": "Terminal task run status"
                        }
                      },
                      "required": [
                        "taskId",
                        "dispatchRunId",
                        "outcome",
                        "status"
                      ],
                      "additionalProperties": false
                    },
                    {
                      "type": "object",
                      "properties": {
                        "taskId": {
                          "type": "string",
                          "minLength": 1
                        },
                        "dispatchRunId": {
                          "type": "string",
                          "minLength": 1
                        },
                        "taskRunId": {
                          "type": "string",
                          "minLength": 1
                        },
                        "outcome": {
                          "type": "string",
                          "enum": [
                            "dispatch-not-found"
                          ]
                        }
                      },
                      "required": [
                        "taskId",
                        "dispatchRunId",
                        "outcome"
                      ],
                      "additionalProperties": false
                    },
                    {
                      "type": "object",
                      "properties": {
                        "taskId": {
                          "type": "string",
                          "minLength": 1
                        },
                        "dispatchRunId": {
                          "type": "string",
                          "minLength": 1
                        },
                        "outcome": {
                          "type": "string",
                          "enum": [
                            "runtime-not-ready"
                          ]
                        }
                      },
                      "required": [
                        "taskId",
                        "dispatchRunId",
                        "outcome"
                      ],
                      "additionalProperties": false,
                      "description": "The attempt has been claimed but its runtime is not yet addressable; no cancellation was delivered, retry"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "taskId": {
                          "type": "string",
                          "minLength": 1
                        },
                        "taskRunId": {
                          "type": "string",
                          "minLength": 1
                        },
                        "outcome": {
                          "type": "string",
                          "enum": [
                            "runtime-abort"
                          ]
                        },
                        "result": {
                          "anyOf": [
                            {
                              "type": "object",
                              "properties": {
                                "outcome": {
                                  "type": "string",
                                  "enum": [
                                    "accepted"
                                  ]
                                },
                                "sessionId": {
                                  "type": "string",
                                  "description": "The live session the abort was signalled for (server-resolved)"
                                }
                              },
                              "required": [
                                "outcome",
                                "sessionId"
                              ],
                              "additionalProperties": false
                            },
                            {
                              "type": "object",
                              "properties": {
                                "outcome": {
                                  "type": "string",
                                  "enum": [
                                    "noLiveSession"
                                  ]
                                }
                              },
                              "required": [
                                "outcome"
                              ],
                              "additionalProperties": false,
                              "description": "The run is live but holds no addressable engine session yet (cold/booting) — nothing in flight to stop"
                            },
                            {
                              "type": "object",
                              "properties": {
                                "outcome": {
                                  "type": "string",
                                  "enum": [
                                    "alreadySettled"
                                  ]
                                },
                                "runStatus": {
                                  "type": "string",
                                  "enum": [
                                    "preparing",
                                    "running",
                                    "awaiting_user_input",
                                    "sleeping",
                                    "succeeded",
                                    "failed",
                                    "cancelled"
                                  ],
                                  "description": "The run's stored status at the time of the call"
                                }
                              },
                              "required": [
                                "outcome",
                                "runStatus"
                              ],
                              "additionalProperties": false,
                              "description": "The run is terminal, or its lifecycle workflow is already gone (settle race) — nothing left to abort"
                            },
                            {
                              "type": "object",
                              "properties": {
                                "outcome": {
                                  "type": "string",
                                  "enum": [
                                    "deviceRun"
                                  ]
                                }
                              },
                              "required": [
                                "outcome"
                              ],
                              "additionalProperties": false,
                              "description": "The run is a LEGACY device-driven run: abort travels the device inbox (cancel kind), not the sandbox lifecycle workflow (EMP-1441 W3/W4)"
                            },
                            {
                              "type": "object",
                              "properties": {
                                "outcome": {
                                  "type": "string",
                                  "enum": [
                                    "nativeStop"
                                  ]
                                },
                                "commandId": {
                                  "type": "string",
                                  "description": "The native `stop` command admitted to the task's journal; the lifecycle workflow applies it"
                                }
                              },
                              "required": [
                                "outcome",
                                "commandId"
                              ],
                              "additionalProperties": false,
                              "description": "The run is native (sandbox or paired machine): its Stop is the native stop command, honoured even while a device run waits for its claim"
                            },
                            {
                              "type": "object",
                              "properties": {
                                "outcome": {
                                  "type": "string",
                                  "enum": [
                                    "stoppedBeforeDispatch"
                                  ]
                                }
                              },
                              "required": [
                                "outcome"
                              ],
                              "additionalProperties": false,
                              "description": "The named turn was closed before the runtime was sent it: it will not run, and nothing else on the run was touched"
                            },
                            {
                              "type": "object",
                              "properties": {
                                "outcome": {
                                  "type": "string",
                                  "enum": [
                                    "noSuchTurn"
                                  ]
                                }
                              },
                              "required": [
                                "outcome"
                              ],
                              "additionalProperties": false,
                              "description": "No turn with this client message id exists on the task (its send never reached the server): nothing was stopped"
                            },
                            {
                              "type": "object",
                              "properties": {
                                "outcome": {
                                  "type": "string",
                                  "enum": [
                                    "turnAlreadyEnded"
                                  ]
                                }
                              },
                              "required": [
                                "outcome"
                              ],
                              "additionalProperties": false,
                              "description": "The named turn was already over (answered, closed or checkpointed) when the Stop arrived: nothing was stopped, and a later turn on the run keeps running"
                            }
                          ],
                          "description": "Typed outcome of a run-addressed abort — never a 500 for a stale or settled target"
                        }
                      },
                      "required": [
                        "taskId",
                        "taskRunId",
                        "outcome",
                        "result"
                      ],
                      "additionalProperties": false
                    },
                    {
                      "type": "object",
                      "properties": {
                        "taskId": {
                          "type": "string",
                          "minLength": 1
                        },
                        "outcome": {
                          "type": "string",
                          "enum": [
                            "no-live-run"
                          ]
                        }
                      },
                      "required": [
                        "taskId",
                        "outcome"
                      ],
                      "additionalProperties": false
                    }
                  ],
                  "description": "The cancellation owner's actual outcome; no root lifecycle transition is implied"
                }
              }
            }
          },
          "400": {
            "description": "The request is invalid: a field failed validation (`details` lists the issues), or it was refused as a client error (`code` names the refusal where the route reports one).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "No valid task API key. Send `Authorization: Bearer tsk_…`.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The key lacks the `tasks:create` capability, or its principal may not act on this resource.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found in the key's organization.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "The resource is in a state that refuses this request (`code` names the conflict where the route reports one).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unexpected server error (`code` is `TASK_API_INTERNAL_ERROR`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Open work has not caught up yet; retry shortly (`code` is `NATIVE_OPEN_WORK_NOT_CAUGHT_UP`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/tasks/{taskId}": {
      "get": {
        "tags": [
          "Tasks"
        ],
        "summary": "Get a task",
        "description": "Returns a task created with `POST /tasks`, by the `taskId` that call returned, with its status, output and cost. A key reads tasks it created and tasks owned by the person it acts for.",
        "operationId": "getTask",
        "parameters": [
          {
            "in": "path",
            "name": "taskId",
            "required": true,
            "description": "The task's id.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The task.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "taskId": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "taskDispatchRunId": {
                      "type": "string",
                      "minLength": 1,
                      "description": "Canonical Task API dispatch-run identifier"
                    },
                    "taskRunId": {
                      "type": "string",
                      "minLength": 1,
                      "nullable": true,
                      "description": "Runtime task-run identifier when the task has reached runtime execution"
                    },
                    "runtimeTaskId": {
                      "type": "string",
                      "minLength": 1,
                      "nullable": true,
                      "description": "Runtime task-tree task identifier when the task has reached runtime execution"
                    },
                    "rootTaskId": {
                      "type": "string",
                      "minLength": 1,
                      "nullable": true,
                      "description": "Root runtime task identifier used to correlate a whole task tree"
                    },
                    "orgId": {
                      "type": "string",
                      "minLength": 1
                    },
                    "namespace": {
                      "type": "string",
                      "minLength": 1
                    },
                    "title": {
                      "type": "string",
                      "nullable": true,
                      "description": "Human-facing task title, read through from the linked task row and falling back to the dispatch row's stored title"
                    },
                    "agentId": {
                      "type": "string",
                      "minLength": 1
                    },
                    "sessionId": {
                      "type": "string",
                      "nullable": true
                    },
                    "taskOpencodeBranchId": {
                      "type": "string",
                      "nullable": true,
                      "description": "Stable OpenCode branch ID backing the task conversation"
                    },
                    "taskLink": {
                      "type": "string",
                      "nullable": true,
                      "description": "Relative browser path for opening the task conversation in the workspace UI"
                    },
                    "status": {
                      "type": "string",
                      "enum": [
                        "queued",
                        "running",
                        "succeeded",
                        "failed",
                        "cancelled"
                      ],
                      "description": "Task dispatch run lifecycle status"
                    },
                    "createdAt": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "startedAt": {
                      "type": "string",
                      "format": "date-time",
                      "nullable": true
                    },
                    "completedAt": {
                      "type": "string",
                      "format": "date-time",
                      "nullable": true
                    },
                    "costUsd": {
                      "type": "number",
                      "minimum": 0,
                      "nullable": true,
                      "description": "Model spend of the whole run this task ran on (its turns, follow-ups and sub-agents), from the billing ledger. Null until the run's calls have ended and the ledger is final past them, or when the spend cannot be stated; costUnknownReason says which. A run that settles after it parked reads null again until the ledger is final past the settle. A later LiteLLM re-rate (a signed correction row) can still move a final figure, down as well as up."
                    },
                    "costUnknownReason": {
                      "type": "string",
                      "enum": [
                        "ledger_not_final",
                        "device_calls_unbounded",
                        "no_rows",
                        "unrated_rows",
                        "run_live",
                        "run_resumable",
                        "run_shared_by_dispatches",
                        "unbound",
                        "ledger_net_negative"
                      ],
                      "description": "Why costUsd is null. ledger_not_final: the billing ledger has not yet recorded every call that started before the run's calls ended. no_rows: the billing ledger holds no model call for the run. unrated_rows: a model call of the run carries no price. run_live: a model call can still be made on the run. run_resumable: the run is paused and its next start resumes it, so its spend can still grow. device_calls_unbounded: This task ran on a paired machine; its cost is still counting and isn't shown as final yet. run_shared_by_dispatches: more than one task is bound to the run, so no one task's share can be stated; the run-level spend is a separate follow-up (issue #6604). unbound: the task is bound to no run (it never started, or it ran on a paired machine without one). ledger_net_negative: the billing ledger's corrections leave the run below zero, which is a ledger fault."
                    },
                    "output": {
                      "type": "object",
                      "properties": {
                        "text": {
                          "type": "string",
                          "description": "Task textual output"
                        },
                        "files": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "properties": {
                              "id": {
                                "type": "string",
                                "minLength": 1,
                                "description": "Stable output file identifier within the task run"
                              },
                              "uri": {
                                "type": "string",
                                "pattern": "^org\\_drive\\:\\/\\/",
                                "description": "Canonical org Drive URI for this file"
                              },
                              "name": {
                                "type": "string",
                                "minLength": 1,
                                "description": "Display filename"
                              },
                              "source": {
                                "type": "string",
                                "enum": [
                                  "input",
                                  "generated"
                                ],
                                "description": "Whether the file was attached as input or generated by the task run"
                              },
                              "contentType": {
                                "type": "string",
                                "nullable": true,
                                "description": "MIME type"
                              },
                              "sizeBytes": {
                                "type": "integer",
                                "minimum": 0,
                                "nullable": true,
                                "description": "File size in bytes"
                              }
                            },
                            "required": [
                              "id",
                              "uri",
                              "name",
                              "source",
                              "contentType",
                              "sizeBytes"
                            ],
                            "additionalProperties": false,
                            "description": "File reference returned as task output context"
                          },
                          "description": "Referenced or generated file references"
                        },
                        "appliedSkills": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "properties": {
                              "skillId": {
                                "type": "string",
                                "minLength": 1,
                                "description": "Skill identifier"
                              },
                              "versionId": {
                                "type": "string",
                                "minLength": 1,
                                "nullable": true,
                                "description": "Optional skill version ID to pin for deterministic behavior"
                              }
                            },
                            "required": [
                              "skillId"
                            ],
                            "additionalProperties": false,
                            "description": "Skill reference used by a task"
                          },
                          "description": "Skills this run used, as recorded from its tool calls; a skill only requested or listed is not here"
                        },
                        "structured": {
                          "description": "Validated structured answer; present only when the request declared an outputSchema"
                        }
                      },
                      "required": [
                        "text",
                        "files",
                        "appliedSkills"
                      ],
                      "additionalProperties": false,
                      "description": "Task success result payload"
                    },
                    "error": {
                      "type": "object",
                      "properties": {
                        "code": {
                          "type": "string",
                          "minLength": 1,
                          "description": "Machine-readable error code"
                        },
                        "message": {
                          "type": "string",
                          "minLength": 1,
                          "description": "Human-readable error message"
                        }
                      },
                      "required": [
                        "code",
                        "message"
                      ],
                      "additionalProperties": false,
                      "description": "Task failure payload"
                    },
                    "postTurnScript": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "status": {
                              "type": "string",
                              "enum": [
                                "not_registered"
                              ]
                            }
                          },
                          "required": [
                            "status"
                          ],
                          "additionalProperties": false
                        },
                        {
                          "type": "object",
                          "properties": {
                            "status": {
                              "type": "string",
                              "enum": [
                                "pending",
                                "running"
                              ]
                            }
                          },
                          "required": [
                            "status"
                          ],
                          "additionalProperties": false
                        },
                        {
                          "type": "object",
                          "properties": {
                            "status": {
                              "type": "string",
                              "enum": [
                                "completed"
                              ]
                            },
                            "process": {
                              "anyOf": [
                                {
                                  "type": "object",
                                  "properties": {
                                    "version": {
                                      "type": "number",
                                      "enum": [
                                        1
                                      ]
                                    },
                                    "stdout": {
                                      "type": "string",
                                      "maxLength": 8192
                                    },
                                    "stderr": {
                                      "type": "string",
                                      "maxLength": 8192
                                    },
                                    "stdoutTruncated": {
                                      "type": "boolean",
                                      "description": "The machine-result stream exceeded its 8 KiB capture limit"
                                    },
                                    "stderrTruncated": {
                                      "type": "boolean",
                                      "description": "Diagnostics exceeded their 2 KiB capture limit; does not imply the machine result was truncated"
                                    },
                                    "status": {
                                      "type": "string",
                                      "enum": [
                                        "exited"
                                      ]
                                    },
                                    "exitCode": {
                                      "type": "integer",
                                      "minimum": 0,
                                      "maximum": 255
                                    }
                                  },
                                  "required": [
                                    "version",
                                    "stdout",
                                    "stderr",
                                    "stdoutTruncated",
                                    "stderrTruncated",
                                    "status",
                                    "exitCode"
                                  ],
                                  "additionalProperties": false
                                },
                                {
                                  "type": "object",
                                  "properties": {
                                    "version": {
                                      "type": "number",
                                      "enum": [
                                        1
                                      ]
                                    },
                                    "stdout": {
                                      "type": "string",
                                      "maxLength": 8192
                                    },
                                    "stderr": {
                                      "type": "string",
                                      "maxLength": 8192
                                    },
                                    "stdoutTruncated": {
                                      "type": "boolean",
                                      "description": "The machine-result stream exceeded its 8 KiB capture limit"
                                    },
                                    "stderrTruncated": {
                                      "type": "boolean",
                                      "description": "Diagnostics exceeded their 2 KiB capture limit; does not imply the machine result was truncated"
                                    },
                                    "status": {
                                      "type": "string",
                                      "enum": [
                                        "signalled"
                                      ]
                                    },
                                    "signal": {
                                      "type": "string",
                                      "minLength": 1,
                                      "maxLength": 32
                                    }
                                  },
                                  "required": [
                                    "version",
                                    "stdout",
                                    "stderr",
                                    "stdoutTruncated",
                                    "stderrTruncated",
                                    "status",
                                    "signal"
                                  ],
                                  "additionalProperties": false
                                },
                                {
                                  "type": "object",
                                  "properties": {
                                    "version": {
                                      "type": "number",
                                      "enum": [
                                        1
                                      ]
                                    },
                                    "stdout": {
                                      "type": "string",
                                      "maxLength": 8192
                                    },
                                    "stderr": {
                                      "type": "string",
                                      "maxLength": 8192
                                    },
                                    "stdoutTruncated": {
                                      "type": "boolean",
                                      "description": "The machine-result stream exceeded its 8 KiB capture limit"
                                    },
                                    "stderrTruncated": {
                                      "type": "boolean",
                                      "description": "Diagnostics exceeded their 2 KiB capture limit; does not imply the machine result was truncated"
                                    },
                                    "status": {
                                      "type": "string",
                                      "enum": [
                                        "timed_out"
                                      ]
                                    }
                                  },
                                  "required": [
                                    "version",
                                    "stdout",
                                    "stderr",
                                    "stdoutTruncated",
                                    "stderrTruncated",
                                    "status"
                                  ],
                                  "additionalProperties": false
                                },
                                {
                                  "type": "object",
                                  "properties": {
                                    "version": {
                                      "type": "number",
                                      "enum": [
                                        1
                                      ]
                                    },
                                    "stdout": {
                                      "type": "string",
                                      "maxLength": 8192
                                    },
                                    "stderr": {
                                      "type": "string",
                                      "maxLength": 8192
                                    },
                                    "stdoutTruncated": {
                                      "type": "boolean",
                                      "description": "The machine-result stream exceeded its 8 KiB capture limit"
                                    },
                                    "stderrTruncated": {
                                      "type": "boolean",
                                      "description": "Diagnostics exceeded their 2 KiB capture limit; does not imply the machine result was truncated"
                                    },
                                    "status": {
                                      "type": "string",
                                      "enum": [
                                        "cancelled"
                                      ]
                                    }
                                  },
                                  "required": [
                                    "version",
                                    "stdout",
                                    "stderr",
                                    "stdoutTruncated",
                                    "stderrTruncated",
                                    "status"
                                  ],
                                  "additionalProperties": false
                                },
                                {
                                  "type": "object",
                                  "properties": {
                                    "version": {
                                      "type": "number",
                                      "enum": [
                                        1
                                      ]
                                    },
                                    "stdout": {
                                      "type": "string",
                                      "maxLength": 8192
                                    },
                                    "stderr": {
                                      "type": "string",
                                      "maxLength": 8192
                                    },
                                    "stdoutTruncated": {
                                      "type": "boolean",
                                      "description": "The machine-result stream exceeded its 8 KiB capture limit"
                                    },
                                    "stderrTruncated": {
                                      "type": "boolean",
                                      "description": "Diagnostics exceeded their 2 KiB capture limit; does not imply the machine result was truncated"
                                    },
                                    "status": {
                                      "type": "string",
                                      "enum": [
                                        "launch_failed"
                                      ]
                                    },
                                    "message": {
                                      "type": "string",
                                      "maxLength": 1024
                                    }
                                  },
                                  "required": [
                                    "version",
                                    "stdout",
                                    "stderr",
                                    "stdoutTruncated",
                                    "stderrTruncated",
                                    "status",
                                    "message"
                                  ],
                                  "additionalProperties": false
                                }
                              ]
                            }
                          },
                          "required": [
                            "status",
                            "process"
                          ],
                          "additionalProperties": false
                        },
                        {
                          "type": "object",
                          "properties": {
                            "status": {
                              "type": "string",
                              "enum": [
                                "failed"
                              ]
                            },
                            "reason": {
                              "type": "string",
                              "minLength": 1
                            },
                            "code": {
                              "type": "string",
                              "enum": [
                                "job_still_running"
                              ],
                              "description": "Present when the check was not run for a typed reason: `job_still_running`, a background job the task started outlived the check's wait"
                            }
                          },
                          "required": [
                            "status",
                            "reason"
                          ],
                          "additionalProperties": false
                        }
                      ],
                      "description": "Present only for a registered post-turn script. Its status and process output are independent of the subject task's status."
                    }
                  },
                  "required": [
                    "taskId",
                    "orgId",
                    "namespace",
                    "agentId",
                    "sessionId",
                    "taskOpencodeBranchId",
                    "taskLink",
                    "status",
                    "createdAt",
                    "startedAt",
                    "completedAt"
                  ],
                  "additionalProperties": false,
                  "description": "Task polling response"
                }
              }
            }
          },
          "400": {
            "description": "The request is invalid: a field failed validation (`details` lists the issues), or it was refused as a client error (`code` names the refusal where the route reports one).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "No valid task API key. Send `Authorization: Bearer tsk_…`.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The key lacks the `tasks:read` capability, or its principal may not act on this resource.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found in the key's organization.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "The resource is in a state that refuses this request (`code` names the conflict where the route reports one).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unexpected server error (`code` is `TASK_API_INTERNAL_ERROR`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Open work has not caught up yet; retry shortly (`code` is `NATIVE_OPEN_WORK_NOT_CAUGHT_UP`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "patch": {
        "tags": [
          "Tasks"
        ],
        "summary": "Update a task",
        "description": "Changes a task's title, or its webhook delivery while the task is still running. Send at least one field; the task's agent, input and owner cannot change.",
        "operationId": "updateTask",
        "parameters": [
          {
            "in": "path",
            "name": "taskId",
            "required": true,
            "description": "The task's id.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "title": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 280,
                    "nullable": true,
                    "description": "New human-facing task title; null clears it"
                  },
                  "delivery": {
                    "type": "object",
                    "properties": {
                      "type": {
                        "type": "string",
                        "enum": [
                          "webhook"
                        ]
                      },
                      "config": {
                        "type": "object",
                        "properties": {
                          "endpoint": {
                            "type": "string",
                            "format": "uri",
                            "description": "New webhook URL for terminal task updates"
                          },
                          "signingSecret": {
                            "type": "string",
                            "minLength": 16,
                            "description": "New HMAC signing secret; rotates the secret used for webhook signatures"
                          },
                          "frequency": {
                            "type": "string",
                            "enum": [
                              "on_finish"
                            ],
                            "description": "New delivery trigger frequency"
                          }
                        },
                        "additionalProperties": false
                      }
                    },
                    "required": [
                      "type",
                      "config"
                    ],
                    "additionalProperties": false,
                    "description": "Partial webhook delivery configuration; only the supplied fields change"
                  }
                },
                "additionalProperties": false,
                "description": "Task update request payload"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The updated task.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "taskId": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "taskDispatchRunId": {
                      "type": "string",
                      "minLength": 1,
                      "description": "Canonical Task API dispatch-run identifier"
                    },
                    "taskRunId": {
                      "type": "string",
                      "minLength": 1,
                      "nullable": true,
                      "description": "Runtime task-run identifier when the task has reached runtime execution"
                    },
                    "runtimeTaskId": {
                      "type": "string",
                      "minLength": 1,
                      "nullable": true,
                      "description": "Runtime task-tree task identifier when the task has reached runtime execution"
                    },
                    "rootTaskId": {
                      "type": "string",
                      "minLength": 1,
                      "nullable": true,
                      "description": "Root runtime task identifier used to correlate a whole task tree"
                    },
                    "orgId": {
                      "type": "string",
                      "minLength": 1
                    },
                    "namespace": {
                      "type": "string",
                      "minLength": 1
                    },
                    "title": {
                      "type": "string",
                      "nullable": true,
                      "description": "Human-facing task title, read through from the linked task row and falling back to the dispatch row's stored title"
                    },
                    "agentId": {
                      "type": "string",
                      "minLength": 1
                    },
                    "sessionId": {
                      "type": "string",
                      "nullable": true
                    },
                    "taskOpencodeBranchId": {
                      "type": "string",
                      "nullable": true,
                      "description": "Stable OpenCode branch ID backing the task conversation"
                    },
                    "taskLink": {
                      "type": "string",
                      "nullable": true,
                      "description": "Relative browser path for opening the task conversation in the workspace UI"
                    },
                    "status": {
                      "type": "string",
                      "enum": [
                        "queued",
                        "running",
                        "succeeded",
                        "failed",
                        "cancelled"
                      ],
                      "description": "Task dispatch run lifecycle status"
                    },
                    "createdAt": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "startedAt": {
                      "type": "string",
                      "format": "date-time",
                      "nullable": true
                    },
                    "completedAt": {
                      "type": "string",
                      "format": "date-time",
                      "nullable": true
                    },
                    "costUsd": {
                      "type": "number",
                      "minimum": 0,
                      "nullable": true,
                      "description": "Model spend of the whole run this task ran on (its turns, follow-ups and sub-agents), from the billing ledger. Null until the run's calls have ended and the ledger is final past them, or when the spend cannot be stated; costUnknownReason says which. A run that settles after it parked reads null again until the ledger is final past the settle. A later LiteLLM re-rate (a signed correction row) can still move a final figure, down as well as up."
                    },
                    "costUnknownReason": {
                      "type": "string",
                      "enum": [
                        "ledger_not_final",
                        "device_calls_unbounded",
                        "no_rows",
                        "unrated_rows",
                        "run_live",
                        "run_resumable",
                        "run_shared_by_dispatches",
                        "unbound",
                        "ledger_net_negative"
                      ],
                      "description": "Why costUsd is null. ledger_not_final: the billing ledger has not yet recorded every call that started before the run's calls ended. no_rows: the billing ledger holds no model call for the run. unrated_rows: a model call of the run carries no price. run_live: a model call can still be made on the run. run_resumable: the run is paused and its next start resumes it, so its spend can still grow. device_calls_unbounded: This task ran on a paired machine; its cost is still counting and isn't shown as final yet. run_shared_by_dispatches: more than one task is bound to the run, so no one task's share can be stated; the run-level spend is a separate follow-up (issue #6604). unbound: the task is bound to no run (it never started, or it ran on a paired machine without one). ledger_net_negative: the billing ledger's corrections leave the run below zero, which is a ledger fault."
                    },
                    "output": {
                      "type": "object",
                      "properties": {
                        "text": {
                          "type": "string",
                          "description": "Task textual output"
                        },
                        "files": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "properties": {
                              "id": {
                                "type": "string",
                                "minLength": 1,
                                "description": "Stable output file identifier within the task run"
                              },
                              "uri": {
                                "type": "string",
                                "pattern": "^org\\_drive\\:\\/\\/",
                                "description": "Canonical org Drive URI for this file"
                              },
                              "name": {
                                "type": "string",
                                "minLength": 1,
                                "description": "Display filename"
                              },
                              "source": {
                                "type": "string",
                                "enum": [
                                  "input",
                                  "generated"
                                ],
                                "description": "Whether the file was attached as input or generated by the task run"
                              },
                              "contentType": {
                                "type": "string",
                                "nullable": true,
                                "description": "MIME type"
                              },
                              "sizeBytes": {
                                "type": "integer",
                                "minimum": 0,
                                "nullable": true,
                                "description": "File size in bytes"
                              }
                            },
                            "required": [
                              "id",
                              "uri",
                              "name",
                              "source",
                              "contentType",
                              "sizeBytes"
                            ],
                            "additionalProperties": false,
                            "description": "File reference returned as task output context"
                          },
                          "description": "Referenced or generated file references"
                        },
                        "appliedSkills": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "properties": {
                              "skillId": {
                                "type": "string",
                                "minLength": 1,
                                "description": "Skill identifier"
                              },
                              "versionId": {
                                "type": "string",
                                "minLength": 1,
                                "nullable": true,
                                "description": "Optional skill version ID to pin for deterministic behavior"
                              }
                            },
                            "required": [
                              "skillId"
                            ],
                            "additionalProperties": false,
                            "description": "Skill reference used by a task"
                          },
                          "description": "Skills this run used, as recorded from its tool calls; a skill only requested or listed is not here"
                        },
                        "structured": {
                          "description": "Validated structured answer; present only when the request declared an outputSchema"
                        }
                      },
                      "required": [
                        "text",
                        "files",
                        "appliedSkills"
                      ],
                      "additionalProperties": false,
                      "description": "Task success result payload"
                    },
                    "error": {
                      "type": "object",
                      "properties": {
                        "code": {
                          "type": "string",
                          "minLength": 1,
                          "description": "Machine-readable error code"
                        },
                        "message": {
                          "type": "string",
                          "minLength": 1,
                          "description": "Human-readable error message"
                        }
                      },
                      "required": [
                        "code",
                        "message"
                      ],
                      "additionalProperties": false,
                      "description": "Task failure payload"
                    },
                    "postTurnScript": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "status": {
                              "type": "string",
                              "enum": [
                                "not_registered"
                              ]
                            }
                          },
                          "required": [
                            "status"
                          ],
                          "additionalProperties": false
                        },
                        {
                          "type": "object",
                          "properties": {
                            "status": {
                              "type": "string",
                              "enum": [
                                "pending",
                                "running"
                              ]
                            }
                          },
                          "required": [
                            "status"
                          ],
                          "additionalProperties": false
                        },
                        {
                          "type": "object",
                          "properties": {
                            "status": {
                              "type": "string",
                              "enum": [
                                "completed"
                              ]
                            },
                            "process": {
                              "anyOf": [
                                {
                                  "type": "object",
                                  "properties": {
                                    "version": {
                                      "type": "number",
                                      "enum": [
                                        1
                                      ]
                                    },
                                    "stdout": {
                                      "type": "string",
                                      "maxLength": 8192
                                    },
                                    "stderr": {
                                      "type": "string",
                                      "maxLength": 8192
                                    },
                                    "stdoutTruncated": {
                                      "type": "boolean",
                                      "description": "The machine-result stream exceeded its 8 KiB capture limit"
                                    },
                                    "stderrTruncated": {
                                      "type": "boolean",
                                      "description": "Diagnostics exceeded their 2 KiB capture limit; does not imply the machine result was truncated"
                                    },
                                    "status": {
                                      "type": "string",
                                      "enum": [
                                        "exited"
                                      ]
                                    },
                                    "exitCode": {
                                      "type": "integer",
                                      "minimum": 0,
                                      "maximum": 255
                                    }
                                  },
                                  "required": [
                                    "version",
                                    "stdout",
                                    "stderr",
                                    "stdoutTruncated",
                                    "stderrTruncated",
                                    "status",
                                    "exitCode"
                                  ],
                                  "additionalProperties": false
                                },
                                {
                                  "type": "object",
                                  "properties": {
                                    "version": {
                                      "type": "number",
                                      "enum": [
                                        1
                                      ]
                                    },
                                    "stdout": {
                                      "type": "string",
                                      "maxLength": 8192
                                    },
                                    "stderr": {
                                      "type": "string",
                                      "maxLength": 8192
                                    },
                                    "stdoutTruncated": {
                                      "type": "boolean",
                                      "description": "The machine-result stream exceeded its 8 KiB capture limit"
                                    },
                                    "stderrTruncated": {
                                      "type": "boolean",
                                      "description": "Diagnostics exceeded their 2 KiB capture limit; does not imply the machine result was truncated"
                                    },
                                    "status": {
                                      "type": "string",
                                      "enum": [
                                        "signalled"
                                      ]
                                    },
                                    "signal": {
                                      "type": "string",
                                      "minLength": 1,
                                      "maxLength": 32
                                    }
                                  },
                                  "required": [
                                    "version",
                                    "stdout",
                                    "stderr",
                                    "stdoutTruncated",
                                    "stderrTruncated",
                                    "status",
                                    "signal"
                                  ],
                                  "additionalProperties": false
                                },
                                {
                                  "type": "object",
                                  "properties": {
                                    "version": {
                                      "type": "number",
                                      "enum": [
                                        1
                                      ]
                                    },
                                    "stdout": {
                                      "type": "string",
                                      "maxLength": 8192
                                    },
                                    "stderr": {
                                      "type": "string",
                                      "maxLength": 8192
                                    },
                                    "stdoutTruncated": {
                                      "type": "boolean",
                                      "description": "The machine-result stream exceeded its 8 KiB capture limit"
                                    },
                                    "stderrTruncated": {
                                      "type": "boolean",
                                      "description": "Diagnostics exceeded their 2 KiB capture limit; does not imply the machine result was truncated"
                                    },
                                    "status": {
                                      "type": "string",
                                      "enum": [
                                        "timed_out"
                                      ]
                                    }
                                  },
                                  "required": [
                                    "version",
                                    "stdout",
                                    "stderr",
                                    "stdoutTruncated",
                                    "stderrTruncated",
                                    "status"
                                  ],
                                  "additionalProperties": false
                                },
                                {
                                  "type": "object",
                                  "properties": {
                                    "version": {
                                      "type": "number",
                                      "enum": [
                                        1
                                      ]
                                    },
                                    "stdout": {
                                      "type": "string",
                                      "maxLength": 8192
                                    },
                                    "stderr": {
                                      "type": "string",
                                      "maxLength": 8192
                                    },
                                    "stdoutTruncated": {
                                      "type": "boolean",
                                      "description": "The machine-result stream exceeded its 8 KiB capture limit"
                                    },
                                    "stderrTruncated": {
                                      "type": "boolean",
                                      "description": "Diagnostics exceeded their 2 KiB capture limit; does not imply the machine result was truncated"
                                    },
                                    "status": {
                                      "type": "string",
                                      "enum": [
                                        "cancelled"
                                      ]
                                    }
                                  },
                                  "required": [
                                    "version",
                                    "stdout",
                                    "stderr",
                                    "stdoutTruncated",
                                    "stderrTruncated",
                                    "status"
                                  ],
                                  "additionalProperties": false
                                },
                                {
                                  "type": "object",
                                  "properties": {
                                    "version": {
                                      "type": "number",
                                      "enum": [
                                        1
                                      ]
                                    },
                                    "stdout": {
                                      "type": "string",
                                      "maxLength": 8192
                                    },
                                    "stderr": {
                                      "type": "string",
                                      "maxLength": 8192
                                    },
                                    "stdoutTruncated": {
                                      "type": "boolean",
                                      "description": "The machine-result stream exceeded its 8 KiB capture limit"
                                    },
                                    "stderrTruncated": {
                                      "type": "boolean",
                                      "description": "Diagnostics exceeded their 2 KiB capture limit; does not imply the machine result was truncated"
                                    },
                                    "status": {
                                      "type": "string",
                                      "enum": [
                                        "launch_failed"
                                      ]
                                    },
                                    "message": {
                                      "type": "string",
                                      "maxLength": 1024
                                    }
                                  },
                                  "required": [
                                    "version",
                                    "stdout",
                                    "stderr",
                                    "stdoutTruncated",
                                    "stderrTruncated",
                                    "status",
                                    "message"
                                  ],
                                  "additionalProperties": false
                                }
                              ]
                            }
                          },
                          "required": [
                            "status",
                            "process"
                          ],
                          "additionalProperties": false
                        },
                        {
                          "type": "object",
                          "properties": {
                            "status": {
                              "type": "string",
                              "enum": [
                                "failed"
                              ]
                            },
                            "reason": {
                              "type": "string",
                              "minLength": 1
                            },
                            "code": {
                              "type": "string",
                              "enum": [
                                "job_still_running"
                              ],
                              "description": "Present when the check was not run for a typed reason: `job_still_running`, a background job the task started outlived the check's wait"
                            }
                          },
                          "required": [
                            "status",
                            "reason"
                          ],
                          "additionalProperties": false
                        }
                      ],
                      "description": "Present only for a registered post-turn script. Its status and process output are independent of the subject task's status."
                    }
                  },
                  "required": [
                    "taskId",
                    "orgId",
                    "namespace",
                    "agentId",
                    "sessionId",
                    "taskOpencodeBranchId",
                    "taskLink",
                    "status",
                    "createdAt",
                    "startedAt",
                    "completedAt"
                  ],
                  "additionalProperties": false,
                  "description": "Task polling response"
                }
              }
            }
          },
          "400": {
            "description": "The request is invalid: a field failed validation (`details` lists the issues), or it was refused as a client error (`code` names the refusal where the route reports one).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "No valid task API key. Send `Authorization: Bearer tsk_…`.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The key lacks the `tasks:create` capability, or its principal may not act on this resource.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found in the key's organization.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "The resource is in a state that refuses this request (`code` names the conflict where the route reports one).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unexpected server error (`code` is `TASK_API_INTERNAL_ERROR`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Open work has not caught up yet; retry shortly (`code` is `NATIVE_OPEN_WORK_NOT_CAUGHT_UP`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/tasks/{taskId}/status": {
      "get": {
        "tags": [
          "Tasks"
        ],
        "summary": "Get a task's live status",
        "description": "Returns what the task's run is doing now, including whether it is waiting for input. A task that has not started yet answers 409 with `code` `TASK_NOT_DISPATCHED`.",
        "operationId": "getTaskStatus",
        "parameters": [
          {
            "in": "path",
            "name": "taskId",
            "required": true,
            "description": "The task's id.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The task's live status.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "taskId": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "orgId": {
                      "type": "string",
                      "minLength": 1
                    },
                    "agentId": {
                      "type": "string",
                      "minLength": 1
                    },
                    "taskOpencodeBranchId": {
                      "type": "string",
                      "minLength": 1,
                      "description": "Stable OpenCode branch ID backing the task conversation"
                    },
                    "taskLink": {
                      "type": "string",
                      "minLength": 1,
                      "description": "Relative browser path for opening the task conversation in the workspace UI"
                    },
                    "status": {
                      "type": "string",
                      "enum": [
                        "queued",
                        "running",
                        "succeeded",
                        "failed",
                        "cancelled",
                        "awaiting_input"
                      ],
                      "description": "Task-native polling status"
                    },
                    "createdAt": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "startedAt": {
                      "type": "string",
                      "format": "date-time",
                      "nullable": true
                    },
                    "completedAt": {
                      "type": "string",
                      "format": "date-time",
                      "nullable": true
                    },
                    "output": {
                      "type": "object",
                      "properties": {
                        "text": {
                          "type": "string",
                          "description": "Task textual output"
                        },
                        "files": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "properties": {
                              "id": {
                                "type": "string",
                                "minLength": 1,
                                "description": "Stable output file identifier within the task run"
                              },
                              "uri": {
                                "type": "string",
                                "pattern": "^org\\_drive\\:\\/\\/",
                                "description": "Canonical org Drive URI for this file"
                              },
                              "name": {
                                "type": "string",
                                "minLength": 1,
                                "description": "Display filename"
                              },
                              "source": {
                                "type": "string",
                                "enum": [
                                  "input",
                                  "generated"
                                ],
                                "description": "Whether the file was attached as input or generated by the task run"
                              },
                              "contentType": {
                                "type": "string",
                                "nullable": true,
                                "description": "MIME type"
                              },
                              "sizeBytes": {
                                "type": "integer",
                                "minimum": 0,
                                "nullable": true,
                                "description": "File size in bytes"
                              }
                            },
                            "required": [
                              "id",
                              "uri",
                              "name",
                              "source",
                              "contentType",
                              "sizeBytes"
                            ],
                            "additionalProperties": false,
                            "description": "File reference returned as task output context"
                          },
                          "description": "Referenced or generated file references"
                        },
                        "appliedSkills": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "properties": {
                              "skillId": {
                                "type": "string",
                                "minLength": 1,
                                "description": "Skill identifier"
                              },
                              "versionId": {
                                "type": "string",
                                "minLength": 1,
                                "nullable": true,
                                "description": "Optional skill version ID to pin for deterministic behavior"
                              }
                            },
                            "required": [
                              "skillId"
                            ],
                            "additionalProperties": false,
                            "description": "Skill reference used by a task"
                          },
                          "description": "Skills this run used, as recorded from its tool calls; a skill only requested or listed is not here"
                        },
                        "structured": {
                          "description": "Validated structured answer; present only when the request declared an outputSchema"
                        }
                      },
                      "required": [
                        "text",
                        "files",
                        "appliedSkills"
                      ],
                      "additionalProperties": false,
                      "description": "Task success result payload"
                    },
                    "error": {
                      "type": "object",
                      "properties": {
                        "code": {
                          "type": "string",
                          "minLength": 1,
                          "description": "Machine-readable error code"
                        },
                        "message": {
                          "type": "string",
                          "minLength": 1,
                          "description": "Human-readable error message"
                        }
                      },
                      "required": [
                        "code",
                        "message"
                      ],
                      "additionalProperties": false,
                      "description": "Task failure payload"
                    },
                    "latestPrompt": {
                      "type": "object",
                      "properties": {
                        "promptId": {
                          "type": "string",
                          "minLength": 1
                        },
                        "clientMessageId": {
                          "type": "string",
                          "nullable": true
                        },
                        "settled": {
                          "type": "boolean"
                        },
                        "outcome": {
                          "type": "string",
                          "enum": [
                            "succeeded",
                            "failed",
                            "cancelled",
                            "unsettled"
                          ]
                        },
                        "run": {
                          "type": "object",
                          "properties": {
                            "id": {
                              "type": "string",
                              "minLength": 1
                            },
                            "status": {
                              "type": "string",
                              "minLength": 1,
                              "description": "Raw task_run status of the run that accepted this prompt — honest about 'sleeping'"
                            }
                          },
                          "required": [
                            "id",
                            "status"
                          ],
                          "additionalProperties": false
                        }
                      },
                      "required": [
                        "promptId",
                        "clientMessageId",
                        "settled",
                        "outcome",
                        "run"
                      ],
                      "additionalProperties": false,
                      "description": "ADVISORY task-level convenience: the task's most recent turn, derived with the same durable-facts rules as the prompt-scoped result endpoint. NOT authoritative for a specific caller's prompt — a newer turn from any caller replaces it. To track YOUR prompt, use GET /api/v1/tasks/:taskId/prompts/:promptId/result keyed on the promptId the create response returned."
                    }
                  },
                  "required": [
                    "taskId",
                    "orgId",
                    "agentId",
                    "taskOpencodeBranchId",
                    "taskLink",
                    "status",
                    "createdAt",
                    "startedAt",
                    "completedAt"
                  ],
                  "additionalProperties": false,
                  "description": "Task-native polling response sourced from task and task_run rows"
                }
              }
            }
          },
          "400": {
            "description": "The request is invalid: a field failed validation (`details` lists the issues), or it was refused as a client error (`code` names the refusal where the route reports one).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "No valid task API key. Send `Authorization: Bearer tsk_…`.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The key lacks the `tasks:read` capability, or its principal may not act on this resource.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found in the key's organization.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "The resource is in a state that refuses this request (`code` names the conflict where the route reports one).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unexpected server error (`code` is `TASK_API_INTERNAL_ERROR`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Open work has not caught up yet; retry shortly (`code` is `NATIVE_OPEN_WORK_NOT_CAUGHT_UP`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/tasks/{taskId}/prompts/{promptId}/result": {
      "get": {
        "tags": [
          "Tasks"
        ],
        "summary": "Get the result of one prompt",
        "description": "Available where the prompt-result feature is on for the key's organization; elsewhere this answers 404.",
        "operationId": "getTaskPromptResult",
        "parameters": [
          {
            "in": "path",
            "name": "taskId",
            "required": true,
            "description": "The task's id.",
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "path",
            "name": "promptId",
            "required": true,
            "description": "The prompt's id: `promptId` in the prompt response.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The prompt's result.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "taskId": {
                      "type": "string",
                      "minLength": 1
                    },
                    "taskRunId": {
                      "type": "string",
                      "minLength": 1,
                      "description": "Run (sandbox epoch) that accepted this prompt"
                    },
                    "promptId": {
                      "type": "string",
                      "minLength": 1,
                      "description": "task_run_prompt identifier this result is scoped to"
                    },
                    "clientMessageId": {
                      "type": "string",
                      "nullable": true,
                      "description": "Caller correlation id recorded on the prompt row (server-generated when the prompt request omitted it)"
                    },
                    "settled": {
                      "type": "boolean",
                      "description": "True once THIS prompt's outcome is durably known; later runs or prompts on the task never change it"
                    },
                    "outcome": {
                      "type": "string",
                      "enum": [
                        "succeeded",
                        "failed",
                        "cancelled",
                        "unsettled"
                      ],
                      "description": "succeeded = this prompt's turn finalized; failed = the prompt errored or its run ended before delivering the turn; cancelled = its run was cancelled first; unsettled = still in flight"
                    },
                    "prompt": {
                      "type": "object",
                      "properties": {
                        "lifecycleStatus": {
                          "type": "string",
                          "minLength": 1,
                          "description": "Raw task_run_prompt lifecycle status"
                        },
                        "finalizedAt": {
                          "type": "string",
                          "format": "date-time",
                          "nullable": true,
                          "description": "When this prompt's turn was durably recognized complete"
                        }
                      },
                      "required": [
                        "lifecycleStatus",
                        "finalizedAt"
                      ],
                      "additionalProperties": false
                    },
                    "run": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string",
                          "minLength": 1
                        },
                        "status": {
                          "type": "string",
                          "minLength": 1,
                          "description": "Raw task_run status — honest about 'sleeping', unlike the task-status route's mapping"
                        },
                        "endedAt": {
                          "type": "string",
                          "format": "date-time",
                          "nullable": true
                        }
                      },
                      "required": [
                        "id",
                        "status",
                        "endedAt"
                      ],
                      "additionalProperties": false
                    },
                    "output": {
                      "type": "object",
                      "properties": {
                        "text": {
                          "type": "string",
                          "description": "Task textual output"
                        },
                        "files": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "properties": {
                              "id": {
                                "type": "string",
                                "minLength": 1,
                                "description": "Stable output file identifier within the task run"
                              },
                              "uri": {
                                "type": "string",
                                "pattern": "^org\\_drive\\:\\/\\/",
                                "description": "Canonical org Drive URI for this file"
                              },
                              "name": {
                                "type": "string",
                                "minLength": 1,
                                "description": "Display filename"
                              },
                              "source": {
                                "type": "string",
                                "enum": [
                                  "input",
                                  "generated"
                                ],
                                "description": "Whether the file was attached as input or generated by the task run"
                              },
                              "contentType": {
                                "type": "string",
                                "nullable": true,
                                "description": "MIME type"
                              },
                              "sizeBytes": {
                                "type": "integer",
                                "minimum": 0,
                                "nullable": true,
                                "description": "File size in bytes"
                              }
                            },
                            "required": [
                              "id",
                              "uri",
                              "name",
                              "source",
                              "contentType",
                              "sizeBytes"
                            ],
                            "additionalProperties": false,
                            "description": "File reference returned as task output context"
                          },
                          "description": "Referenced or generated file references"
                        },
                        "appliedSkills": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "properties": {
                              "skillId": {
                                "type": "string",
                                "minLength": 1,
                                "description": "Skill identifier"
                              },
                              "versionId": {
                                "type": "string",
                                "minLength": 1,
                                "nullable": true,
                                "description": "Optional skill version ID to pin for deterministic behavior"
                              }
                            },
                            "required": [
                              "skillId"
                            ],
                            "additionalProperties": false,
                            "description": "Skill reference used by a task"
                          },
                          "description": "Skills this run used, as recorded from its tool calls; a skill only requested or listed is not here"
                        },
                        "structured": {
                          "description": "Validated structured answer; present only when the request declared an outputSchema"
                        }
                      },
                      "required": [
                        "text",
                        "files",
                        "appliedSkills"
                      ],
                      "additionalProperties": false,
                      "description": "Present only when outcome is succeeded; text and files may each be empty — success is theirs jointly, not text's alone"
                    },
                    "error": {
                      "type": "object",
                      "properties": {
                        "code": {
                          "type": "string",
                          "minLength": 1,
                          "description": "Machine-readable error code"
                        },
                        "message": {
                          "type": "string",
                          "minLength": 1,
                          "description": "Human-readable error message"
                        }
                      },
                      "required": [
                        "code",
                        "message"
                      ],
                      "additionalProperties": false,
                      "description": "Present only when outcome is failed or cancelled"
                    }
                  },
                  "required": [
                    "taskId",
                    "taskRunId",
                    "promptId",
                    "clientMessageId",
                    "settled",
                    "outcome",
                    "prompt",
                    "run"
                  ],
                  "additionalProperties": false,
                  "description": "Authoritative result of one specific task prompt (turn), correct across a task's many runs"
                }
              }
            }
          },
          "400": {
            "description": "The request is invalid: a field failed validation (`details` lists the issues), or it was refused as a client error (`code` names the refusal where the route reports one).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "No valid task API key. Send `Authorization: Bearer tsk_…`.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The key lacks the `tasks:read` capability, or its principal may not act on this resource.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found in the key's organization, or the prompt-result feature is off for it.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "The resource is in a state that refuses this request (`code` names the conflict where the route reports one).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unexpected server error (`code` is `TASK_API_INTERNAL_ERROR`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Open work has not caught up yet; retry shortly (`code` is `NATIVE_OPEN_WORK_NOT_CAUGHT_UP`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/tasks/{taskId}/share-link": {
      "post": {
        "tags": [
          "Tasks"
        ],
        "summary": "Create or reuse a share link",
        "description": "The body is optional; `mode` defaults to `view`.",
        "operationId": "createTaskShareLink",
        "parameters": [
          {
            "in": "path",
            "name": "taskId",
            "required": true,
            "description": "The task's id.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "mode": {
                    "type": "string",
                    "enum": [
                      "view",
                      "edit"
                    ],
                    "description": "Share mode to publish or reuse. Use edit to grant org-member editor access and return the live task route.",
                    "default": "view"
                  }
                },
                "additionalProperties": false,
                "description": "Task share link publish request"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The task's share link.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "shareId": {
                      "type": "string",
                      "minLength": 1,
                      "description": "Opaque share token"
                    },
                    "shareUrl": {
                      "type": "string",
                      "format": "uri",
                      "description": "Share URL for the published task tree"
                    },
                    "rootTaskId": {
                      "type": "string",
                      "minLength": 1,
                      "description": "Root task ID associated with the shared task tree"
                    },
                    "visibility": {
                      "type": "string",
                      "enum": [
                        "org_member"
                      ],
                      "description": "Visibility policy for shared task trees. org_member means any member in the same organization can view."
                    },
                    "mode": {
                      "type": "string",
                      "enum": [
                        "view",
                        "edit"
                      ],
                      "description": "Access mode for shared task links. view = read-only transcript. edit = org members can interact with the agent."
                    }
                  },
                  "required": [
                    "shareId",
                    "shareUrl",
                    "rootTaskId",
                    "visibility",
                    "mode"
                  ],
                  "additionalProperties": false,
                  "description": "Task share link publish or reuse result"
                }
              }
            }
          },
          "400": {
            "description": "The request is invalid: a field failed validation (`details` lists the issues), or it was refused as a client error (`code` names the refusal where the route reports one).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "No valid task API key. Send `Authorization: Bearer tsk_…`.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The key lacks the `tasks:create` capability, or its principal may not act on this resource.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found in the key's organization.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "The resource is in a state that refuses this request (`code` names the conflict where the route reports one).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unexpected server error (`code` is `TASK_API_INTERNAL_ERROR`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Open work has not caught up yet; retry shortly (`code` is `NATIVE_OPEN_WORK_NOT_CAUGHT_UP`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/tasks/{taskId}/files/{fileId}/download-url": {
      "post": {
        "tags": [
          "Tasks"
        ],
        "summary": "Get a download URL for an output file",
        "description": "The URL is short-lived: the response carries its `expiresAt` and `ttlSeconds`.",
        "operationId": "createTaskFileDownloadUrl",
        "parameters": [
          {
            "in": "path",
            "name": "taskId",
            "required": true,
            "description": "The task's id.",
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "path",
            "name": "fileId",
            "required": true,
            "description": "The file's id.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "A signed download URL.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "url": {
                      "type": "string",
                      "format": "uri",
                      "description": "Short-lived URL for downloading the file"
                    },
                    "method": {
                      "type": "string",
                      "enum": [
                        "GET"
                      ]
                    },
                    "expiresAt": {
                      "type": "string",
                      "format": "date-time",
                      "description": "ISO timestamp when this URL expires"
                    },
                    "ttlSeconds": {
                      "type": "integer",
                      "exclusiveMinimum": true,
                      "minimum": 0,
                      "description": "Time to live for the signed URL in seconds"
                    }
                  },
                  "required": [
                    "url",
                    "method",
                    "expiresAt",
                    "ttlSeconds"
                  ],
                  "additionalProperties": false,
                  "description": "On-demand signed download URL for a task output file"
                }
              }
            }
          },
          "400": {
            "description": "The request is invalid: a field failed validation (`details` lists the issues), or it was refused as a client error (`code` names the refusal where the route reports one).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "No valid task API key. Send `Authorization: Bearer tsk_…`.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "The download is gated by the first-download paywall for the key's organization (`code` `DOWNLOAD_PAYWALL_GATED`).",
            "headers": {
              "Cache-Control": {
                "description": "`no-store`",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The key lacks the `files:read` capability, or its principal may not act on this resource.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found in the key's organization.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "The resource is in a state that refuses this request (`code` names the conflict where the route reports one).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unexpected server error (`code` is `TASK_API_INTERNAL_ERROR`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Open work has not caught up yet; retry shortly (`code` is `NATIVE_OPEN_WORK_NOT_CAUGHT_UP`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/tasks/{taskId}/cancel": {
      "post": {
        "tags": [
          "Tasks"
        ],
        "summary": "Cancel a task",
        "description": "Cancelling a task that already finished is not an error: the answer reports its final status with `alreadyTerminal: true`.",
        "operationId": "cancelTask",
        "parameters": [
          {
            "in": "path",
            "name": "taskId",
            "required": true,
            "description": "The task's id.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "What the cancellation did.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean",
                      "enum": [
                        true
                      ]
                    },
                    "taskId": {
                      "type": "string",
                      "description": "The dispatch-run id the cancel addressed"
                    },
                    "status": {
                      "type": "string",
                      "enum": [
                        "cancel_requested",
                        "succeeded",
                        "failed",
                        "cancelled"
                      ],
                      "description": "cancel_requested = a live run was asked to stop and terminalizes as cancelled through its own funnel; cancelled with alreadyTerminal=false = a queued task was cancelled before it ran; any terminal value with alreadyTerminal=true = the run had already finished with that status"
                    },
                    "alreadyTerminal": {
                      "type": "boolean",
                      "description": "True when the run was already terminal and this cancel was a no-op"
                    }
                  },
                  "required": [
                    "ok",
                    "taskId",
                    "status",
                    "alreadyTerminal"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "400": {
            "description": "The request is invalid: a field failed validation (`details` lists the issues), or it was refused as a client error (`code` names the refusal where the route reports one).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "No valid task API key. Send `Authorization: Bearer tsk_…`.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The key lacks the `tasks:create` capability, or its principal may not act on this resource.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found in the key's organization.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "The resource is in a state that refuses this request (`code` names the conflict where the route reports one).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unexpected server error (`code` is `TASK_API_INTERNAL_ERROR`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Open work has not caught up yet; retry shortly (`code` is `NATIVE_OPEN_WORK_NOT_CAUGHT_UP`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/tasks/prompt": {
      "post": {
        "tags": [
          "Tasks"
        ],
        "summary": "Send a prompt",
        "description": "Starts a task, or continues one when `taskId` is set. Name the agent with `agentId`, or omit it and send `ownerUserEmail` with `workspaceSlug` to use that person's agent in that workspace; a key scoped to specific agents must send `agentId`.",
        "operationId": "promptTask",
        "parameters": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "agentId": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Target agent ID. When omitted, the agent is derived from (ownerUserEmail + workspaceSlug) — see workspaceSlug."
                  },
                  "taskId": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Existing task to continue; omit to create a new task under the agent"
                  },
                  "taskOpencodeBranchId": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Stable OpenCode branch identifier; omit for new tasks (will be derived)"
                  },
                  "workspaceId": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Optional workspace context captured for the task conversation; required when callers want workspace-backed task artifacts"
                  },
                  "projectId": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Optional sidebar project to file a NEW task under (e.g. a recurring task's scheduled project); ignored for follow-up prompts"
                  },
                  "title": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 280,
                    "description": "Optional explicit task title used only when creating a new task conversation; ignored for follow-up prompts"
                  },
                  "clientMessageId": {
                    "type": "string",
                    "pattern": "^msg\\_",
                    "minLength": 5,
                    "description": "Caller-supplied OpenCode-compatible message id (must start with 'msg_'). Mirrors the web UI path which generates its own id client-side and passes it through. If omitted, a server-generated id is used."
                  },
                  "clientRequestId": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Caller-supplied idempotency token for new-task creation. When two new-task prompts carry the same clientRequestId the task-runtime returns the existing task run instead of creating a duplicate. Mirrors the web UI path. If omitted, a server-generated token is used (no cross-call dedup). Ignored for follow-up prompts on an existing taskId."
                  },
                  "fileIds": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "minLength": 1
                    },
                    "default": [],
                    "description": "Attached task file identifiers to make available to the first prompt"
                  },
                  "skills": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "skillId": {
                          "type": "string",
                          "minLength": 1,
                          "description": "Skill identifier"
                        },
                        "versionId": {
                          "type": "string",
                          "minLength": 1,
                          "nullable": true,
                          "description": "Optional skill version ID to pin for deterministic behavior"
                        }
                      },
                      "required": [
                        "skillId"
                      ],
                      "additionalProperties": false,
                      "description": "Skill reference used by a task"
                    },
                    "default": [],
                    "description": "Requested skill references to apply when creating a new task conversation"
                  },
                  "skillInlineContent": {
                    "type": "object",
                    "properties": {
                      "skillId": {
                        "type": "string",
                        "minLength": 1,
                        "description": "Skill whose content is being overridden for this dispatch"
                      },
                      "content": {
                        "type": "string",
                        "description": "Inline skill markdown that replaces the storagePath lookup for skillId"
                      }
                    },
                    "required": [
                      "skillId",
                      "content"
                    ],
                    "additionalProperties": false,
                    "description": "Per-dispatch inline override for one of the skill references' content. Service-principal-gated at the task-api boundary. The referenced skillId must appear in `skills`; the inline content is delivered as a `skill-inline-content:<skillId>` noReplyPrompt and the agent is instructed to read it instead of running `context-cli skill pull`."
                  },
                  "outputSchema": {
                    "description": "Output contract for a NEW task conversation: a JSON Schema the agent's final answer must satisfy. Declared by the REQUESTER (never by the agent), validated server-side, and submitted from the sandbox with `context-cli task submit-output`. The rendered schema is injected into the task context before the agent starts. A task that declares this and ends without an accepted submission is reported FAILED. Ignored for follow-up prompts on an existing taskId — the contract is set at creation."
                  },
                  "prompt": {
                    "type": "object",
                    "properties": {
                      "text": {
                        "type": "string",
                        "minLength": 1,
                        "description": "User-visible prompt text"
                      },
                      "parts": {
                        "type": "array",
                        "items": {
                          "description": "JSON object stored in archived task snapshots"
                        },
                        "description": "Optional rich prompt parts (OpenCode-compatible)"
                      },
                      "model": {
                        "type": "object",
                        "properties": {
                          "providerID": {
                            "type": "string",
                            "minLength": 1,
                            "description": "Configured provider identifier from the agent config"
                          },
                          "modelID": {
                            "type": "string",
                            "minLength": 1,
                            "description": "Configured model identifier within the selected provider"
                          }
                        },
                        "required": [
                          "providerID",
                          "modelID"
                        ],
                        "additionalProperties": false,
                        "description": "Optional explicit model override, in the legacy wire's `{providerID, modelID}` shape",
                        "nullable": true
                      },
                      "variant": {
                        "type": "string",
                        "minLength": 1,
                        "description": "Optional opencode model variant key for the explicit model override (per-request provider-options overlay, e.g. an effort preset). Requires `model`: a variant is a refinement of an explicitly selected model, never of the agent default.",
                        "nullable": true
                      },
                      "noReplyPrompts": {
                        "type": "array",
                        "items": {
                          "type": "object",
                          "properties": {
                            "messageID": {
                              "type": "string",
                              "minLength": 1,
                              "description": "Optional stable synthetic message id for the no-reply prompt"
                            },
                            "system": {
                              "type": "string",
                              "minLength": 1,
                              "description": "System label for the no-reply prompt"
                            },
                            "parts": {
                              "type": "array",
                              "items": {
                                "description": "JSON object stored in archived task snapshots"
                              },
                              "minItems": 1,
                              "description": "Serialized prompt parts to inject before the committed prompt"
                            },
                            "fatal": {
                              "type": "boolean",
                              "description": "Whether failure to inject this no-reply prompt should abort dispatch"
                            }
                          },
                          "required": [
                            "system",
                            "parts"
                          ],
                          "additionalProperties": false
                        },
                        "description": "Optional synthetic no-reply prompts injected before the committed prompt"
                      }
                    },
                    "required": [
                      "text"
                    ],
                    "additionalProperties": false,
                    "description": "Prompt payload for the task, as the Task API door accepts it"
                  },
                  "ownerUserId": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Optional execution owner override by user ID. Service keys may set this. Mutually exclusive with ownerUserEmail."
                  },
                  "ownerUserEmail": {
                    "type": "string",
                    "format": "email",
                    "description": "Optional execution owner override by user email; resolved within the task key's organization. Service keys may set this. Mutually exclusive with ownerUserId. Required when agentId is omitted so the agent can be derived."
                  },
                  "workspaceSlug": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Optional workspace slug used to derive the execution agent when agentId is omitted. Requires ownerUserEmail to identify the executing user."
                  },
                  "shareMode": {
                    "type": "string",
                    "enum": [
                      "view",
                      "edit"
                    ],
                    "description": "When set, publishes a share link for the task and includes it in the response. 'edit' returns a live task route for org members."
                  }
                },
                "required": [
                  "prompt"
                ],
                "additionalProperties": false,
                "description": "Task API prompt request payload"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "The prompt was accepted by a task run, or queued for one (`outcome`).",
            "content": {
              "application/json": {
                "schema": {
                  "anyOf": [
                    {
                      "type": "object",
                      "properties": {
                        "outcome": {
                          "type": "string",
                          "enum": [
                            "prompt-accepted"
                          ],
                          "description": "Absent on legacy accepted responses"
                        },
                        "taskRunId": {
                          "type": "string",
                          "minLength": 1,
                          "description": "Active task run that accepted the prompt"
                        },
                        "taskId": {
                          "type": "string",
                          "minLength": 1,
                          "description": "Task that owns the run"
                        },
                        "promptId": {
                          "type": "string",
                          "minLength": 1,
                          "description": "Durable task_run_prompt id for THIS accepted prompt — the key for the prompt-scoped result endpoint, so a caller can track its own turn across the task's many runs"
                        },
                        "clientMessageId": {
                          "type": "string",
                          "minLength": 1,
                          "description": "Client message id recorded on the prompt row (server-generated when the request omitted it)"
                        },
                        "taskOpencodeBranchId": {
                          "type": "string",
                          "minLength": 1,
                          "description": "OpenCode branch that owns the task conversation"
                        },
                        "shareLink": {
                          "type": "object",
                          "properties": {
                            "shareId": {
                              "type": "string",
                              "minLength": 1
                            },
                            "shareUrl": {
                              "type": "string",
                              "format": "uri"
                            },
                            "mode": {
                              "type": "string",
                              "minLength": 1
                            }
                          },
                          "required": [
                            "shareId",
                            "shareUrl",
                            "mode"
                          ],
                          "additionalProperties": false,
                          "description": "Share link for the task, present when shareMode was requested"
                        },
                        "modelSwitch": {
                          "type": "object",
                          "properties": {
                            "from": {
                              "type": "object",
                              "properties": {
                                "providerID": {
                                  "type": "string",
                                  "minLength": 1,
                                  "description": "Configured provider identifier from the agent config"
                                },
                                "modelID": {
                                  "type": "string",
                                  "minLength": 1,
                                  "description": "Configured model identifier within the selected provider"
                                }
                              },
                              "required": [
                                "providerID",
                                "modelID"
                              ],
                              "additionalProperties": false,
                              "description": "The model this turn would have run on (the caller's pick, else the task's recorded model), which this deployment does not serve"
                            },
                            "to": {
                              "type": "object",
                              "properties": {
                                "providerID": {
                                  "type": "string",
                                  "minLength": 1,
                                  "description": "Configured provider identifier from the agent config"
                                },
                                "modelID": {
                                  "type": "string",
                                  "minLength": 1,
                                  "description": "Configured model identifier within the selected provider"
                                }
                              },
                              "required": [
                                "providerID",
                                "modelID"
                              ],
                              "additionalProperties": false,
                              "description": "The model this turn runs on instead; the task's later turns stay on it until a new pick"
                            },
                            "reason": {
                              "type": "string",
                              "enum": [
                                "renamed",
                                "not_served"
                              ],
                              "description": "Why the task's model was switched: renamed (same model, new id) or not_served (moved to the deployment default)"
                            }
                          },
                          "required": [
                            "from",
                            "to",
                            "reason"
                          ],
                          "additionalProperties": false,
                          "description": "The turn's model was switched at accept, not refused. Absent when the turn kept its model, or when this response answers an idempotent retry (same clientMessageId), which does not re-run the resolver"
                        }
                      },
                      "required": [
                        "taskRunId",
                        "taskId",
                        "promptId",
                        "clientMessageId",
                        "taskOpencodeBranchId"
                      ],
                      "additionalProperties": false,
                      "description": "Prompt durably accepted by a task run"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "outcome": {
                          "type": "string",
                          "enum": [
                            "dispatch-enqueued"
                          ]
                        },
                        "dispatchRunId": {
                          "type": "string",
                          "minLength": 1,
                          "description": "Dispatch ledger entry waiting for the runtime to claim the prompt"
                        },
                        "taskId": {
                          "type": "string",
                          "minLength": 1,
                          "description": "Root task that owns the queued prompt, not a dispatch ledger id"
                        },
                        "clientMessageId": {
                          "type": "string",
                          "minLength": 1,
                          "description": "Retry identity preserved until the runtime accepts this prompt"
                        },
                        "taskOpencodeBranchId": {
                          "type": "string",
                          "minLength": 1,
                          "description": "OpenCode branch that will receive the prompt"
                        },
                        "taskRunId": {
                          "not": {},
                          "description": "Unavailable until a runtime claims the dispatch"
                        },
                        "promptId": {
                          "not": {},
                          "description": "Unavailable until a runtime accepts the prompt"
                        },
                        "shareLink": {
                          "type": "object",
                          "properties": {
                            "shareId": {
                              "type": "string",
                              "minLength": 1
                            },
                            "shareUrl": {
                              "type": "string",
                              "format": "uri"
                            },
                            "mode": {
                              "type": "string",
                              "minLength": 1
                            }
                          },
                          "required": [
                            "shareId",
                            "shareUrl",
                            "mode"
                          ],
                          "additionalProperties": false,
                          "description": "Share link for the task, present when shareMode was requested"
                        },
                        "modelSwitch": {
                          "type": "object",
                          "properties": {
                            "from": {
                              "type": "object",
                              "properties": {
                                "providerID": {
                                  "type": "string",
                                  "minLength": 1,
                                  "description": "Configured provider identifier from the agent config"
                                },
                                "modelID": {
                                  "type": "string",
                                  "minLength": 1,
                                  "description": "Configured model identifier within the selected provider"
                                }
                              },
                              "required": [
                                "providerID",
                                "modelID"
                              ],
                              "additionalProperties": false,
                              "description": "The model this turn would have run on (the caller's pick, else the task's recorded model), which this deployment does not serve"
                            },
                            "to": {
                              "type": "object",
                              "properties": {
                                "providerID": {
                                  "type": "string",
                                  "minLength": 1,
                                  "description": "Configured provider identifier from the agent config"
                                },
                                "modelID": {
                                  "type": "string",
                                  "minLength": 1,
                                  "description": "Configured model identifier within the selected provider"
                                }
                              },
                              "required": [
                                "providerID",
                                "modelID"
                              ],
                              "additionalProperties": false,
                              "description": "The model this turn runs on instead; the task's later turns stay on it until a new pick"
                            },
                            "reason": {
                              "type": "string",
                              "enum": [
                                "renamed",
                                "not_served"
                              ],
                              "description": "Why the task's model was switched: renamed (same model, new id) or not_served (moved to the deployment default)"
                            }
                          },
                          "required": [
                            "from",
                            "to",
                            "reason"
                          ],
                          "additionalProperties": false,
                          "description": "The turn's model was switched at accept, not refused. Absent when the turn kept its model, or when this response answers an idempotent retry (same clientMessageId), which does not re-run the resolver"
                        }
                      },
                      "required": [
                        "outcome",
                        "dispatchRunId",
                        "taskId",
                        "clientMessageId",
                        "taskOpencodeBranchId"
                      ],
                      "additionalProperties": false,
                      "description": "Prompt queued for asynchronous runtime acceptance; no runtime or prompt record is claimed"
                    }
                  ],
                  "description": "Result of the unified task prompt endpoint"
                }
              }
            }
          },
          "400": {
            "description": "The request is invalid: a field failed validation (`details` lists the issues), or it was refused as a client error (`code` names the refusal where the route reports one).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "No valid task API key. Send `Authorization: Bearer tsk_…`.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The key lacks the `tasks:create` capability, or its principal may not act on this resource.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found in the key's organization.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "The resource is in a state that refuses this request (`code` names the conflict where the route reports one).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unexpected server error (`code` is `TASK_API_INTERNAL_ERROR`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Open work has not caught up yet; retry shortly (`code` is `NATIVE_OPEN_WORK_NOT_CAUGHT_UP`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/workflow-selection": {
      "post": {
        "tags": [
          "Workflow selection"
        ],
        "summary": "Select workflows for a case",
        "description": "Blocks until the selection finishes, which can take several minutes.",
        "operationId": "selectWorkflows",
        "parameters": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "caseId": {
                    "type": "string",
                    "description": "SF case number, echoed in response"
                  },
                  "caseName": {
                    "type": "string",
                    "description": "SF case title"
                  },
                  "caseDescription": {
                    "type": "string",
                    "description": "Summary of tech pre-processed logs"
                  },
                  "userEmail": {
                    "type": "string",
                    "format": "email",
                    "description": "Requesting user email, echoed in response"
                  },
                  "problemAreas": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "maxItems": 100,
                    "description": "Compatibility shape: workflow tags to pre-filter by, sent at the top level. Prefer filters.problemAreas, which wins when both are present. Resolve with resolveProblemAreas — never read this field directly."
                  },
                  "filters": {
                    "type": "object",
                    "properties": {
                      "problemAreas": {
                        "type": "array",
                        "items": {
                          "type": "string"
                        },
                        "maxItems": 100,
                        "description": "Workflow tags to pre-filter by (OR logic). Canonical location."
                      },
                      "teams": {
                        "type": "array",
                        "items": {
                          "type": "string"
                        },
                        "minItems": 1,
                        "description": "Team slugs (maps to workspace slugs)"
                      }
                    },
                    "required": [
                      "teams"
                    ],
                    "additionalProperties": false
                  },
                  "metadata": {
                    "type": "object",
                    "additionalProperties": {},
                    "description": "Opaque metadata (logFiles, urgency, etc.)"
                  }
                },
                "required": [
                  "caseId",
                  "caseName",
                  "caseDescription",
                  "userEmail",
                  "filters"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The selected workflows.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "requestId": {
                      "type": "string",
                      "description": "Unique identifier for this selection request"
                    },
                    "caseId": {
                      "type": "string",
                      "description": "Echoed from request"
                    },
                    "userEmail": {
                      "type": "string",
                      "description": "Echoed from request"
                    },
                    "organization": {
                      "type": "string",
                      "description": "Organization name"
                    },
                    "teams": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "description": "Workspace ID"
                          },
                          "name": {
                            "type": "string",
                            "description": "Workspace name"
                          },
                          "workflows": {
                            "type": "array",
                            "items": {
                              "type": "object",
                              "properties": {
                                "id": {
                                  "type": "string",
                                  "description": "Workflow ID"
                                },
                                "name": {
                                  "type": "string",
                                  "description": "Workflow name"
                                },
                                "description": {
                                  "type": "string",
                                  "nullable": true,
                                  "description": "Workflow description"
                                },
                                "category": {
                                  "type": "string",
                                  "nullable": true,
                                  "description": "Primary category (first tag or null)"
                                },
                                "confidenceScore": {
                                  "type": "number",
                                  "minimum": 0,
                                  "maximum": 100,
                                  "description": "Relevance score 0-100"
                                },
                                "reasoning": {
                                  "type": "string",
                                  "description": "Why this workflow matches the case"
                                },
                                "relevantKeywords": {
                                  "type": "array",
                                  "items": {
                                    "type": "string"
                                  },
                                  "description": "Keywords connecting this workflow to the case"
                                }
                              },
                              "required": [
                                "id",
                                "name",
                                "description",
                                "category",
                                "confidenceScore",
                                "reasoning",
                                "relevantKeywords"
                              ],
                              "additionalProperties": false
                            }
                          },
                          "knowledge": {
                            "type": "array",
                            "items": {
                              "type": "object",
                              "properties": {
                                "id": {
                                  "type": "string"
                                },
                                "name": {
                                  "type": "string"
                                },
                                "description": {
                                  "type": "string"
                                },
                                "confidenceScore": {
                                  "type": "number",
                                  "minimum": 0,
                                  "maximum": 100
                                },
                                "reasoning": {
                                  "type": "string"
                                },
                                "relevantKeywords": {
                                  "type": "array",
                                  "items": {
                                    "type": "string"
                                  }
                                }
                              },
                              "required": [
                                "id",
                                "name",
                                "description",
                                "confidenceScore",
                                "reasoning",
                                "relevantKeywords"
                              ],
                              "additionalProperties": false
                            }
                          }
                        },
                        "required": [
                          "id",
                          "name",
                          "workflows",
                          "knowledge"
                        ],
                        "additionalProperties": false
                      },
                      "description": "Results grouped by workspace (mapped to teams)"
                    },
                    "files": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      },
                      "description": "File references from metadata"
                    },
                    "prompt": {
                      "type": "string",
                      "description": "Reserved for future optimized prompt generation"
                    }
                  },
                  "required": [
                    "requestId",
                    "caseId",
                    "userEmail",
                    "organization",
                    "teams",
                    "files"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "400": {
            "description": "The request is invalid: a field failed validation (`details` lists the issues), or it was refused as a client error (`code` names the refusal where the route reports one).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "No valid task API key. Send `Authorization: Bearer tsk_…`.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The key lacks the `workflows:read` capability, or its principal may not act on this resource.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "A team in `filters.teams` was not found in the key's organization.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "The resource is in a state that refuses this request (`code` names the conflict where the route reports one).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unexpected server error (`code` is `TASK_API_INTERNAL_ERROR`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  }
}
