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

# Send Paige a message and get its reply

> Talk to Paige the way a person does in the dashboard chat: one plain-language `message` — a question about the bot, a change to build, something to do with conversations, templates or broadcasts, or the answer to a question Paige asked — and Paige's `reply`. **Projects on the new AI engine only**; any other project answers `409 engine_unavailable` (use the other endpoints, e.g. `POST /v1/code`). The MCP tool `ask_paige` wraps this endpoint.

**What Paige may do is decided by your key's OTHER scopes, action by action.** `agent:chat` opens the conversation and nothing more: reading code needs `code:read`, changing it needs `code:write` (flows also `flows:write`), reading or changing conversations needs `conversations:read` / `conversations:write`, contacts `contacts:read` / `contacts:write`, templates `templates:read`, broadcasts `broadcasts:read` / `broadcasts:manage`, project tables `tables:read` / `tables:write` (a table change also needs `code:write`; a raw query also needs `contacts:read` + `conversations:read`, because it can read Paige's own tables; the bot's logs also need `conversations:read`). Without the scope, Paige is told the action is not allowed for this key and says so in its reply. Paige never drafts into the dashboard composer and never drives the dashboard preview bot.

**Nothing is SENT from a chat, and four kinds of change always wait for a person.** Creating a template, sending a template, tagging an audience and a campaign come back as `actions` (the reply ends with `status: "needs_confirmation"`) — Paige cannot create a template or tag contacts itself through the API, whatever the key holds. Other changes DO apply when the key holds that endpoint's scope: a conversation's state (`conversations:write`), a segment (`broadcasts:manage`), code, tables and flows (`code:write`, `tables:write`, `flows:write`, including publishing a flow). Each action is for you (or your user) to carry out: `template_send` (needs `messages:send` to be proposed; send it with `POST /v1/messages`), `template_create` (needs `templates:manage` to be proposed; create it with `POST /v1/templates`), `tag_audience` (needs `contacts:write`; apply it in the dashboard or per contact with `PATCH /v1/contacts/{id}`), `broadcast_approval` (a campaign held in `pending_approval`, `broadcast_id`; it is approved in the dashboard only).

