> ## 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.

# Confirm, reject or revise a build plan

> The follow-up to a `POST /v1/code` that answered `status: "needs_confirmation"` (projects on the new AI engine only, GRE-1040). `{id}` is that response's `plan_id`. Only the SAME credential whose build proposed the plan can decide it — the same API key (or the same MCP connection) — never another key of the same owner and never a plan proposed in the dashboard chat; any other plan id answers `404 not_found`.

- `approve` builds the plan now and answers like `POST /v1/code` (`status` `completed` / `needs_input`, `summary`, `files_changed`, plus `plan_id`). Approving a plan whose build stopped part-way resumes it from its first unfinished step. Consumes credits.
- `reject` drops the plan. `revise` records what to change — **`note` is required for revise** (`400 note_required` without it) — and the next `POST /v1/code` call plans again with that note. Both answer `status: "decided"`.

Repeating a decision is safe: a plan that is already building, built, or decided the same way answers `status: "decided"` with `already_decided: true` and starts nothing; a different decision on a decided plan is `409 plan_already_decided`. A plan waiting for its decision is replaced by the next request on the same credential (another `POST /v1/code`, `POST /v1/chat`, or MCP `ask_paige`): any decision on it then answers `409 plan_already_decided`, with a message saying it was replaced, and nothing starts. Send a new build request. Supports the optional `Idempotency-Key` header. Approving while another build is running on the project answers `409 build_in_progress`. A project not on the new engine answers `409 engine_unavailable`.

**Required scope:** `code:write`



## OpenAPI

