Mailbuttons Threads API

The threads API from Mailbuttons — 8 operation(s) for threads.

GitHub OpenAPI

Operations 8

GET /v1/mailboxes/{mailbox_id}/messages/new List recent messages in a mailbox, optionally since a cursor #
GET /v1/mailboxes/{mailbox_id}/messages/{email_id} Get one full email, including body text and threading headers #
GET /v1/mailboxes/{mailbox_id}/messages/{email_id}/attachments/{blob_id} Download one attachment's bytes #
POST /v1/mailboxes/{mailbox_id}/messages/{email_id}/bounce Send a notification-style bounce to the original sender #
POST /v1/mailboxes/{mailbox_id}/messages/{email_id}/reply Reply to one email #
GET /v1/mailboxes/{mailbox_id}/threads List a mailbox's threads, newest first #
GET /v1/mailboxes/{mailbox_id}/threads/{thread_id} Get one thread with its messages #
GET /v1/mailboxes/{mailbox_id}/threads/{thread_id}/messages Get just the messages of one thread #

Work with this as data

Every API here is available over the APIs.io API and to AI agents over MCP.

MCP server

One button, every client — Claude, Cursor, VS Code and the rest.

https://apis.io/mcp

Tools for apis

7 MCP tools reach this
  • find_apisBrowse and filter every API in the catalog.
  • get_api_artifactsOne API's artifacts, grouped by type.
  • get_openapiThe primary OpenAPI for this API.
  • find_similar_apisAPIs that look like this one.
  • apis_io_searchSTART HERE — APIs, providers and tags for one query, each with its total.
  • resolveTurn a domain, URL or GitHub org into the provider it belongs to.
  • find_cohortsEvery scored population of providers in the catalog.
All 92 tools →

Call it yourself

curl for this page
This API
curl "https://apis.io/api/v1/apis/mailbuttons-com:mailbuttons-com-threads-api"
All apis
curl "https://apis.io/api/v1/apis?limit=25"

Calls without X-API-Key need no key. Calls with it need a paid plan — get a key.

Get an API key

Free tier, no form to fill in. Signing in shares your email address with us — we store it to create your key and to recognise you if you sign in with another provider. By signing up you are subscribing to the APIs.io and API Evangelist newsletters — you can unsubscribe from any issue. See our Privacy Policy and Terms.

A second provider on the same verified email joins the account you already have.

OpenAPI Specification

mailbuttons-com-threads-api-openapi.yml Raw ↑
openapi: 3.2.0
info:
  description: 'REST API for provisioning and operating governed email accounts for AI

    agents, on mbag.ai and mailbuttons.com. Authenticate with a Bearer API

    key: `mbk_`-prefixed when obtained via the OTP flow below (see `/auth/otp/cli-exchange`);

    dashboard-issued keys carry no prefix.'
  title: Mailbuttons Agent Mail Threads API
  version: 1.0.0
