openapi: 3.0.3
info:
  title: AgentMail API
  description: Programmatic email inboxes for AI agents
  version: 0.0.0
  contact:
    url: https://agentmail.to
servers:
  - url: https://api.agentmail.to
    description: Production
security:
  - bearerAuth: []
tags:
  - name: Inboxes
    description: Create and manage email inboxes.
  - name: Messages
    description: Send, receive, and manage messages within an inbox.
paths:
  /v0/inboxes:
    get:
      tags:
        - Inboxes
      operationId: listInboxes
      summary: List inboxes
      description: Returns a paginated list of inboxes for the authenticated account.
      parameters:
        - name: limit
          in: query
          description: Maximum number of inboxes to return.
          required: false
          schema:
            type: integer
            minimum: 1
            maximum: 100
        - name: page_token
          in: query
          description: Pagination token returned from a previous list call.
          required: false
          schema:
            type: string
      responses:
        '200':
          description: A paginated list of inboxes.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/InboxCollection'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '422':
          $ref: '#/components/responses/UnprocessableEntity'
    post:
      tags:
        - Inboxes
      operationId: createInbox
      summary: Create an inbox
      description: Creates a new email inbox.
      requestBody:
        required: false
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateInboxRequest'
      responses:
        '201':
          description: The newly created inbox.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Inbox'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '422':
          $ref: '#/components/responses/UnprocessableEntity'
  /v0/inboxes/{inbox_id}:
    parameters:
      - name: inbox_id
        in: path
        description: The unique identifier of the inbox.
        required: true
        schema:
          type: string
    get:
      tags:
        - Inboxes
      operationId: getInbox
      summary: Get an inbox
      description: Retrieves a single inbox by ID.
      responses:
        '200':
          description: The requested inbox.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Inbox'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          $ref: '#/components/responses/NotFound'
    patch:
      tags:
        - Inboxes
      operationId: updateInbox
      summary: Update an inbox
      description: Updates the display name of an existing inbox.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UpdateInboxRequest'
      responses:
        '200':
          description: The updated inbox.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Inbox'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          $ref: '#/components/responses/NotFound'
        '422':
          $ref: '#/components/responses/UnprocessableEntity'
    delete:
      tags:
        - Inboxes
      operationId: deleteInbox
      summary: Delete an inbox
      description: Permanently deletes an inbox and all its messages.
      responses:
        '204':
          description: Inbox deleted successfully.
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          $ref: '#/components/responses/NotFound'
  /v0/inboxes/{inbox_id}/messages:
    parameters:
      - name: inbox_id
        in: path
        description: The unique identifier of the inbox.
        required: true
        schema:
          type: string
    get:
      tags:
        - Messages
      operationId: listMessages
      summary: List messages
      description: Returns a paginated list of messages in the inbox.
      parameters:
        - name: limit
          in: query
          description: Maximum number of messages to return.
          required: false
          schema:
            type: integer
            minimum: 1
            maximum: 100
        - name: page_token
          in: query
          description: Pagination token returned from a previous list call.
          required: false
          schema:
            type: string
        - name: labels
          in: query
          description: Filter messages by labels.
          required: false
          schema:
            type: array
            items:
              type: string
        - name: before
          in: query
          description: Return messages before this ISO 8601 timestamp.
          required: false
          schema:
            type: string
            format: date-time
        - name: after
          in: query
          description: Return messages after this ISO 8601 timestamp.
          required: false
          schema:
            type: string
            format: date-time
        - name: ascending
          in: query
          description: Sort in ascending order (oldest first). Defaults to descending.
          required: false
          schema:
            type: boolean
        - name: include_spam
          in: query
          description: Include messages marked as spam.
          required: false
          schema:
            type: boolean
        - name: include_blocked
          in: query
          description: Include messages that were blocked.
          required: false
          schema:
            type: boolean
        - name: include_trash
          in: query
          description: Include messages in the trash.
          required: false
          schema:
            type: boolean
      responses:
        '200':
          description: A paginated list of messages.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MessageCollection'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          $ref: '#/components/responses/NotFound'
        '422':
          $ref: '#/components/responses/UnprocessableEntity'
    post:
      tags:
        - Messages
      operationId: sendMessage
      summary: Send a message
      description: Sends an email from the inbox.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SendMessageRequest'
      responses:
        '201':
          description: The sent message reference.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SendMessageResponse'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          $ref: '#/components/responses/NotFound'
        '422':
          $ref: '#/components/responses/UnprocessableEntity'
  /v0/inboxes/{inbox_id}/messages/{message_id}:
    parameters:
      - name: inbox_id
        in: path
        description: The unique identifier of the inbox.
        required: true
        schema:
          type: string
      - name: message_id
        in: path
        description: The unique identifier of the message.
        required: true
        schema:
          type: string
    get:
      tags:
        - Messages
      operationId: getMessage
      summary: Get a message
      description: Retrieves a single message by ID.
      responses:
        '200':
          description: The requested message.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Message'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          $ref: '#/components/responses/NotFound'
    patch:
      tags:
        - Messages
      operationId: updateMessage
      summary: Update a message
      description: Adds or removes labels on a message.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UpdateMessageRequest'
      responses:
        '200':
          description: The updated message.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Message'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          $ref: '#/components/responses/NotFound'
        '422':
          $ref: '#/components/responses/UnprocessableEntity'
  /v0/inboxes/{inbox_id}/messages/{message_id}/reply:
    parameters:
      - name: inbox_id
        in: path
        description: The unique identifier of the inbox.
        required: true
        schema:
          type: string
      - name: message_id
        in: path
        description: The unique identifier of the message to reply to.
        required: true
        schema:
          type: string
    post:
      tags:
        - Messages
      operationId: replyToMessage
      summary: Reply to a message
      description: Sends a reply to an existing message.
      requestBody:
        required: false
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ReplyMessageRequest'
      responses:
        '201':
          description: The sent reply reference.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SendMessageResponse'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          $ref: '#/components/responses/NotFound'
        '422':
          $ref: '#/components/responses/UnprocessableEntity'
  /v0/inboxes/{inbox_id}/messages/{message_id}/reply-all:
    parameters:
      - name: inbox_id
        in: path
        description: The unique identifier of the inbox.
        required: true
        schema:
          type: string
      - name: message_id
        in: path
        description: The unique identifier of the message to reply-all to.
        required: true
        schema:
          type: string
    post:
      tags:
        - Messages
      operationId: replyAllToMessage
      summary: Reply all to a message
      description: Sends a reply to all recipients of an existing message.
      requestBody:
        required: false
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ReplyMessageRequest'
      responses:
        '201':
          description: The sent reply-all reference.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SendMessageResponse'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          $ref: '#/components/responses/NotFound'
        '422':
          $ref: '#/components/responses/UnprocessableEntity'
  /v0/inboxes/{inbox_id}/messages/{message_id}/forward:
    parameters:
      - name: inbox_id
        in: path
        description: The unique identifier of the inbox.
        required: true
        schema:
          type: string
      - name: message_id
        in: path
        description: The unique identifier of the message to forward.
        required: true
        schema:
          type: string
    post:
      tags:
        - Messages
      operationId: forwardMessage
      summary: Forward a message
      description: Forwards an existing message to new recipients.
      requestBody:
        required: false
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ForwardMessageRequest'
      responses:
        '201':
          description: The forwarded message reference.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SendMessageResponse'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          $ref: '#/components/responses/NotFound'
        '422':
          $ref: '#/components/responses/UnprocessableEntity'
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: API key issued by AgentMail.
  schemas:
    Inbox:
      type: object
      required:
        - pod_id
        - inbox_id
        - updated_at
        - created_at
      properties:
        pod_id:
          type: string
          description: The pod that owns this inbox.
          example: pod_abc123
        inbox_id:
          type: string
          description: The unique identifier of the inbox.
          example: inbox_xyz789
        display_name:
          type: string
          nullable: true
          description: Human-readable label for the inbox.
          example: Support Team
        client_id:
          type: string
          nullable: true
          description: Optional client-supplied identifier for correlation.
          example: client_007
        created_at:
          type: string
          format: date-time
          description: ISO 8601 timestamp when the inbox was created.
          example: '2024-01-15T10:30:00Z'
        updated_at:
          type: string
          format: date-time
          description: ISO 8601 timestamp when the inbox was last updated.
          example: '2024-01-15T12:00:00Z'
    InboxCollection:
      type: object
      required:
        - inboxes
        - count
      properties:
        inboxes:
          type: array
          items:
            $ref: '#/components/schemas/Inbox'
        count:
          type: integer
          description: Total number of inboxes matching the query.
          example: 42
        limit:
          type: integer
          nullable: true
          description: The limit applied to this page.
          example: 20
        next_page_token:
          type: string
          nullable: true
          description: Token to retrieve the next page, or null if this is the last page.
          example: tok_nextpage
    CreateInboxRequest:
      type: object
      properties:
        username:
          type: string
          description: >-
            Local part of the email address (before the @). Auto-generated if
            omitted.
          example: support
        domain:
          type: string
          description: >-
            Domain for the email address. Defaults to the account default
            domain.
          example: agentmail.to
        display_name:
          type: string
          description: Human-readable label for the inbox.
          example: Support Team
        client_id:
          type: string
          description: Optional client-supplied identifier for correlation.
          example: client_007
    UpdateInboxRequest:
      type: object
      required:
        - display_name
      properties:
        display_name:
          type: string
          description: New display name for the inbox.
          example: New Name <support@agentmail.to>
    Attachment:
      type: object
      required:
        - attachment_id
        - size
      properties:
        attachment_id:
          type: string
          description: The unique identifier of the attachment.
          example: att_abc123
        size:
          type: integer
          description: Size of the attachment in bytes.
          example: 20480
        filename:
          type: string
          nullable: true
          description: Original filename of the attachment.
          example: report.pdf
        content_type:
          type: string
          nullable: true
          description: MIME type of the attachment.
          example: application/pdf
        content_disposition:
          type: string
          nullable: true
          description: Content-Disposition header value.
          example: attachment; filename="report.pdf"
        content_id:
          type: string
          nullable: true
          description: Content-ID for inline attachments.
          example: <image001@example.com>
    Message:
      type: object
      required:
        - inbox_id
        - thread_id
        - message_id
        - labels
        - timestamp
        - from
        - to
        - size
        - updated_at
        - created_at
      properties:
        inbox_id:
          type: string
          description: The inbox this message belongs to.
          example: inbox_xyz789
        thread_id:
          type: string
          description: The thread this message belongs to.
          example: thread_abc123
        message_id:
          type: string
          description: The unique identifier of the message.
          example: msg_def456
        labels:
          type: array
          items:
            type: string
          description: Labels applied to the message.
          example:
            - inbox
            - unread
        timestamp:
          type: string
          format: date-time
          description: ISO 8601 timestamp when the message was sent.
          example: '2024-01-15T10:30:00Z'
        from:
          type: string
          description: Sender email address.
          example: sender@example.com
        to:
          type: array
          items:
            type: string
          description: Recipient email addresses.
          example:
            - recipient@example.com
        size:
          type: integer
          description: Size of the message in bytes.
          example: 4096
        updated_at:
          type: string
          format: date-time
          description: ISO 8601 timestamp when the message was last updated.
          example: '2024-01-15T12:00:00Z'
        created_at:
          type: string
          format: date-time
          description: ISO 8601 timestamp when the message was created.
          example: '2024-01-15T10:30:00Z'
        cc:
          type: array
          items:
            type: string
          nullable: true
          description: CC recipient email addresses.
          example:
            - cc@example.com
        bcc:
          type: array
          items:
            type: string
          nullable: true
          description: BCC recipient email addresses.
        reply_to:
          type: array
          items:
            type: string
          nullable: true
          description: Reply-To email addresses.
        subject:
          type: string
          nullable: true
          description: Subject of the message.
          example: Hello from AgentMail
        preview:
          type: string
          nullable: true
          description: Short preview snippet of the message body.
          example: Just checking in...
        text:
          type: string
          nullable: true
          description: Plain-text body of the message.
        html:
          type: string
          nullable: true
          description: HTML body of the message.
        extracted_text:
          type: string
          nullable: true
          description: Extracted plain-text content (stripped of quoted replies).
        extracted_html:
          type: string
          nullable: true
          description: Extracted HTML content (stripped of quoted replies).
        in_reply_to:
          type: string
          nullable: true
          description: Message-ID of the message this is a reply to.
        references:
          type: array
          items:
            type: string
          nullable: true
          description: List of Message-IDs in the thread ancestry.
        attachments:
          type: array
          items:
            $ref: '#/components/schemas/Attachment'
          nullable: true
          description: Attachments included in the message.
        headers:
          type: object
          nullable: true
          additionalProperties:
            type: string
          description: Additional email headers as key-value pairs.
    MessageCollection:
      type: object
      required:
        - messages
        - count
      properties:
        messages:
          type: array
          items:
            $ref: '#/components/schemas/Message'
        count:
          type: integer
          description: Total number of messages matching the query.
          example: 42
        limit:
          type: integer
          nullable: true
          description: The limit applied to this page.
          example: 20
        next_page_token:
          type: string
          nullable: true
          description: Token to retrieve the next page, or null if this is the last page.
          example: tok_nextpage
    SendMessageRequest:
      type: object
      properties:
        to:
          oneOf:
            - type: string
            - type: array
              items:
                type: string
          description: Recipient email address(es).
          example: recipient@example.com
        cc:
          oneOf:
            - type: string
            - type: array
              items:
                type: string
          description: CC recipient email address(es).
          nullable: true
        bcc:
          oneOf:
            - type: string
            - type: array
              items:
                type: string
          description: BCC recipient email address(es).
          nullable: true
        subject:
          type: string
          description: Subject of the message.
          example: Hello from AgentMail
        text:
          type: string
          description: Plain-text body.
        html:
          type: string
          description: HTML body.
        reply_to:
          oneOf:
            - type: string
            - type: array
              items:
                type: string
          description: Reply-To email address(es).
          nullable: true
        labels:
          type: array
          items:
            type: string
          description: Labels to apply to the sent message.
          nullable: true
        headers:
          type: object
          additionalProperties:
            type: string
          description: Additional email headers.
          nullable: true
    SendMessageResponse:
      type: object
      required:
        - message_id
        - thread_id
      properties:
        message_id:
          type: string
          description: The unique identifier of the sent message.
          example: msg_def456
        thread_id:
          type: string
          description: The thread the message belongs to.
          example: thread_abc123
    UpdateMessageRequest:
      type: object
      properties:
        add_labels:
          type: array
          items:
            type: string
          description: Labels to add to the message.
          nullable: true
          example:
            - read
        remove_labels:
          type: array
          items:
            type: string
          description: Labels to remove from the message.
          nullable: true
          example:
            - unread
    ReplyMessageRequest:
      type: object
      properties:
        to:
          oneOf:
            - type: string
            - type: array
              items:
                type: string
          description: Override recipient email address(es).
          nullable: true
        cc:
          oneOf:
            - type: string
            - type: array
              items:
                type: string
          description: CC recipient email address(es).
          nullable: true
        bcc:
          oneOf:
            - type: string
            - type: array
              items:
                type: string
          description: BCC recipient email address(es).
          nullable: true
        text:
          type: string
          description: Plain-text body of the reply.
        html:
          type: string
          description: HTML body of the reply.
        reply_to:
          oneOf:
            - type: string
            - type: array
              items:
                type: string
          description: Reply-To email address(es).
          nullable: true
        labels:
          type: array
          items:
            type: string
          description: Labels to apply to the reply.
          nullable: true
        headers:
          type: object
          additionalProperties:
            type: string
          description: Additional email headers.
          nullable: true
    ForwardMessageRequest:
      type: object
      properties:
        to:
          oneOf:
            - type: string
            - type: array
              items:
                type: string
          description: Recipient email address(es) to forward to.
          nullable: true
        cc:
          oneOf:
            - type: string
            - type: array
              items:
                type: string
          description: CC recipient email address(es).
          nullable: true
        bcc:
          oneOf:
            - type: string
            - type: array
              items:
                type: string
          description: BCC recipient email address(es).
          nullable: true
        subject:
          type: string
          description: Override subject for the forwarded message.
          nullable: true
        text:
          type: string
          description: Additional plain-text body prepended to the forwarded content.
        html:
          type: string
          description: Additional HTML body prepended to the forwarded content.
        reply_to:
          oneOf:
            - type: string
            - type: array
              items:
                type: string
          description: Reply-To email address(es).
          nullable: true
        labels:
          type: array
          items:
            type: string
          description: Labels to apply to the forwarded message.
          nullable: true
        headers:
          type: object
          additionalProperties:
            type: string
          description: Additional email headers.
          nullable: true
    ApiError:
      type: object
      required:
        - error
        - message
      properties:
        error:
          type: string
          description: Machine-readable error code.
          example: not_found
        message:
          type: string
          description: Human-readable error description.
          example: Inbox not found.
  responses:
    Unauthorized:
      description: Missing or invalid API key.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiError'
    NotFound:
      description: The requested resource does not exist.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiError'
    UnprocessableEntity:
      description: Validation error — the request body is invalid.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiError'