````yaml /api-reference/openapi.json post /v1/code/plans/{id}/decision
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/code/plans/{id}/decision:
    post:
      tags:
        - Build
      summary: Confirm, reject or revise a build plan
      description: >-
        The follow-up to a `POST /v1/code` that answered `status:
        "needs_confirmation"` (projects on the new AI engine only, GRE-1040).
        `{id}` is that response's `plan_id`. Only the SAME credential whose
        build proposed the plan can decide it — the same API key (or the same
        MCP connection) — never another key of the same owner and never a plan
        proposed in the dashboard chat; any other plan id answers `404
        not_found`.


        - `approve` builds the plan now and answers like `POST /v1/code`
        (`status` `completed` / `needs_input`, `summary`, `files_changed`, plus
        `plan_id`). Approving a plan whose build stopped part-way resumes it
        from its first unfinished step. Consumes credits.

        - `reject` drops the plan. `revise` records what to change — **`note` is
        required for revise** (`400 note_required` without it) — and the next
        `POST /v1/code` call plans again with that note. Both answer `status:
        "decided"`.


        Repeating a decision is safe: a plan that is already building, built, or
        decided the same way answers `status: "decided"` with `already_decided:
        true` and starts nothing; a different decision on a decided plan is `409
        plan_already_decided`. A plan waiting for its decision is replaced by
        the next request on the same credential (another `POST /v1/code`, `POST
        /v1/chat`, or MCP `ask_paige`): any decision on it then answers `409
        plan_already_decided`, with a message saying it was replaced, and
        nothing starts. Send a new build request. Supports the optional
        `Idempotency-Key` header. Approving while another build is running on
        the project answers `409 build_in_progress`. A project not on the new
        engine answers `409 engine_unavailable`.


        **Required scope:** `code:write`
      operationId: decideBuildPlan
      parameters:
        - schema:
            type: string
          required: true
          name: id
          in: path
        - 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:
                decision:
                  type: string
                  enum:
                    - approve
                    - reject
                    - revise
                  description: >-
                    "approve" builds the plan now (and resumes a plan whose
                    build stopped part-way); "reject" drops it; "revise" records
                    what to change (note required) for the next build_code call
                    to plan again.
                note:
                  type: string
                  maxLength: 2000
                  description: >-
                    Optional guidance for the builder on approve; REQUIRED for
                    revise (what to change). At most 2000 characters.
              required:
                - decision
      responses:
        '200':
          description: Success.
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    enum:
                      - true
                  data:
                    type: object
                    properties:
                      summary:
                        type: string
                      files_changed:
                        type: array
                        items:
                          type: string
                      cancelled:
                        type: boolean
                      status:
                        type: string
                        enum:
                          - completed
                          - needs_input
                          - needs_confirmation
                          - decided
                        description: >-
                          `decided` for reject / revise and for a repeat;
                          otherwise the approved build's status, as on `POST
                          /v1/code`.
                      engine:
                        type: string
                        enum:
                          - v2
                        description: 'v2 engine only: which engine ran the build.'
                      turn_id:
                        type:
                          - string
                          - 'null'
                        description: >-
                          v2 engine only: the turn id (matches its trace and its
                          credit-ledger row).
                      plan_id:
                        type: string
                        description: >-
                          With `needs_confirmation` (and on an approved build):
                          the plan id.
                      plan:
                        type:
                          - object
                          - 'null'
                        properties: {}
                        description: >-
                          With `status: "decided"`: the plan row — `id`,
                          `status` (proposed | rejected | approved | building |
                          completed | failed), `decision`, `requires_approval`,
                          `completed_steps`, `plan`. With `needs_confirmation`
                          on `POST /v1/code`: the proposed plan itself.
                      confirm_path:
                        type: string
                        description: 'With `needs_confirmation`: where to send the decision.'
                      question:
                        type: string
                        description: >-
                          With `needs_input`: 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 `needs_input` 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 `needs_input` when Paige asked several things at
                          once (GRE-1128): 2 to 4 questions, each with its own
                          choices. Answer them all in one message.
                      tests:
                        type: object
                        properties:
                          status:
                            type: string
                            enum:
                              - passed
                              - failed
                              - inconclusive
                              - skipped
                              - aborted
                          reason:
                            type:
                              - string
                              - 'null'
                            description: >-
                              Why the run was skipped or not conclusive (e.g.
                              `insufficient_credits`, `run_in_progress`,
                              `ai_step_cap`, `missing_secrets`), or null.
                          scenarios:
                            type: array
                            items:
                              type: object
                              properties:
                                id:
                                  type: string
                                status:
                                  type: string
                                  enum:
                                    - passed
                                    - failed
                                    - inconclusive
                                    - skipped
                                    - aborted
                                reason:
                                  type:
                                    - string
                                    - 'null'
                                steps:
                                  type: integer
                                attempts:
                                  type: integer
                              required:
                                - id
                                - status
                                - reason
                                - steps
                                - attempts
                          missing_secrets:
                            type: array
                            items:
                              type: string
                            description: >-
                              With reason `missing_secrets` (or beside a failed
                              run): the project secret NAMES (never values) the
                              bot needs and that are not set. Add them in
                              Settings → Secrets; the scenarios that need them
                              were not played or not decided, and no fix round
                              was spent on them.
                          jev_calls:
                            type: integer
                          ai_steps:
                            type: integer
                          run_id:
                            type:
                              - string
                              - 'null'
                          duration_ms:
                            type: integer
                        required:
                          - status
                          - reason
                          - scenarios
                          - jev_calls
                          - ai_steps
                          - run_id
                          - duration_ms
                        description: >-
                          v2 engine only (GRE-1047): when the build changed the
                          bot and it has test scenarios, its tests were played
                          through the preview bot when the build finished; this
                          is the LAST run of the build. A failure the bot's code
                          caused went back to the builder, at most twice; never
                          while plan steps are open, and never for a failure the
                          test itself caused, a scenario that only ran out of
                          steps, or a missing project secret (`missing_secrets`:
                          only the user can add it). Codes and counts only —
                          never message text.
                      unfinished:
                        type: object
                        properties:
                          reason:
                            type: string
                            enum:
                              - unfinished
                              - steps
                              - tokens
                              - guarded
                            description: >-
                              `steps` or `tokens` when the turn hit that cap;
                              `unfinished` when the builder stopped by itself;
                              `guarded` when text a customer wrote looked like
                              an instruction (no `plan_id`: ask again in a new
                              request).
                          open_steps:
                            type: array
                            items:
                              type: object
                              properties:
                                id:
                                  type: string
                                title:
                                  type: string
                              required:
                                - id
                                - title
                          completed_steps:
                            type: array
                            items:
                              type: string
                          total_steps:
                            type: integer
                          plan_id:
                            type: string
                            description: >-
                              The saved plan: approve it again (the confirm
                              call) to build only the open steps.
                        required:
                          - reason
                          - open_steps
                          - completed_steps
                          - total_steps
                        description: >-
                          v2 engine only (GRE-1158): with `status: "completed"`,
                          a planned build that ended with steps still open.
                          Absent when every step is done. A caller must read
                          this: `completed` means the turn ended, not that the
                          plan is built.
                      already_decided:
                        type: boolean
                        description: >-
                          With `status: "decided"`: true when nothing new was
                          recorded or started (a repeat, a lost race, or a plan
                          already built).
                    required:
                      - status
                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'
        '404':
          description: Resource not found (`not_found` / `*_not_found`).
          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.