servers:
- url: https://mbag.ai/api
- url: https://mailbuttons.com/api
security:
- apiKey: []
tags:
- name: Threads
paths:
  /v1/mailboxes/{mailbox_id}/messages/new:
    get:
      operationId: listNewMessages
      parameters:
      - in: path
        name: mailbox_id
        required: true
        schema:
          format: int32
          type: integer
      - description: JMAP `receivedAt`-style timestamp; when given, only messages received after it are returned.
        in: query
        name: since
        required: false
        schema:
          type: string
      - description: Capped server-side at 250.
        in: query
        name: limit
        schema:
          default: 25
          type: integer
      responses:
        '200':
          content:
            application/json:
              schema:
                items:
                  $ref: '#/components/schemas/EmailMessage'
                type: array
          description: Messages, newest first.
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
          description: Mailbox not found (or not owned by the caller).
        '409':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
          description: Mailbox has no JMAP credentials provisioned yet.
        '500':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
          description: Database error reading mailbox JMAP credentials.
        '502':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
          description: 'Failed to reach or parse the upstream JMAP `/session` response, or

            the session had no primary mail account.

            '
        default:
          content:
            application/json:
              schema:
                type: object
          description: 'Any other status is Stalwart''s own JMAP method-call response

            passed through verbatim (its status code and JSON body, or

            `{"error":"Invalid JSON from upstream"}` if the body didn''t parse

            as JSON).

            '
      security:
      - apiKey: []
      summary: List recent messages in a mailbox, optionally since a cursor
      tags:
      - Threads
  /v1/mailboxes/{mailbox_id}/messages/{email_id}:
    get:
      operationId: getEmail
      parameters:
      - in: path
        name: mailbox_id
        required: true
        schema:
          format: int32
          type: integer
      - in: path
        name: email_id
        required: true
        schema:
          type: string
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/FullEmailMessage'
          description: The full email.
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
          description: 'Mailbox not found (or not owned by the caller), or the mailbox

            was found but the email id doesn''t exist in it — both are JSON

            `{"error": "Mailbox not found"}` / `{"error": "Email not found"}`.

            '
        '409':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
          description: Mailbox has no JMAP credentials provisioned yet.
        '500':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
          description: Database error reading mailbox JMAP credentials.
        '502':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
          description: 'Failed to reach or parse the upstream JMAP `/session` response,

            the session had no primary mail account, or Stalwart returned a

            malformed email object.

            '
        default:
          content:
            application/json:
              schema:
                type: object
          description: 'Any other status is Stalwart''s own JMAP method-call response

            passed through verbatim (its status code and JSON body, or

            `{"error":"Invalid JSON from upstream"}` if the body didn''t parse

            as JSON).

            '
      security:
      - apiKey: []
      summary: Get one full email, including body text and threading headers
      tags:
      - Threads
  /v1/mailboxes/{mailbox_id}/messages/{email_id}/attachments/{blob_id}:
    get:
      description: 'The blob is verified to belong to the named email (which the mailbox

        owns) before download, so a caller can''t pull arbitrary blobs by

        guessing ids.'
      operationId: downloadAttachment
      parameters:
      - in: path
        name: mailbox_id
        required: true
        schema:
          format: int32
          type: integer
      - in: path
        name: email_id
        required: true
        schema:
          type: string
      - in: path
        name: blob_id
        required: true
        schema:
          type: string
      responses:
        '200':
          content:
            application/octet-stream:
              schema:
                format: binary
                type: string
          description: The attachment's raw bytes. `Content-Type` is the attachment's own MIME type; `Content-Disposition` carries its sanitised filename.
          headers:
            Content-Disposition:
              description: '`attachment; filename="<sanitised name>"`'
              schema:
                type: string
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
          description: 'Mailbox not found (or not owned by the caller), the email id

            doesn''t exist in it, or no attachment on that email has this

            blob id — all three are JSON `{"error": "Mailbox not found"}` /

            `{"error": "Email not found"}` / `{"error": "Attachment not

            found on this email"}`.

            '
        '409':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
          description: Mailbox has no JMAP credentials provisioned yet.
        '413':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
          description: Attachment exceeds the 25 MB download limit.
        '500':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
          description: Database error reading mailbox JMAP credentials, or failed to build the streamed response.
        '502':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
          description: 'Failed to reach or parse the upstream JMAP `/session` response,

            the session had no primary mail account, or the blob download

            from Stalwart itself failed or returned a non-2xx status.

            '
      security:
      - apiKey: []
      summary: Download one attachment's bytes
      tags:
      - Threads
  /v1/mailboxes/{mailbox_id}/messages/{email_id}/bounce:
    post:
      description: '`reason` is used verbatim as the bounce''s explanation paragraph. A

        human-triggered action (API-key auth), so Supervised mode does not

        hold it — only Shadow mode (nothing ever leaves) refuses it.'
      operationId: bounceEmail
      parameters:
      - in: path
        name: mailbox_id
        required: true
        schema:
          format: int32
          type: integer
      - in: path
        name: email_id
        required: true
        schema:
          type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/BounceRequest'
        required: true
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BounceResponse'
          description: Bounce sent.
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
          description: 'Mailbox not found (or not owned by the caller). Note: any

            database error on this lookup ALSO surfaces as this same 404

            (same `fetch_one().map_err(|_| ...)` pattern as the reply

            endpoint).

            '
        '409':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
          description: Bounces are suppressed while this mailbox is in shadow assessment mode.
        '422':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
          description: The original message has no sender to bounce to.
        '429':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
          description: 'Bounce rate limit exceeded (fixed at 60/hour per mailbox — not

            tier-dependent). Body is `{"error": "Bounce rate limit exceeded

            (60/hour)"}`, with no separate machine-readable rule field.

            '
        '502':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
          description: 'Failed to read the mailbox''s operating mode, failed to fetch the

            original message via JMAP, or failed to send the bounce. Message

            text is a wrapped upstream error string.

            '
      security:
      - apiKey: []
      summary: Send a notification-style bounce to the original sender
      tags:
      - Threads
  /v1/mailboxes/{mailbox_id}/messages/{email_id}/reply:
    post:
      description: 'Fetches the original message, then sends the reply through the

        mailbox''s operating-mode gate (`policy.mode`): Live sends

        immediately; Supervised/Shadow park it as a draft instead (`held:

        true`) — `success: true` is returned either way, so callers MUST

        check `held` to know whether the reply actually left. A reply that

        actually sends first consumes tier send-cap quota; a held reply

        consumes nothing.'
      operationId: replyToEmail
      parameters:
      - in: path
        name: mailbox_id
        required: true
        schema:
          format: int32
          type: integer
      - in: path
        name: email_id
        required: true
        schema:
          type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ReplyRequest'
        required: true
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ReplyResponse'
          description: Reply sent or parked — see `held`.
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
          description: 'Mailbox not found (or not owned by the caller). Note: any

            database error on this lookup ALSO surfaces as this same 404

            (the handler uses `fetch_one().map_err(|_| ...)` without

            distinguishing "no row" from a query failure).

            '
        '429':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
          description: 'Tier send cap reached (daily or monthly). Unlike

            `POST .../send`, the error body here is JUST

            `{"error": "<human-readable message>"}` — there is no separate

            machine-readable `rule` field; the message text names the plan

            and links to the pricing page.

            '
        '502':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
          description: Failed to fetch the original message via JMAP, or failed to send/park the reply. Message text is a wrapped upstream error string.
      security:
      - apiKey: []
      summary: Reply to one email
      tags:
      - Threads
  /v1/mailboxes/{mailbox_id}/threads:
    get:
      description: 'Backed by a JMAP `Email/query` (`collapseThreads: true`) + `Email/get`

        against the mailbox''s own Stalwart principal.'
      operationId: listThreads
      parameters:
      - in: path
        name: mailbox_id
        required: true
        schema:
          format: int32
          type: integer
      - description: Capped server-side at 250.
        in: query
        name: limit
        schema:
          default: 25
          type: integer
      responses:
        '200':
          content:
            application/json:
              schema:
                items:
                  $ref: '#/components/schemas/ThreadSummary'
                type: array
          description: Threads, newest first.
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
          description: Mailbox not found (or not owned by the caller).
        '409':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
          description: Mailbox has no JMAP credentials provisioned yet.
        '500':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
          description: Database error reading mailbox JMAP credentials.
        '502':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
          description: 'Failed to reach or parse the upstream JMAP `/session` response, or

            the session had no primary mail account.

            '
        default:
          content:
            application/json:
              schema:
                type: object
          description: 'Any other status is Stalwart''s own JMAP method-call response

            passed through verbatim (its status code and JSON body, or

            `{"error":"Invalid JSON from upstream"}` if the body didn''t parse

            as JSON).

            '
      security:
      - apiKey: []
      summary: List a mailbox's threads, newest first
      tags:
      - Threads
  /v1/mailboxes/{mailbox_id}/threads/{thread_id}:
    get:
      operationId: getThread
      parameters:
      - in: path
        name: mailbox_id
        required: true
        schema:
          format: int32
          type: integer
      - in: path
        name: thread_id
        required: true
        schema:
          type: string
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ThreadDetails'
          description: The thread and its messages, oldest first.
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
          description: Mailbox not found (or not owned by the caller).
        '409':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
          description: Mailbox has no JMAP credentials provisioned yet.
        '500':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
          description: Database error reading mailbox JMAP credentials.
        '502':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
          description: 'Failed to reach or parse the upstream JMAP `/session` response, or

            the session had no primary mail account.

            '
        default:
          content:
            application/json:
              schema:
                type: object
          description: 'Any other status is Stalwart''s own JMAP method-call response

            passed through verbatim (its status code and JSON body, or

            `{"error":"Invalid JSON from upstream"}` if the body didn''t parse

            as JSON).

            '
      security:
      - apiKey: []
      summary: Get one thread with its messages
      tags:
      - Threads
  /v1/mailboxes/{mailbox_id}/threads/{thread_id}/messages:
    get:
      description: Same lookup as `GET .../threads/{thread_id}`, returning only its `messages` array.
      operationId: getThreadMessages
      parameters:
      - in: path
        name: mailbox_id
        required: true
        schema:
          format: int32
          type: integer
      - in: path
        name: thread_id
        required: true
        schema:
          type: string
      responses:
        '200':
          content:
            application/json:
              schema:
                items:
                  $ref: '#/components/schemas/EmailMessage'
                type: array
          description: Messages in the thread, oldest first.
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
          description: Mailbox not found (or not owned by the caller).
        '409':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
          description: Mailbox has no JMAP credentials provisioned yet.
        '500':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
          description: Database error reading mailbox JMAP credentials.
        '502':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
          description: 'Failed to reach or parse the upstream JMAP `/session` response, or

            the session had no primary mail account.

            '
        default:
          content:
            application/json:
              schema:
                type: object
          description: 'Any other status is Stalwart''s own JMAP method-call response

            passed through verbatim (its status code and JSON body, or

            `{"error":"Invalid JSON from upstream"}` if the body didn''t parse

            as JSON).

            '
      security:
      - apiKey: []
      summary: Get just the messages of one thread
      tags:
      - Threads