**Shared with `POST /v1/code`:** the same per-credential conversation (each API key, or MCP connection, has its own; it never sees the dashboard chat or another key's calls, and never appears in the dashboard chat) — so a plan proposed here (`needs_confirmation` with `plan_id`) is decided with `POST /v1/code/plans/{plan_id}/decision` (needs `code:write`), and a question asked here (`needs_input`) is answered by your next message. The same single-flight rule: one API / MCP turn per project at a time, and none while the key owner has a chat turn running in the dashboard — `409 build_in_progress`, for questions too; retry when it has finished. A turn that reaches its step or token limit stops there; send another message to carry on. A turn that writes code commits it like a build.

**Billing:** every message is charged at its real cost, like a dashboard chat turn, questions included. With no credits left the call answers `402` with `error.code: "insufficient_credits"` before any AI model runs; top up in the dashboard, then send the message again. **Rate limit:** its own per-key bucket of 10 messages a minute, on top of the general per-key limit (`429 rate_limited`). Read `status` first:
- `completed` — `reply` is Paige's answer (`files_changed` lists what it wrote; `cancelled: true` when it hit its time limit or you disconnected — what it wrote is kept).
- `needs_confirmation` — a plan (`plan_id`, `plan`, `confirm_path`) and/or `actions` wait for a person.
- `needs_input` — Paige asked `question` (with `options` when it is multiple choice: answer with one `label`, or your own words when `allow_other` is true; with `questions` when it asked several things at once: answer them all); send the answer as your next `message`.

**Required scope:** `agent:chat`



## OpenAPI

````yaml /api-reference/openapi.json post /v1/chat
openapi: 3.1.0
info:
  title: Paige API
  version: 1.1.0
  description: >-
    The Paige public REST API (`/v1`). Build WhatsApp automations against your
    Paige project: send messages, manage templates, read conversations, tag
    contacts, assemble broadcasts, edit bot code + flows, and register signed
    webhooks.


    ## Authentication

    Every `/v1` request authenticates with a project API key: `Authorization:
    Bearer pk_live_…`. Mint and scope keys in **Settings → API keys**. A key
    carries its own project context, so `/v1` paths never include a project id.


    ## Scopes

    Each endpoint requires one or more scopes (see each operation, and the
    `x-required-scopes` extension). Grant a key only the scopes it needs. A key
    missing a required scope gets `403 insufficient_scope`.


    ## Response envelope

    Success: `{ "success": true, "data": … }`. Error: `{ "success": false,
    "error": { "code", "message" }, "request_id" }`. Some errors add
    `error.details` with structured extras (e.g. `quota_exceeded` carries
    `limit` + `resetAt`) — read it defensively, its keys depend on the code. The
    `request_id` is also returned as the `X-Request-Id` header on every
    response.


    ## Rate limits & quota

    Requests are throttled per key (`RateLimit-*` headers; exceed → `429
    rate_limited`). WhatsApp sends also draw down a daily quota (exceed → `429
    quota_exceeded`). Both carry `Retry-After`.


    ## Idempotency

    Send an `Idempotency-Key` header on `POST /v1/messages` to make retries safe
    — a completed key replays the stored response and never re-sends.


    ## Webhook signatures

    Outbound webhook deliveries carry `X-Paige-Signature:
    t=<unix>,v1=<hmac_sha256>`. Verify with the reference `verifyPaigeSignature`
    helper (constant-time HMAC over `"<t>.<rawBody>"`, 300s tolerance).
  contact:
    name: Paige
    url: https://paigeme.dev
servers:
  - url: https://api.paigeme.dev
    description: Production
security:
  - ApiKeyAuth: []
tags:
  - name: Meta
    description: Smoke / diagnostics.
  - name: Messages
    description: Send messages and read delivery status + media.
  - name: Conversations
    description: List conversations, read messages, set state.
  - name: Contacts
    description: Read contact messages; update names, tags, attributes.
  - name: Templates
    description: WhatsApp message template CRUD.
  - name: Broadcasts
    description: Segments + broadcast assembly (always pending_approval).
  - name: Build
    description: Read/edit bot code, deploy, read/generate/update flows.
  - name: Chat
    description: >-
      Send Paige a message in plain language and get its reply (projects on the
      new AI engine).
  - name: Tables
    description: >-
      Read and write the project's own database tables. Paige platform tables
      are denied, and an update or delete must always be filtered.
  - name: Media
    description: >-
      Upload, list, retrieve and delete the project's media assets. The slug an
      upload returns is what the bot sends by.
  - name: Webhooks
    description: Register signed outbound webhooks.
paths:
  /v1/chat:
    post:
      tags:
        - Chat
      summary: Send Paige a message and get its reply
      description: >-
        Talk to Paige the way a person does in the dashboard chat: one
        plain-language `message` — a question about the bot, a change to build,
        something to do with conversations, templates or broadcasts, or the
        answer to a question Paige asked — and Paige's `reply`. **Projects on
        the new AI engine only**; any other project answers `409
        engine_unavailable` (use the other endpoints, e.g. `POST /v1/code`). The
        MCP tool `ask_paige` wraps this endpoint.


        **What Paige may do is decided by your key's OTHER scopes, action by
        action.** `agent:chat` opens the conversation and nothing more: reading
        code needs `code:read`, changing it needs `code:write` (flows also
        `flows:write`), reading or changing conversations needs
        `conversations:read` / `conversations:write`, contacts `contacts:read` /
        `contacts:write`, templates `templates:read`, broadcasts
        `broadcasts:read` / `broadcasts:manage`, project tables `tables:read` /
        `tables:write` (a table change also needs `code:write`; a raw query also
        needs `contacts:read` + `conversations:read`, because it can read
        Paige's own tables; the bot's logs also need `conversations:read`).
        Without the scope, Paige is told the action is not allowed for this key
        and says so in its reply. Paige never drafts into the dashboard composer
        and never drives the dashboard preview bot.


        **Nothing is SENT from a chat, and four kinds of change always wait for
        a person.** Creating a template, sending a template, tagging an audience
        and a campaign come back as `actions` (the reply ends with `status:
        "needs_confirmation"`) — Paige cannot create a template or tag contacts
        itself through the API, whatever the key holds. Other changes DO apply
        when the key holds that endpoint's scope: a conversation's state
        (`conversations:write`), a segment (`broadcasts:manage`), code, tables
        and flows (`code:write`, `tables:write`, `flows:write`, including
        publishing a flow). Each action is for you (or your user) to carry out:
        `template_send` (needs `messages:send` to be proposed; send it with
        `POST /v1/messages`), `template_create` (needs `templates:manage` to be
        proposed; create it with `POST /v1/templates`), `tag_audience` (needs
        `contacts:write`; apply it in the dashboard or per contact with `PATCH
        /v1/contacts/{id}`), `broadcast_approval` (a campaign held in
        `pending_approval`, `broadcast_id`; it is approved in the dashboard
        only).


        **Shared with `POST /v1/code`:** the same per-credential conversation
        (each API key, or MCP connection, has its own; it never sees the
        dashboard chat or another key's calls, and never appears in the
        dashboard chat) — so a plan proposed here (`needs_confirmation` with
        `plan_id`) is decided with `POST /v1/code/plans/{plan_id}/decision`
        (needs `code:write`), and a question asked here (`needs_input`) is
        answered by your next message. The same single-flight rule: one API /
        MCP turn per project at a time, and none while the key owner has a chat
        turn running in the dashboard — `409 build_in_progress`, for questions
        too; retry when it has finished. A turn that reaches its step or token
        limit stops there; send another message to carry on. A turn that writes
        code commits it like a build.


        **Billing:** every message is charged at its real cost, like a dashboard
        chat turn, questions included. With no credits left the call answers
        `402` with `error.code: "insufficient_credits"` before any AI model
        runs; top up in the dashboard, then send the message again. **Rate
        limit:** its own per-key bucket of 10 messages a minute, on top of the
        general per-key limit (`429 rate_limited`). Read `status` first:

        - `completed` — `reply` is Paige's answer (`files_changed` lists what it
        wrote; `cancelled: true` when it hit its time limit or you disconnected
        — what it wrote is kept).

        - `needs_confirmation` — a plan (`plan_id`, `plan`, `confirm_path`)
        and/or `actions` wait for a person.

        - `needs_input` — Paige asked `question` (with `options` when it is
        multiple choice: answer with one `label`, or your own words when
        `allow_other` is true; with `questions` when it asked several things at
        once: answer them all); send the answer as your next `message`.


        **Required scope:** `agent:chat`
      operationId: chat
      parameters:
        - schema:
            type: string
            description: >-
              Target project id, for an MCP OAuth bearer (`mcp_at_…`) attached
              to more than one project — get ids from `GET /v1/projects`.
              Matched case-insensitively.


              Omit it and a READ falls back to the connection's default project;
              a **mutation** (any non-GET) on a connection with 2+ projects is
              rejected with `400 project_required` — a write is never defaulted
              to a guessed project. A connection with exactly one project never
              needs the header.


              Scopes are checked against the SELECTED project only, never a
              union across the connection.


              For a `pk_` API key the header selects nothing — one key is one
              project's context — but it IS validated: omit it and the key's own
              project is used, send it and it must name that project, otherwise
              the call is rejected with `403 project_not_attached` (a blank
              value is `400 invalid_project_header`, as above).
          required: false
          name: X-Paige-Project
          in: header
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                message:
                  type: string
                  minLength: 1
                  maxLength: 10000
                  description: >-
                    What you want from Paige, in plain language: a question
                    about the bot, a change to build, something to do with
                    conversations, templates or broadcasts, or the answer to a
                    question Paige asked you.
              required:
                - message
      responses:
        '200':
          description: Success.
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    enum:
                      - true
                  data:
                    type: object
                    properties:
                      status:
                        type: string
                        enum:
                          - completed
                          - needs_confirmation
                          - needs_input
                        description: >-
                          `needs_confirmation`: a plan and/or `actions` wait for
                          a person. `needs_input`: answer `question` with your
                          next message.
                      reply:
                        type: string
                        description: Paige's reply (its final message of the turn).
                      files_changed:
                        type: array
                        items:
                          type: string
                        description: >-
                          Project files the turn wrote (dev); empty for most
                          replies.
                      cancelled:
                        type: boolean
                        description: >-
                          True when the turn was cut off (time limit, or the
                          caller disconnected). Work already written is kept.
                      engine:
                        type: string
                        enum:
                          - v2
                      turn_id:
                        type:
                          - string
                          - 'null'
                        description: >-
                          The turn id (matches its trace and its credit-ledger
                          row).
                      plan_id:
                        type: string
                        description: >-
                          With a plan: decide it with POST
                          /v1/code/plans/{plan_id}/decision.
                      plan:
                        type:
                          - object
                          - 'null'
                        properties: {}
                        description: 'With a plan: the proposed plan (as on POST /v1/code).'
                      confirm_path:
                        type: string
                      question:
                        type: string
                        description: >-
                          With `needs_input` (or with `needs_confirmation` when
                          Paige also asked something in the same turn): what
                          Paige asked. When it asked several things at once,
                          every question, one per line (`questions` has their
                          choices).
                      options:
                        type: array
                        items:
                          type: object
                          properties:
                            label:
                              type: string
                              description: >-
                                The choice, in a few words. Send it back as the
                                answer.
                            description:
                              type: string
                              description: What choosing it means, in one line.
                          required:
                            - label
                        description: >-
                          With `question` when Paige asked ONE multiple-choice
                          question (GRE-1052): 2 to 4 choices. Answer with one
                          `label` exactly, or — when `allow_other` is true —
                          with your own words.
                      allow_other:
                        type: boolean
                        description: >-
                          With `options`: true when an answer other than the
                          listed labels is welcome.
                      questions:
                        type: array
                        items:
                          type: object
                          properties:
                            question:
                              type: string
                              description: What Paige asked.
                            options:
                              type: array
                              items:
                                type: object
                                properties:
                                  label:
                                    type: string
                                    description: >-
                                      The choice, in a few words. Send it back
                                      as the answer.
                                  description:
                                    type: string
                                    description: What choosing it means, in one line.
                                required:
                                  - label
                              description: >-
                                2 to 4 choices. Answer with one `label`, or with
                                your own words when `allow_other` is true.
                            allow_other:
                              type: boolean
                              description: >-
                                True when an answer other than the listed labels
                                is welcome.
                          required:
                            - question
                            - options
                            - allow_other
                        description: >-
                          With `question` when Paige asked several things at
                          once (GRE-1128): 2 to 4 questions, each with its own
                          choices. Answer them all in one message.
                      actions:
                        type: array
                        items:
                          type: object
                          properties:
                            type:
                              type: string
                              enum:
                                - template_send
                                - template_create
                                - tag_audience
                                - broadcast_approval
                              description: >-
                                What waits for a person. `template_send` → send
                                with POST /v1/messages; `template_create` → POST
                                /v1/templates; `tag_audience` → apply in the
                                dashboard (or per contact, PATCH
                                /v1/contacts/{id}); `broadcast_approval` →
                                approve the held campaign in the dashboard.
                            proposal:
                              type: object
                              properties: {}
                              description: >-
                                template_send / template_create / tag_audience:
                                the proposal, exactly as the dashboard's
                                approval card shows it (recipient, template,
                                variables; the template draft; the audience, its
                                count and the tags).
                            broadcast_id:
                              type: string
                              description: >-
                                broadcast_approval: the campaign held in
                                pending_approval.
                            status:
                              type: string
                              description: 'broadcast_approval: `pending_approval`.'
                            summary:
                              type:
                                - object
                                - 'null'
                              properties: {}
                              description: >-
                                broadcast_approval: audience count, estimated
                                cost, template preview, variable mapping,
                                schedule.
                            launch_blocked_reason:
                              type:
                                - string
                                - 'null'
                              description: >-
                                broadcast_approval: why it cannot launch yet
                                (e.g. its template is still pending), or null.
                          required:
                            - type
                        description: >-
                          With `needs_confirmation`: what Paige proposed and
                          nobody has done yet — template creates and sends,
                          audience tags and campaigns are never applied from a
                          chat. (Other changes, made with the key's scopes, have
                          already applied and are described in `reply`.)
                    required:
                      - status
                      - reply
                      - files_changed
                      - cancelled
                      - engine
                      - turn_id
                required:
                  - success
                  - data
        '400':
          description: >-
            Validation / bad request (e.g. `invalid_request`, `invalid_cursor`,
            `invalid_template` for a Meta 4xx rejection of a template payload,
            which carries Meta's own detail as the message; note
            `outside_24h_window` is 409, not 400). Also `invalid_project_header`
            (any credential: `X-Paige-Project` was sent but blank) and, for
            multi-project MCP bearers, `project_required` (a mutation, or a read
            with no default, and no `X-Paige-Project`).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          description: >-
            Missing or invalid API key (`api_key_required` / `invalid_api_key` /
            `invalid_token` for a revoked or expired OAuth bearer).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '402':
          description: >-
            Out of credits: `error.code` is `insufficient_credits`. Refused
            before any AI model runs, and nothing is charged. A project owner or
            workspace admin tops up in the Paige dashboard (Settings → Usage),
            then the call can be repeated.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '403':
          description: >-
            Key lacks the required scope, project inactive, or a write targets a
            platform-protected file (`insufficient_scope` / `project_inactive` /
            `subscription_inactive` / `protected_file`). Also
            `project_not_attached` (the `X-Paige-Project` project is not one
            this credential may act on — not attached to the MCP connection, or
            not the `pk_` key's own project; identical response whether or not
            it exists) and, for MCP bearers, `no_project_access` (the connection
            has no projects attached).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '409':
          description: >-
            Conflict — 24h window closed (`outside_24h_window`) or idempotency
            (`idempotency_in_progress` / `idempotency_key_mismatch`). On the
            build endpoints: `build_in_progress` (one build per project at a
            time), `plan_already_decided` or `engine_unavailable`.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '429':
          description: >-
            Rate limit (`rate_limited`) or daily send quota (`quota_exceeded`)
            exceeded. Carries `RateLimit-*` + `Retry-After` headers.
          headers:
            RateLimit-Limit:
              description: Requests permitted in the current window.
              schema:
                type: integer
            RateLimit-Remaining:
              description: Requests remaining in the current window.
              schema:
                type: integer
            RateLimit-Reset:
              description: Seconds until the window resets.
              schema:
                type: integer
            Retry-After:
              description: Seconds to wait before retrying.
              schema:
                type: integer
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '500':
          description: Unexpected server error (`server_error`).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '502':
          description: >-
            Upstream failure — a Meta credentials rejection (`meta_auth_error`)
            or a failed/truncated agent run on the build + flow endpoints
            (`build_failed`).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '503':
          description: >-
            Temporarily unavailable — try again (`credit_check_failed`,
            `plan_build_unavailable`, `plans_unavailable`).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
      security:
        - ApiKeyAuth: []
components:
  schemas:
    ErrorResponse:
      type: object
      properties:
        success:
          type: boolean
          enum:
            - false
        error:
          $ref: '#/components/schemas/ApiError'
        request_id:
          type: string
          description: Per-request id, also returned as the X-Request-Id header.
      required:
        - success
        - error
        - request_id
    ApiError:
      type: object
      properties:
        code:
          type: string
          description: Stable, machine-readable error code.
          example: invalid_request
        message:
          type: string
          description: Human-readable message (safe to surface).
          example: Invalid request body
        details:
          type: object
          properties: {}
          description: >-
            Structured extras for codes that carry them — the keys depend on
            `code`. `quota_exceeded` carries `limit` + `resetAt`; most errors
            omit this field entirely.
      required:
        - code
        - message
  securitySchemes:
    ApiKeyAuth:
      type: http
      scheme: bearer
      bearerFormat: API key
      description: >-
        Project API key issued in Settings → API keys. Send it as
        `Authorization: Bearer pk_live_…`.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.