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

# Run agent asynchronously

> Start an asynchronous agent run and return a runId that can be polled for status updates. Once the run status is `done`, call `/api/agents/:agentId/run-async/:runId/result` to retrieve the same final payload shape returned by the synchronous run endpoint.



## OpenAPI

````yaml https://app.cotool.ai/api/docs/openapi.json post /api/agents/{agentId}/run-async
openapi: 3.1.0
info:
  title: Cotool API
  version: 1.0.0
  description: >-
    # Cotool API Documentation


    The Cotool API allows you to interact with the Cotool platform
    programmatically, enabling you to build powerful integrations and automate
    your workflows.


    ## Getting an API Key


    Follow these steps to generate your API key:


    1. **Log in** to the Cotool web interface

    2. **Navigate** to `/settings/api-keys`

    3. **Click** "Generate Key"

    4. **Copy and store** your API key securely ⚠️ *It won't be shown again*


    ## API Key Authentication


    For programmatic access and integrations, use your API key with the
    Authorization header:


    ```http

    Authorization: Bearer your_api_key_here

    ```


    ```bash

    curl -X GET "https://app.cotool.ai/api/endpoint" \
      -H "Authorization: Bearer your_api_key_here" \
      -H "Content-Type: application/json"
    ```
servers:
  - url: https://app.cotool.ai
    description: Production server
security:
  - ApiKeyAuth: []
paths:
  /api/agents/{agentId}/run-async:
    post:
      tags:
        - Agents
      summary: Run agent asynchronously
      description: >-
        Start an asynchronous agent run and return a runId that can be polled
        for status updates. Once the run status is `done`, call
        `/api/agents/:agentId/run-async/:runId/result` to retrieve the same
        final payload shape returned by the synchronous run endpoint.
      parameters:
        - in: path
          name: agentId
          description: Unique identifier of the agent to execute
          schema:
            type: string
            format: uuid
            description: Unique identifier of the agent to execute
          required: true
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                inputs:
                  type: object
                  additionalProperties: {}
                  description: >-
                    Input values for agent execution based on agent input
                    configuration. This can be any JSON object and will be
                    stringified as input to the agent.
                attachments:
                  type: array
                  items:
                    type: object
                    properties:
                      fileId:
                        type: string
                        description: Unique identifier of the uploaded file
                      fileName:
                        type: string
                        description: Name of the file
                      size:
                        type: number
                        description: Size of the file in bytes
                      fileType:
                        type: string
                        enum:
                          - image
                          - pdf
                          - spreadsheet
                          - document
                          - presentation
                          - file
                        description: Semantic file type for iconography
                      previewText:
                        type: string
                        description: Optional text preview for text-like files
                    required:
                      - fileId
                      - fileName
                      - size
                    additionalProperties: false
                  description: >-
                    Optional array of file attachments to include with the agent
                    execution
              required:
                - inputs
              description: >-
                Input values for agent execution based on agent input
                configuration
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  runId:
                    type: string
                    format: uuid
                    description: >-
                      Unique identifier for this asynchronous agent run that can
                      be polled for status
                required:
                  - runId
                description: Response containing run ID for asynchronous agent execution
        '400':
          description: Bad request — input validation failed or the request was malformed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ValidationError'
        '401':
          description: Unauthorized — missing or invalid API key / session
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '403':
          description: Forbidden — the authenticated user lacks the required permissions
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PermissionError'
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
      x-codeSamples:
        - lang: shell
          label: cURL
          source: |-
            curl -X POST "https://app.cotool.ai/api/agents/:agentId/run-async" \
              -H "Authorization: Bearer YOUR_API_KEY" \
              -H "Content-Type: application/json" \
              -d '{"inputs":null,"attachments":[{"fileId":"string","fileName":"string","size":0,"fileType":"image","previewText":"string"}]}'
components:
  schemas:
    ValidationError:
      type: object
      properties:
        error:
          type: string
          description: Error message describing what went wrong
        issues:
          type: array
          description: >-
            Detailed validation issues, present when request or response schema
            validation fails
          items:
            type: object
            additionalProperties: true
      required:
        - error
    Error:
      type: object
      properties:
        error:
          type: string
          description: Error message describing what went wrong
      required:
        - error
    PermissionError:
      type: object
      properties:
        error:
          type: string
          description: Error message describing what went wrong
        missingPerms:
          type: array
          description: Permissions the authenticated user is missing for this operation
          items:
            type: string
      required:
        - error
  securitySchemes:
    ApiKeyAuth:
      type: http
      scheme: bearer
      bearerFormat: API Key
      description: >-
        API Key authentication for programmatic access. Include your API key in
        the Authorization header as: `Bearer your_api_key_here`

````