components:
  schemas:
    ThreadSummary:
      properties:
        from:
          type:
          - string
          - 'null'
        latest_email_id:
          type: string
        received_at:
          type:
          - string
          - 'null'
        subject:
          type:
          - string
          - 'null'
        thread_id:
          type: string
      required:
      - thread_id
      - latest_email_id
      - subject
      - from
      - received_at
      type: object
    ReplyResponse:
      description: '`held`/`draft_id`/`mode` are omitted entirely (not even `null`) for a

        plain Live send — they only appear when the reply was parked instead

        of sent. `success: true` on its own does NOT mean the reply left;

        callers must check `held`.

        '
      properties:
        draft_id:
          format: int64
          type: integer
        held:
          description: True when the reply was parked (Supervised/Shadow mode) rather than sent.
          type: boolean
        mode:
          description: The mailbox's operating mode (`policy.mode`) that caused the hold, present when `held` is true.
          enum:
          - supervised
          - shadow
          type: string
        success:
          type: boolean
      required:
      - success
      type: object
    EmailMessage:
      properties:
        from:
          type:
          - string
          - 'null'
        id:
          type: string
        preview:
          type:
          - string
          - 'null'
        received_at:
          type:
          - string
          - 'null'
        subject:
          type:
          - string
          - 'null'
        thread_id:
          type:
          - string
          - 'null'
        to:
          items:
            type: string
          type:
          - array
          - 'null'
      required:
      - id
      - thread_id
      - subject
      - from
      - to
      - received_at
      - preview
      type: object
    BounceResponse:
      properties:
        success:
          type: boolean
      required:
      - success
      type: object
    AttachmentMeta:
      description: 'Metadata for one attachment. Fetch its bytes separately via

        `GET .../messages/{email_id}/attachments/{blob_id}`.

        '
      properties:
        blob_id:
          type: string
        content_type:
          type: string
        filename:
          type: string
        size:
          format: int64
          type: integer
      required:
      - blob_id
      - filename
      - content_type
      - size
      type: object
    BounceRequest:
      properties:
        reason:
          description: Used verbatim as the bounce explanation paragraph.
          type: string
      required:
      - reason
      type: object
    ThreadDetails:
      properties:
        messages:
          items:
            $ref: '#/components/schemas/EmailMessage'
          type: array
        thread_id:
          type: string
      required:
      - thread_id
      - messages
      type: object
    ApiError:
      description: 'The shape written by `threads.rs::json_error` and other handlers that

        return a single machine string in `error`. The string is sometimes a

        short stable code (`"Mailbox not found"`) and sometimes an

        interpolated message (a wrapped `sqlx::Error`''s `Display`) — see each

        operation''s response description for which.

        '
      properties:
        error:
          type: string
      required:
      - error
      type: object
    ReplyRequest:
      properties:
        text_body:
          type: string
      required:
      - text_body
      type: object
    FullEmailMessage:
      properties:
        attachments:
          items:
            $ref: '#/components/schemas/AttachmentMeta'
          type: array
        from:
          type:
          - string
          - 'null'
        id:
          type: string
        in_reply_to:
          items:
            type: string
          type:
          - array
          - 'null'
        message_id:
          items:
            type: string
          type:
          - array
          - 'null'
        received_at:
          type:
          - string
          - 'null'
        references:
          items:
            type: string
          type:
          - array
          - 'null'
        subject:
          type:
          - string
          - 'null'
        text_body:
          type:
          - string
          - 'null'
        thread_id:
          type:
          - string
          - 'null'
        to:
          items:
            type: string
          type:
          - array
          - 'null'
      required:
      - id
      - thread_id
      - subject
      - from
      - to
      - received_at
      - text_body
      - message_id
      - in_reply_to
      - references
      - attachments
      type: object
  responses:
    Unauthorized:
      content:
        application/json:
          schema:
            properties:
              error:
                enum:
                - Missing Authorization header
                - Bearer authorization required
                - Invalid API key
                - API key disabled
                type: string
            required:
            - error
            type: object
      description: 'Missing or invalid credential, raised by the `ApiKeyAuth` extractor

        (`backend/src/api_keys.rs`) before the handler runs: no

        `Authorization` header, a non-`Bearer` scheme, a key that doesn''t

        hash-match any row, or a key whose status isn''t `active`. A header

        that isn''t valid UTF-8, has no scheme token, or has `Bearer` with no

        key value returns 400 with this same JSON shape instead of 401.

        '
  securitySchemes:
    apiKey:
      bearerFormat: API key
      scheme: bearer
      type: http