> ## Documentation Index
> Fetch the complete documentation index at: https://docs.twill.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Create task

> Dispatch a new task and start an agent run.

Create a new task from a command prompt. The agent picks the repository at runtime from the workspace's connected repos, so no repository or branch needs to be supplied. You can optionally set `userIntent` to choose the initial run type and attach `files` so the agent can reference uploaded assets in its first message. The response includes the created task plus the first job that was queued for it.


## OpenAPI

````yaml /openapi.json POST /tasks
openapi: 3.0.3
info:
  title: Twill API
  version: 1.0.0
  description: Programmatically create and manage Twill tasks via REST API.
servers:
  - url: https://twill.ai/api/v1
security:
  - bearerAuth: []
tags:
  - name: Tasks
    description: Create and manage tasks.
paths:
  /tasks:
    post:
      tags:
        - Tasks
      summary: Create task
      description: Create a new task and start an agent run.
      operationId: createTask
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateTaskRequest'
            example:
              command: Add a dark mode toggle to the settings page
              userIntent: PLAN
              agent: claude-code/sonnet
              files:
                - filename: design-spec.md
                  mediaType: text/markdown
                  url: https://example.com/design-spec.md
      responses:
        '201':
          description: Task created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CreateTaskResponse'
        '400':
          $ref: '#/components/responses/ValidationError'
        '401':
          $ref: '#/components/responses/UnauthorizedError'
        '429':
          $ref: '#/components/responses/RateLimitedError'
        '500':
          $ref: '#/components/responses/InternalError'
components:
  schemas:
    CreateTaskRequest:
      type: object
      required:
        - command
      properties:
        command:
          type: string
          description: Task description or instructions for the agent.
        agent:
          type: string
          description: >-
            Provider+model id override (e.g. claude-code/sonnet, codex/gpt-5.4,
            open-code/openai/gpt-5.4).
        userIntent:
          type: string
          enum:
            - SWE
            - PLAN
            - ASK
            - DEV_ENVIRONMENT
          default: SWE
          description: >-
            Run type: SWE (implement directly), PLAN (produce a plan), ASK (Q&A
            mode), or DEV_ENVIRONMENT (dev environment setup).
        title:
          type: string
          description: Optional task title (auto-generated if not provided).
        files:
          type: array
          description: Optional file attachments provided as UI message file parts.
          items:
            $ref: '#/components/schemas/FilePart'
    CreateTaskResponse:
      type: object
      required:
        - task
        - job
      properties:
        task:
          $ref: '#/components/schemas/TaskSummary'
        job:
          $ref: '#/components/schemas/JobSummary'
    FilePart:
      type: object
      required:
        - filename
        - mediaType
        - url
      properties:
        filename:
          type: string
          description: Original file name shown to the agent.
        mediaType:
          type: string
          description: MIME type (for example text/plain, image/png).
        url:
          type: string
          description: Publicly accessible URL for the file content.
    TaskSummary:
      type: object
      required:
        - id
        - slug
        - title
        - url
        - repositoryUrl
        - baseBranch
      properties:
        id:
          type: string
        slug:
          type: string
        title:
          type: string
        url:
          type: string
        repositoryUrl:
          type: string
        baseBranch:
          type: string
    JobSummary:
      type: object
      required:
        - id
        - status
      properties:
        id:
          type: string
        status:
          $ref: '#/components/schemas/JobStatus'
    ApiErrorResponse:
      type: object
      required:
        - error
      properties:
        error:
          type: object
          required:
            - code
            - message
          properties:
            code:
              type: string
            message:
              type: string
            details: {}
    JobStatus:
      type: string
      enum:
        - PENDING
        - IN_PROGRESS
        - COMPLETED
        - FAILED
        - CANCELLED
  responses:
    ValidationError:
      description: Invalid request
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiErrorResponse'
          examples:
            invalidBody:
              value:
                error:
                  code: validation_error
                  message: Invalid request body
                  details:
                    issues:
                      - field: command
                        message: command is required
    UnauthorizedError:
      description: Invalid or missing API key
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiErrorResponse'
          example:
            error:
              code: unauthorized
              message: Invalid or missing API key
    RateLimitedError:
      description: Too many requests
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiErrorResponse'
          example:
            error:
              code: rate_limited
              message: Rate limit exceeded. Max 100 requests per minute.
    InternalError:
      description: Server error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiErrorResponse'
          example:
            error:
              code: internal_error
              message: Server error
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer

````