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

# Run an AI agent

> Runs the general AI agent and returns the complete response as a `chatMessages` array.

Use the streaming endpoint (`/stream`) when incremental output is preferred. 429 responses carry a gate message as a `chatMessages` array rather than an error object.



## OpenAPI

````yaml post /ai-agent
openapi: 3.1.0
info:
  title: HERO API
  version: current
  description: |-
    The HERO REST API.

    See https://developers.myhero.so for the rendered docs.
servers:
  - url: https://app.myhero.so
security: []
paths:
  /ai-agent:
    post:
      tags:
        - AI
      summary: Run an AI agent
      description: >-
        Runs the general AI agent and returns the complete response as a
        `chatMessages` array.


        Use the streaming endpoint (`/stream`) when incremental output is
        preferred. 429 responses carry a gate message as a `chatMessages` array
        rather than an error object.
      operationId: aiChat
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                chatMessages:
                  type: array
                  items:
                    type: object
                    properties:
                      type:
                        type: string
                        enum:
                          - user
                          - ai
                      text:
                        type: string
                      metadata:
                        type: object
                        additionalProperties: {}
                    required:
                      - type
                      - text
                  minItems: 1
                context:
                  type: object
                  properties:
                    documentId:
                      type: string
                    projectId:
                      type: string
                    workspaceId:
                      type: string
                    organizationId:
                      type: string
                    mentions:
                      type: array
                      items: {}
                options:
                  type: object
                  properties:
                    provider:
                      type: string
                    model:
                      type: string
                attachments:
                  type: array
                  items:
                    type: object
                    properties:
                      filename:
                        type: string
                      mimeType:
                        type: string
                      base64:
                        type: string
                      size:
                        type: integer
                        minimum: 0
                    required:
                      - filename
                      - mimeType
                      - base64
                      - size
                sessionId:
                  type: string
                documentRefs:
                  type: array
                  items:
                    type: object
                    properties:
                      documentId:
                        type: string
                      format:
                        type: string
                        enum:
                          - editor
                          - docx
                          - pdf
                      addedAt:
                        type: number
                    required:
                      - documentId
                      - format
                      - addedAt
              required:
                - chatMessages
      responses:
        '200':
          description: 200 response
          content:
            application/json:
              schema:
                type: object
                properties:
                  chatMessages:
                    type: array
                    items:
                      type: object
                      properties:
                        type:
                          type: string
                          enum:
                            - user
                            - ai
                        text:
                          type: string
                        metadata:
                          type: object
                          additionalProperties: {}
                      required:
                        - type
                        - text
                required:
                  - chatMessages
        '400':
          description: 400 response
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    description: |-
                      Error class name (e.g.

                      ValidationError, NotFound)
                  message:
                    type: string
                    description: Human-readable error message
                  details:
                    type: array
                    items: {}
                required:
                  - error
                  - message
        '401':
          description: 401 response
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    description: |-
                      Error class name (e.g.

                      ValidationError, NotFound)
                  message:
                    type: string
                    description: Human-readable error message
                  details:
                    type: array
                    items: {}
                required:
                  - error
                  - message
        '403':
          description: 403 response
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    description: |-
                      Error class name (e.g.

                      ValidationError, NotFound)
                  message:
                    type: string
                    description: Human-readable error message
                  details:
                    type: array
                    items: {}
                required:
                  - error
                  - message
        '429':
          description: 429 response
          content:
            application/json:
              schema:
                type: object
                properties:
                  chatMessages:
                    type: array
                    items:
                      type: object
                      properties:
                        type:
                          type: string
                          enum:
                            - user
                            - ai
                        text:
                          type: string
                        metadata:
                          type: object
                          additionalProperties: {}
                      required:
                        - type
                        - text
                required:
                  - chatMessages
      security:
        - bearerAuth: []
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: HERO personal access token

````