Runs Paige’s code agent (its system prompt, scaffold + connector awareness, and guardrails) in a bounded headless loop to write/edit the bot’s code from a natural-language instruction — the higher-quality counterpart to PUT /v1/files/{path}. Flow JSON is rejected (use the flow endpoints). Frozen/injected/auto-generated files (e.g. services/messages.js, config/mediaAssets.js, package.json, .paige/**) are refused (the validated test scenarios save is the one exception to .paige/**), while the agent still authors the bot wiring it owns (routes/*, app.js, config/db.js). Consumes credits; rejected with 402 insufficient_credits when out of balance. A truncated or failed agent run returns 502 build_failed.
Projects on the new AI engine (v2) answer with a status (GRE-1040). The request runs on the same engine as the dashboard chat, with nobody watching: it is routed (a question about the bot is answered, a change is built, a big change is planned first; every one of these is charged at its real cost), it may change WhatsApp Flows too when the key also holds flows:write (and read templates, broadcasts or conversation states only with templates:read / broadcasts:read / conversations:read; it never sends, never tags and never reads contacts — use those endpoints). Each credential (API key, or MCP connection) has its OWN build conversation: a build sees that credential’s earlier builds, never the dashboard chat or another key’s builds, and it never appears in the dashboard chat. One build per project at a time: a second POST /v1/code (or a plan approval) while a build is running on the project — or while the key owner has a chat turn running in the dashboard — answers 409 build_in_progress; retry when it has finished. A build that reaches its step or token limit stops there (it is never resumed automatically); send another call to carry on. Read status before anything else:
completed — done; summary and files_changed as before (cancelled: true when the run hit its time limit or you disconnected: what it wrote is kept).
needs_confirmation — a big change was PLANNED and nothing was built. A simple request for a new feature that collects structured input (a form, a booking, a menu to order from) can land here too, because such a feature can be sent to planning first so that a WhatsApp Flow is chosen where one fits: handle this status on every build. plan holds the plan (goal, approach, steps, risks, complexity, what it touches) and plan_id its id. Show it to your user, then call POST /v1/code/plans/{plan_id}/decision (confirm_path) with approve, reject or revise.
needs_input — Paige needs an answer before it can work; question is what it asked, and options (2 to 4, each a label and an optional description) when it asked one multiple-choice question: answer with one label, or with your own words when allow_other is true. When it asked several things at once, questions has them with their choices (and question lists them all): answer every one in the same message. Send the answer as the instruction of another POST /v1/code call: the question is part of the conversation that call reads.
Projects on the current engine never send status, engine, turn_id or the fields after them: their response is exactly the three fields it has always been.
Project API key issued in Settings → API keys. Send it as Authorization: Bearer pk_live_….
Headers
X-Paige-Project
string
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).
Body
application/json
instruction
string
required
Natural-language description of the code to write or change. Paige's code agent authors/edits the bot files using its own system prompt, scaffold + connector awareness, and guardrails.
Required string length: 1 - 10000
Response
Success.
success
enum<boolean>
required
Available options:
true
data
object
required
Hide child attributes
data.summary
string
required
What the agent did or said.
data.files_changed
string[]
required
Project files the run wrote (dev).
data.cancelled
boolean
required
True when the run was cut off (time limit, or the caller disconnected). Work already written is kept.
data.status
enum<string>
v2 engine only. needs_confirmation: a plan waits for POST /v1/code/plans/{plan_id}/decision. A big change gets one, and so can a simple request for a new feature that collects structured input (a form, a booking, a menu to order from), because such a feature can always be sent to planning first: be ready for this status on any build. needs_input: answer question with another POST /v1/code.
Available options:
completed,
needs_confirmation,
needs_input
data.engine
enum<string>
v2 engine only: which engine ran the build.
Available options:
v2
data.turn_id
string | null
v2 engine only: the turn id (matches its trace and its credit-ledger row).
data.plan_id
string
With needs_confirmation (and on an approved build): the plan id.
data.plan
object | null
With needs_confirmation: the proposed plan — goal, approach, build_choice (kind flow / code / both, reason, flows (each flow_name, mode static / dynamic, table), verification verified / unverified / unknown, messages_fallback; absent on plans saved before it existed, or when the planner gave no usable one), steps (each id, title, files, checks), risks, complexity (1-4), touches (deploy / data / broadcasts), optional contract_notes, optional literals (each kind field_name / body / header / key_format / url_path / reply_text, value exactly as the request gave it, context: the exact details the build is checked against), optional dashboard (title, request: a dashboard the user chose, which this plan does not build: ask for it in a new request once the build is done).
data.confirm_path
string
With needs_confirmation: where to send the decision.
data.question
string
With needs_input: what Paige asked. When it asked several things at once, every question, one per line (questions has their choices).
data.options
object[]
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.
Hide child attributes
data.options.label
string
required
The choice, in a few words. Send it back as the answer.
data.options.description
string
What choosing it means, in one line.
data.allow_other
boolean
With options: true when an answer other than the listed labels is welcome.
data.questions
object[]
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.
Hide child attributes
data.questions.question
string
required
What Paige asked.
data.questions.options
object[]
required
2 to 4 choices. Answer with one label, or with your own words when allow_other is true.
Hide child attributes
data.questions.options.label
string
required
The choice, in a few words. Send it back as the answer.
data.questions.options.description
string
What choosing it means, in one line.
data.questions.allow_other
boolean
required
True when an answer other than the listed labels is welcome.
data.tests
object
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.
Hide child attributes
data.tests.status
enum<string>
required
Available options:
passed,
failed,
inconclusive,
skipped,
aborted
data.tests.reason
string | null
required
Why the run was skipped or not conclusive (e.g. insufficient_credits, run_in_progress, ai_step_cap, missing_secrets), or null.
data.tests.scenarios
object[]
required
Hide child attributes
data.tests.scenarios.id
string
required
data.tests.scenarios.status
enum<string>
required
Available options:
passed,
failed,
inconclusive,
skipped,
aborted
data.tests.scenarios.reason
string | null
required
data.tests.scenarios.steps
integer
required
data.tests.scenarios.attempts
integer
required
data.tests.jev_calls
integer
required
data.tests.ai_steps
integer
required
data.tests.run_id
string | null
required
data.tests.duration_ms
integer
required
data.tests.missing_secrets
string[]
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.
data.unfinished
object
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.
Hide child attributes
data.unfinished.reason
enum<string>
required
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).
Available options:
unfinished,
steps,
tokens,
guarded
data.unfinished.open_steps
object[]
required
Hide child attributes
data.unfinished.open_steps.id
string
required
data.unfinished.open_steps.title
string
required
data.unfinished.completed_steps
string[]
required
data.unfinished.total_steps
integer
required
data.unfinished.plan_id
string
The saved plan: approve it again (the confirm call) to build only the open steps.
Was this page helpful?
{"docsConfig":{"theme":"mint","$schema":"https://mintlify.com/docs.json","name":"paige","description":"Build AI-powered WhatsApp bots with interactive flows, automated conversations, and a built-in database — no backend required.","colors":{"primary":"#81D741","light":"#cfeabb","dark":"#81D741"},"logo":{"light":"https://mintcdn.com/greenpages/SGZewfX5ti1H1LmZ/logo/green-pages-logo.png?fit=max\u0026auto=format\u0026n=SGZewfX5ti1H1LmZ\u0026q=85\u0026s=9b5fbf18d11676f6513a94ed3366cb7f","dark":"https://mintcdn.com/greenpages/SGZewfX5ti1H1LmZ/logo/green-pages-logo.png?fit=max\u0026auto=format\u0026n=SGZewfX5ti1H1LmZ\u0026q=85\u0026s=9b5fbf18d11676f6513a94ed3366cb7f"},"favicon":"https://mintcdn.com/greenpages/ns32KHaAM2ByMLCm/favicon.ico?fit=max\u0026auto=format\u0026n=ns32KHaAM2ByMLCm\u0026q=85\u0026s=10f80cc37fcecd5ef561ba85c6bca8d6","api":{"params":{"expanded":"all"},"playground":{"display":"simple"},"examples":{"languages":["curl","javascript","python"]}},"navbar":{"links":[],"primary":{"type":"button","label":"Start Building","href":"https://paigeme.dev"}},"footer":{"socials":{}},"fonts":{"family":"Geist"},"icons":{"library":"lucide"},"styling":{"eyebrows":"breadcrumbs","latex":true},"contextual":{"options":["copy","view","assistant","download-spec"],"display":"header"},"navigation":{"pages":[]}},"deployment":{"deploymentMetadataValue":{"subdomain":"greenpages","hasAudioNarration":false,"actualSubdomain":"greenpages","customDomains":["howto.paigeme.dev"],"gitSource":{"type":"github","owner":"brendangp","repo":"paige-docs","deployBranch":"main","isPrivate":false,"contentDirectory":"","mountPath":"","label":""},"feedback":{"thumbs":true},"entitlements":{"AI_CHAT":{"status":"DISABLED"}},"buildId":"6b007c142f71afcbab8c3194","clientVersion":"0.0.4286","searchFilterCounts":[{"language":"default","tag":"API","count":57},{"language":"default","tag":"Endpoints","count":49},{"language":"default","tag":"Features","count":42},{"language":"default","tag":"Settings","count":12},{"language":"default","tag":"Learn","count":10},{"language":"default","tag":"Build","count":10},{"language":"default","tag":"Introduction","count":9},{"language":"default","tag":"Getting started","count":8},{"language":"default","tag":"Broadcasts","count":8},{"language":"default","tag":"Tools","count":8}]},"assistantConfig":{"enableAskAiButton":false,"enableStarterQuestions":false,"enableContextualStarterQuestions":false,"enableAskAiSearchBar":true},"basePath":"","hasChatPermissions":false,"hasWebMcpPermissions":false,"toggles":[{"name":"kill-isr","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-rbac-roles","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-mintlify-slack","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-integrations-settings","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"rbac-expansion","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-pr-grouping","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-prefix","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"analytics-v7","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"user-flows-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"no-publish-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-onboarding","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving-live","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"stripTemperatureMiddleware","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"support-platform-pylon-zendesk","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"instant-rollback","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications-server","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-fable","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fixed-ai-action-pricing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"site-roles","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automation-resolve-merge-conflict","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"scoped-publishing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"mintql","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"page-level-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-version-history-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"billing-page-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"full-page-search","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workspace-projects","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"assistant-v5","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fork-pr-previews","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"revalidation-jwt","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-sso-scim","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"hobby-abuse-scan","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"dashboard-inbox","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-signup","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-dual-write","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-enabled","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"approve-review-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-metadata","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"sso-setup-deadline-banner","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-serve","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"live-agents","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"starter-pricing","enabled":true,"variant":{"name":"treatment","enabled":true,"payload":{"type":"string","value":"treatment"},"feature_enabled":true},"impressionData":false},{"name":"llms-txt-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"wildcard-email-auth","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false}],"googleFontsInlined":true},"customCss":[{"filePath":"style.css","content":"/* cyrillic-ext */\n@font-face {\n font-family: 'Geist Mono';\n font-style: normal;\n font-weight: 400;\n font-display: swap;\n src: url(/_mintlify/assets/fonts/google/s/geistmono/v6/or3nQ6H-1_WfwkMZI_qYFrodmgPn.woff2) format('woff2');\n unicode-range: U+0460-052F, U+1C80-1C8A, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F;\n}\n/* cyrillic */\n@font-face {\n font-family: 'Geist Mono';\n font-style: normal;\n font-weight: 400;\n font-display: swap;\n src: url(/_mintlify/assets/fonts/google/s/geistmono/v6/or3nQ6H-1_WfwkMZI_qYFrMdmgPn.woff2) format('woff2');\n unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;\n}\n/* symbols2 */\n@font-face {\n font-family: 'Geist Mono';\n font-style: normal;\n font-weight: 400;\n font-display: swap;\n src: url(/_mintlify/assets/fonts/google/s/geistmono/v6/or3nQ6H-1_WfwkMZI_qYFg08vz7ehw.woff2) format('woff2');\n unicode-range: U+2000-2001, U+2004-2008, U+200A, U+23B8-23BD, U+2500-259F;\n}\n/* vietnamese */\n@font-face {\n font-family: 'Geist Mono';\n font-style: normal;\n font-weight: 400;\n font-display: swap;\n src: url(/_mintlify/assets/fonts/google/s/geistmono/v6/or3nQ6H-1_WfwkMZI_qYFrgdmgPn.woff2) format('woff2');\n unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB;\n}\n/* latin-ext */\n@font-face {\n font-family: 'Geist Mono';\n font-style: normal;\n font-weight: 400;\n font-display: swap;\n src: url(/_mintlify/assets/fonts/google/s/geistmono/v6/or3nQ6H-1_WfwkMZI_qYFrkdmgPn.woff2) format('woff2');\n unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;\n}\n/* latin */\n@font-face {\n font-family: 'Geist Mono';\n font-style: normal;\n font-weight: 400;\n font-display: swap;\n src: url(/_mintlify/assets/fonts/google/s/geistmono/v6/or3nQ6H-1_WfwkMZI_qYFrcdmg.woff2) format('woff2');\n unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;\n}\n/* cyrillic-ext */\n@font-face {\n font-family: 'Geist Mono';\n font-style: normal;\n font-weight: 500;\n font-display: swap;\n src: url(/_mintlify/assets/fonts/google/s/geistmono/v6/or3nQ6H-1_WfwkMZI_qYFrodmgPn.woff2) format('woff2');\n unicode-range: U+0460-052F, U+1C80-1C8A, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F;\n}\n/* cyrillic */\n@font-face {\n font-family: 'Geist Mono';\n font-style: normal;\n font-weight: 500;\n font-display: swap;\n src: url(/_mintlify/assets/fonts/google/s/geistmono/v6/or3nQ6H-1_WfwkMZI_qYFrMdmgPn.woff2) format('woff2');\n unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;\n}\n/* symbols2 */\n@font-face {\n font-family: 'Geist Mono';\n font-style: normal;\n font-weight: 500;\n font-display: swap;\n src: url(/_mintlify/assets/fonts/google/s/geistmono/v6/or3nQ6H-1_WfwkMZI_qYFg08vz7ehw.woff2) format('woff2');\n unicode-range: U+2000-2001, U+2004-2008, U+200A, U+23B8-23BD, U+2500-259F;\n}\n/* vietnamese */\n@font-face {\n font-family: 'Geist Mono';\n font-style: normal;\n font-weight: 500;\n font-display: swap;\n src: url(/_mintlify/assets/fonts/google/s/geistmono/v6/or3nQ6H-1_WfwkMZI_qYFrgdmgPn.woff2) format('woff2');\n unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB;\n}\n/* latin-ext */\n@font-face {\n font-family: 'Geist Mono';\n font-style: normal;\n font-weight: 500;\n font-display: swap;\n src: url(/_mintlify/assets/fonts/google/s/geistmono/v6/or3nQ6H-1_WfwkMZI_qYFrkdmgPn.woff2) format('woff2');\n unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;\n}\n/* latin */\n@font-face {\n font-family: 'Geist Mono';\n font-style: normal;\n font-weight: 500;\n font-display: swap;\n src: url(/_mintlify/assets/fonts/google/s/geistmono/v6/or3nQ6H-1_WfwkMZI_qYFrcdmg.woff2) format('woff2');\n unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;\n}\n/* cyrillic-ext */\n@font-face {\n font-family: 'Geist Mono';\n font-style: normal;\n font-weight: 600;\n font-display: swap;\n src: url(/_mintlify/assets/fonts/google/s/geistmono/v6/or3nQ6H-1_WfwkMZI_qYFrodmgPn.woff2) format('woff2');\n unicode-range: U+0460-052F, U+1C80-1C8A, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F;\n}\n/* cyrillic */\n@font-face {\n font-family: 'Geist Mono';\n font-style: normal;\n font-weight: 600;\n font-display: swap;\n src: url(/_mintlify/assets/fonts/google/s/geistmono/v6/or3nQ6H-1_WfwkMZI_qYFrMdmgPn.woff2) format('woff2');\n unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;\n}\n/* symbols2 */\n@font-face {\n font-family: 'Geist Mono';\n font-style: normal;\n font-weight: 600;\n font-display: swap;\n src: url(/_mintlify/assets/fonts/google/s/geistmono/v6/or3nQ6H-1_WfwkMZI_qYFg08vz7ehw.woff2) format('woff2');\n unicode-range: U+2000-2001, U+2004-2008, U+200A, U+23B8-23BD, U+2500-259F;\n}\n/* vietnamese */\n@font-face {\n font-family: 'Geist Mono';\n font-style: normal;\n font-weight: 600;\n font-display: swap;\n src: url(/_mintlify/assets/fonts/google/s/geistmono/v6/or3nQ6H-1_WfwkMZI_qYFrgdmgPn.woff2) format('woff2');\n unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB;\n}\n/* latin-ext */\n@font-face {\n font-family: 'Geist Mono';\n font-style: normal;\n font-weight: 600;\n font-display: swap;\n src: url(/_mintlify/assets/fonts/google/s/geistmono/v6/or3nQ6H-1_WfwkMZI_qYFrkdmgPn.woff2) format('woff2');\n unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;\n}\n/* latin */\n@font-face {\n font-family: 'Geist Mono';\n font-style: normal;\n font-weight: 600;\n font-display: swap;\n src: url(/_mintlify/assets/fonts/google/s/geistmono/v6/or3nQ6H-1_WfwkMZI_qYFrcdmg.woff2) format('woff2');\n unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;\n}\n:root{--default-border-color: var(--gray-200)}.dark{--default-border-color: var(--gray-800)}#navbar a[href=\"/\"]:has(img.nav-logo){display:inline-flex!important;align-items:center}#navbar a[href=\"/\"]:has(img.nav-logo)::after{content:'paige';font-family:'Geist Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;color:#81D741;font-weight:500;font-size:1rem;letter-spacing:-0.01em;margin-left:0.5rem}#sidebar .nav-dropdown-trigger{border:none!important;border-radius:0!important;background:transparent!important;box-shadow:none!important;padding-left:0.375rem}#sidebar .nav-dropdown-trigger:hover{background-color:rgb(0 0 0 / 0.04)!important}.dark #sidebar .nav-dropdown-trigger:hover{background-color:rgb(255 255 255 / 0.06)!important}#sidebar .nav-dropdown-trigger .nav-dropdown-item-icon{border:none!important;border-radius:0!important;background:transparent!important;height:auto!important;width:auto!important;padding:0!important}.nav-dropdown-content{border-radius:0!important}.nav-dropdown-content .nav-dropdown-item{border-radius:0!important}.nav-dropdown-content .nav-dropdown-item-icon{border:none!important;border-radius:0!important;background:transparent!important;height:auto!important;width:auto!important;padding:0!important}.nav-dropdown-content .nav-dropdown-item-description{display:none!important}#sidebar .nav-anchor span{font-family:ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;font-size:12px;font-weight:500;letter-spacing:-0.02em;text-transform:uppercase}"}]}
{"page":{"pagePath":"api-reference/endpoints/build/author-or-edit-bot-code-via-the-code-agent","slug":"/api-reference/endpoints/build/author-or-edit-bot-code-via-the-code-agent","pageMetadata":{"title":"Author or edit bot code via the code agent","description":"Runs Paige's code agent (its system prompt, scaffold + connector awareness, and guardrails) in a bounded headless loop to write/edit the bot's code from a natural-language instruction — the higher-quality counterpart to `PUT /v1/files/{path}`. Flow JSON is rejected (use the flow endpoints). Frozen/injected/auto-generated files (e.g. `services/messages.js`, `config/mediaAssets.js`, `package.json`, `.paige/**`) are refused (the validated test scenarios save is the one exception to `.paige/**`), while the agent still authors the bot wiring it owns (`routes/*`, `app.js`, `config/db.js`). Consumes credits; rejected with `402 insufficient_credits` when out of balance. A truncated or failed agent run returns `502 build_failed`.\n\n**Projects on the new AI engine (v2) answer with a `status` (GRE-1040).** The request runs on the same engine as the dashboard chat, with nobody watching: it is routed (a question about the bot is answered, a change is built, a big change is planned first; every one of these is charged at its real cost), it may change WhatsApp Flows too when the key also holds `flows:write` (and read templates, broadcasts or conversation states only with `templates:read` / `broadcasts:read` / `conversations:read`; it never sends, never tags and never reads contacts — use those endpoints). Each credential (API key, or MCP connection) has its OWN build conversation: a build sees that credential's earlier builds, never the dashboard chat or another key's builds, and it never appears in the dashboard chat. **One build per project at a time:** a second `POST /v1/code` (or a plan approval) while a build is running on the project — or while the key owner has a chat turn running in the dashboard — answers `409 build_in_progress`; retry when it has finished. A build that reaches its step or token limit stops there (it is never resumed automatically); send another call to carry on. Read `status` before anything else:\n- `completed` — done; `summary` and `files_changed` as before (`cancelled: true` when the run hit its time limit or you disconnected: what it wrote is kept).\n- `needs_confirmation` — a big change was PLANNED and nothing was built. A simple request for a new feature that collects structured input (a form, a booking, a menu to order from) can land here too, because such a feature can be sent to planning first so that a WhatsApp Flow is chosen where one fits: handle this status on every build. `plan` holds the plan (goal, approach, steps, risks, complexity, what it touches) and `plan_id` its id. Show it to your user, then call `POST /v1/code/plans/{plan_id}/decision` (`confirm_path`) with `approve`, `reject` or `revise`.\n- `needs_input` — Paige needs an answer before it can work; `question` is what it asked, and `options` (2 to 4, each a `label` and an optional `description`) when it asked one multiple-choice question: answer with one label, or with your own words when `allow_other` is true. When it asked several things at once, `questions` has them with their choices (and `question` lists them all): answer every one in the same message. Send the answer as the `instruction` of another `POST /v1/code` call: the question is part of the conversation that call reads.\nProjects on the current engine never send `status`, `engine`, `turn_id` or the fields after them: their response is exactly the three fields it has always been.\n\n**Required scope:** `code:write`","deprecated":null,"version":null,"openapi":"/api-reference/openapi.json post /v1/code","href":"/api-reference/endpoints/build/author-or-edit-bot-code-via-the-code-agent","autogeneratedByOpenApi":true},"description":{"compiledSource":"\"use strict\";\nconst {Fragment: _Fragment, jsx: _jsx, jsxs: _jsxs} = arguments[0];\nconst {useMDXComponents: _provideComponents} = arguments[0];\nfunction _createMdxContent(props) {\n const _components = {\n code: \"code\",\n li: \"li\",\n p: \"p\",\n strong: \"strong\",\n ul: \"ul\",\n ..._provideComponents(),\n ...props.components\n };\n return _jsxs(_Fragment, {\n children: [_jsxs(_components.p, {\n children: [\"Runs Paige’s code agent (its system prompt, scaffold + connector awareness, and guardrails) in a bounded headless loop to write/edit the bot’s code from a natural-language instruction — the higher-quality counterpart to \", _jsx(_components.code, {\n children: \"PUT /v1/files/{path}\"\n }), \". Flow JSON is rejected (use the flow endpoints). Frozen/injected/auto-generated files (e.g. \", _jsx(_components.code, {\n children: \"services/messages.js\"\n }), \", \", _jsx(_components.code, {\n children: \"config/mediaAssets.js\"\n }), \", \", _jsx(_components.code, {\n children: \"package.json\"\n }), \", \", _jsx(_components.code, {\n children: \".paige/**\"\n }), \") are refused (the validated test scenarios save is the one exception to \", _jsx(_components.code, {\n children: \".paige/**\"\n }), \"), while the agent still authors the bot wiring it owns (\", _jsx(_components.code, {\n children: \"routes/*\"\n }), \", \", _jsx(_components.code, {\n children: \"app.js\"\n }), \", \", _jsx(_components.code, {\n children: \"config/db.js\"\n }), \"). Consumes credits; rejected with \", _jsx(_components.code, {\n children: \"402 insufficient_credits\"\n }), \" when out of balance. A truncated or failed agent run returns \", _jsx(_components.code, {\n children: \"502 build_failed\"\n }), \".\"]\n }), \"\\n\", _jsxs(_components.p, {\n children: [_jsxs(_components.strong, {\n children: [\"Projects on the new AI engine (v2) answer with a \", _jsx(_components.code, {\n children: \"status\"\n }), \" (GRE-1040).\"]\n }), \" The request runs on the same engine as the dashboard chat, with nobody watching: it is routed (a question about the bot is answered, a change is built, a big change is planned first; every one of these is charged at its real cost), it may change WhatsApp Flows too when the key also holds \", _jsx(_components.code, {\n children: \"flows:write\"\n }), \" (and read templates, broadcasts or conversation states only with \", _jsx(_components.code, {\n children: \"templates:read\"\n }), \" / \", _jsx(_components.code, {\n children: \"broadcasts:read\"\n }), \" / \", _jsx(_components.code, {\n children: \"conversations:read\"\n }), \"; it never sends, never tags and never reads contacts — use those endpoints). Each credential (API key, or MCP connection) has its OWN build conversation: a build sees that credential’s earlier builds, never the dashboard chat or another key’s builds, and it never appears in the dashboard chat. \", _jsx(_components.strong, {\n children: \"One build per project at a time:\"\n }), \" a second \", _jsx(_components.code, {\n children: \"POST /v1/code\"\n }), \" (or a plan approval) while a build is running on the project — or while the key owner has a chat turn running in the dashboard — answers \", _jsx(_components.code, {\n children: \"409 build_in_progress\"\n }), \"; retry when it has finished. A build that reaches its step or token limit stops there (it is never resumed automatically); send another call to carry on. Read \", _jsx(_components.code, {\n children: \"status\"\n }), \" before anything else:\"]\n }), \"\\n\", _jsxs(_components.ul, {\n children: [\"\\n\", _jsxs(_components.li, {\n children: [_jsx(_components.code, {\n children: \"completed\"\n }), \" — done; \", _jsx(_components.code, {\n children: \"summary\"\n }), \" and \", _jsx(_components.code, {\n children: \"files_changed\"\n }), \" as before (\", _jsx(_components.code, {\n children: \"cancelled: true\"\n }), \" when the run hit its time limit or you disconnected: what it wrote is kept).\"]\n }), \"\\n\", _jsxs(_components.li, {\n children: [_jsx(_components.code, {\n children: \"needs_confirmation\"\n }), \" — a big change was PLANNED and nothing was built. A simple request for a new feature that collects structured input (a form, a booking, a menu to order from) can land here too, because such a feature can be sent to planning first so that a WhatsApp Flow is chosen where one fits: handle this status on every build. \", _jsx(_components.code, {\n children: \"plan\"\n }), \" holds the plan (goal, approach, steps, risks, complexity, what it touches) and \", _jsx(_components.code, {\n children: \"plan_id\"\n }), \" its id. Show it to your user, then call \", _jsx(_components.code, {\n children: \"POST /v1/code/plans/{plan_id}/decision\"\n }), \" (\", _jsx(_components.code, {\n children: \"confirm_path\"\n }), \") with \", _jsx(_components.code, {\n children: \"approve\"\n }), \", \", _jsx(_components.code, {\n children: \"reject\"\n }), \" or \", _jsx(_components.code, {\n children: \"revise\"\n }), \".\"]\n }), \"\\n\", _jsxs(_components.li, {\n children: [_jsx(_components.code, {\n children: \"needs_input\"\n }), \" — Paige needs an answer before it can work; \", _jsx(_components.code, {\n children: \"question\"\n }), \" is what it asked, and \", _jsx(_components.code, {\n children: \"options\"\n }), \" (2 to 4, each a \", _jsx(_components.code, {\n children: \"label\"\n }), \" and an optional \", _jsx(_components.code, {\n children: \"description\"\n }), \") when it asked one multiple-choice question: answer with one label, or with your own words when \", _jsx(_components.code, {\n children: \"allow_other\"\n }), \" is true. When it asked several things at once, \", _jsx(_components.code, {\n children: \"questions\"\n }), \" has them with their choices (and \", _jsx(_components.code, {\n children: \"question\"\n }), \" lists them all): answer every one in the same message. Send the answer as the \", _jsx(_components.code, {\n children: \"instruction\"\n }), \" of another \", _jsx(_components.code, {\n children: \"POST /v1/code\"\n }), \" call: the question is part of the conversation that call reads.\\nProjects on the current engine never send \", _jsx(_components.code, {\n children: \"status\"\n }), \", \", _jsx(_components.code, {\n children: \"engine\"\n }), \", \", _jsx(_components.code, {\n children: \"turn_id\"\n }), \" or the fields after them: their response is exactly the three fields it has always been.\"]\n }), \"\\n\"]\n }), \"\\n\", _jsxs(_components.p, {\n children: [_jsx(_components.strong, {\n children: \"Required scope:\"\n }), \" \", _jsx(_components.code, {\n children: \"code:write\"\n })]\n })]\n });\n}\nfunction MDXContent(props = {}) {\n const {wrapper: MDXLayout} = {\n ..._provideComponents(),\n ...props.components\n };\n return MDXLayout ? _jsx(MDXLayout, {\n ...props,\n children: _jsx(_createMdxContent, {\n ...props\n })\n }) : _createMdxContent(props);\n}\nreturn {\n default: MDXContent\n};\n","frontmatter":{},"scope":{}},"pageType":"default","mdx":{"mdxSource":{"compiledSource":"\"use strict\";const{Fragment:_Fragment,jsx:_jsx}=arguments[0];const{useMDXComponents:_provideComponents}=arguments[0];function _createMdxContent(props){return _jsx(_Fragment,{})}function MDXContent(props={}){const{wrapper:MDXLayout}={..._provideComponents(),...props.components};return MDXLayout?_jsx(MDXLayout,{...props,children:_jsx(_createMdxContent,{...props})}):_createMdxContent(props)}return{default:MDXContent}","frontmatter":{},"scope":{"config":{},"pageMetadata":{"title":"Author or edit bot code via the code agent","description":"Runs Paige's code agent (its system prompt, scaffold + connector awareness, and guardrails) in a bounded headless loop to write/edit the bot's code from a natural-language instruction — the higher-quality counterpart to `PUT /v1/files/{path}`. Flow JSON is rejected (use the flow endpoints). Frozen/injected/auto-generated files (e.g. `services/messages.js`, `config/mediaAssets.js`, `package.json`, `.paige/**`) are refused (the validated test scenarios save is the one exception to `.paige/**`), while the agent still authors the bot wiring it owns (`routes/*`, `app.js`, `config/db.js`). Consumes credits; rejected with `402 insufficient_credits` when out of balance. A truncated or failed agent run returns `502 build_failed`.\n\n**Projects on the new AI engine (v2) answer with a `status` (GRE-1040).** The request runs on the same engine as the dashboard chat, with nobody watching: it is routed (a question about the bot is answered, a change is built, a big change is planned first; every one of these is charged at its real cost), it may change WhatsApp Flows too when the key also holds `flows:write` (and read templates, broadcasts or conversation states only with `templates:read` / `broadcasts:read` / `conversations:read`; it never sends, never tags and never reads contacts — use those endpoints). Each credential (API key, or MCP connection) has its OWN build conversation: a build sees that credential's earlier builds, never the dashboard chat or another key's builds, and it never appears in the dashboard chat. **One build per project at a time:** a second `POST /v1/code` (or a plan approval) while a build is running on the project — or while the key owner has a chat turn running in the dashboard — answers `409 build_in_progress`; retry when it has finished. A build that reaches its step or token limit stops there (it is never resumed automatically); send another call to carry on. Read `status` before anything else:\n- `completed` — done; `summary` and `files_changed` as before (`cancelled: true` when the run hit its time limit or you disconnected: what it wrote is kept).\n- `needs_confirmation` — a big change was PLANNED and nothing was built. A simple request for a new feature that collects structured input (a form, a booking, a menu to order from) can land here too, because such a feature can be sent to planning first so that a WhatsApp Flow is chosen where one fits: handle this status on every build. `plan` holds the plan (goal, approach, steps, risks, complexity, what it touches) and `plan_id` its id. Show it to your user, then call `POST /v1/code/plans/{plan_id}/decision` (`confirm_path`) with `approve`, `reject` or `revise`.\n- `needs_input` — Paige needs an answer before it can work; `question` is what it asked, and `options` (2 to 4, each a `label` and an optional `description`) when it asked one multiple-choice question: answer with one label, or with your own words when `allow_other` is true. When it asked several things at once, `questions` has them with their choices (and `question` lists them all): answer every one in the same message. Send the answer as the `instruction` of another `POST /v1/code` call: the question is part of the conversation that call reads.\nProjects on the current engine never send `status`, `engine`, `turn_id` or the fields after them: their response is exactly the three fields it has always been.\n\n**Required scope:** `code:write`","deprecated":null,"version":null,"openapi":"/api-reference/openapi.json post /v1/code","href":"/api-reference/endpoints/build/author-or-edit-bot-code-via-the-code-agent","autogeneratedByOpenApi":true}}},"mdxSourceWithNoJs":null},"mdxExtracts":{"tableOfContents":[],"codeExamples":{}},"jsLinks":[],"openApiReferenceData":{"operation":{"operationId":"buildCode","tags":["Build"],"summary":"Author or edit bot code via the code agent","description":"Runs Paige's code agent (its system prompt, scaffold + connector awareness, and guardrails) in a bounded headless loop to write/edit the bot's code from a natural-language instruction — the higher-quality counterpart to `PUT /v1/files/{path}`. Flow JSON is rejected (use the flow endpoints). Frozen/injected/auto-generated files (e.g. `services/messages.js`, `config/mediaAssets.js`, `package.json`, `.paige/**`) are refused (the validated test scenarios save is the one exception to `.paige/**`), while the agent still authors the bot wiring it owns (`routes/*`, `app.js`, `config/db.js`). Consumes credits; rejected with `402 insufficient_credits` when out of balance. A truncated or failed agent run returns `502 build_failed`.\n\n**Projects on the new AI engine (v2) answer with a `status` (GRE-1040).** The request runs on the same engine as the dashboard chat, with nobody watching: it is routed (a question about the bot is answered, a change is built, a big change is planned first; every one of these is charged at its real cost), it may change WhatsApp Flows too when the key also holds `flows:write` (and read templates, broadcasts or conversation states only with `templates:read` / `broadcasts:read` / `conversations:read`; it never sends, never tags and never reads contacts — use those endpoints). Each credential (API key, or MCP connection) has its OWN build conversation: a build sees that credential's earlier builds, never the dashboard chat or another key's builds, and it never appears in the dashboard chat. **One build per project at a time:** a second `POST /v1/code` (or a plan approval) while a build is running on the project — or while the key owner has a chat turn running in the dashboard — answers `409 build_in_progress`; retry when it has finished. A build that reaches its step or token limit stops there (it is never resumed automatically); send another call to carry on. Read `status` before anything else:\n- `completed` — done; `summary` and `files_changed` as before (`cancelled: true` when the run hit its time limit or you disconnected: what it wrote is kept).\n- `needs_confirmation` — a big change was PLANNED and nothing was built. A simple request for a new feature that collects structured input (a form, a booking, a menu to order from) can land here too, because such a feature can be sent to planning first so that a WhatsApp Flow is chosen where one fits: handle this status on every build. `plan` holds the plan (goal, approach, steps, risks, complexity, what it touches) and `plan_id` its id. Show it to your user, then call `POST /v1/code/plans/{plan_id}/decision` (`confirm_path`) with `approve`, `reject` or `revise`.\n- `needs_input` — Paige needs an answer before it can work; `question` is what it asked, and `options` (2 to 4, each a `label` and an optional `description`) when it asked one multiple-choice question: answer with one label, or with your own words when `allow_other` is true. When it asked several things at once, `questions` has them with their choices (and `question` lists them all): answer every one in the same message. Send the answer as the `instruction` of another `POST /v1/code` call: the question is part of the conversation that call reads.\nProjects on the current engine never send `status`, `engine`, `turn_id` or the fields after them: their response is exactly the three fields it has always been.\n\n**Required scope:** `code:write`","security":["1f0a3921-581d-4579-9edc-6750446c0dbf"],"x-required-scopes":["code:write"],"parameters":["8af0b44c-8eb9-40ff-8e0c-b3d815d4bfe1"],"requestBody":"fba96b3c-db68-4583-914c-01f6963199e8","responses":{"200":"91ecc45d-7e45-49b2-813a-2e3e2f4f58a9","400":"8ce14133-cf1f-4b05-a962-07b2471a473a","401":"412a5187-93ac-494f-99f3-d0c40b5bf423","402":"b408dde4-967b-46df-b25a-a6b3e81f0a68","403":"ffc28878-3a92-42b1-b0dc-f8c5764fc90c","409":"dd2b0a20-202f-472b-a11d-a692fc6eefe8","429":"0aed04ec-7f14-45ab-acae-faa58a84ce49","500":"7817aaaf-fdeb-4791-9cd7-621c998a1cf0","502":"8e6d5dbd-1cb0-4de5-b850-919963923f27","503":"5f8932b1-77ea-4e2f-a1f6-1483b4c0176f"},"method":"post","type":"path","servers":["2f61f958-73d8-4f9e-a417-8b9b7e2662ed"],"path":"/v1/code","baseUrlOptions":["https://api.paigeme.dev"],"title":"Author or edit bot code via the code agent","codeSamples":[],"requestExampleLanguages":["bash","javascript","python"],"requiredOnlyExamples":false,"requestExampleType":"generated","responseExampleType":"generated"},"dependencies":{"parameters":{"8af0b44c-8eb9-40ff-8e0c-b3d815d4bfe1":{"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.\n\nOmit 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.\n\nScopes are checked against the SELECTED project only, never a union across the connection.\n\nFor 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).","isRequired":false,"uniqueKey":"","typeLabel":"string"},"required":false,"name":"X-Paige-Project","in":"header"}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"instruction":{"type":"string","minLength":1,"maxLength":10000,"description":"Natural-language description of the code to write or change. Paige's code agent authors/edits the bot files using its own system prompt, scaffold + connector awareness, and guardrails.","isRequired":true,"uniqueKey":"instruction","typeLabel":"string"}},"required":["instruction"],"uniqueKey":"","typeLabel":"object"},"examples":{"Example":{"title":"Example","value":{"instruction":"\u003cstring>"}}},"exampleType":"generated"}},"exampleType":"generated"},"responses":{"91ecc45d-7e45-49b2-813a-2e3e2f4f58a9":{"description":"Success.","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean","enum":[true],"isRequired":true,"uniqueKey":"success","typeLabel":"enum\u003cboolean>"},"data":{"type":"object","properties":{"summary":{"type":"string","description":"What the agent did or said.","isRequired":true,"uniqueKey":"data.summary","typeLabel":"string"},"files_changed":{"type":"array","items":{"type":"string","uniqueKey":"data.files_changed.items.[INDEX]","typeLabel":"string"},"description":"Project files the run wrote (dev).","isRequired":true,"uniqueKey":"data.files_changed","typeLabel":"string[]"},"cancelled":{"type":"boolean","description":"True when the run was cut off (time limit, or the caller disconnected). Work already written is kept.","isRequired":true,"uniqueKey":"data.cancelled","typeLabel":"boolean"},"status":{"type":"string","enum":["completed","needs_confirmation","needs_input"],"description":"v2 engine only. `needs_confirmation`: a plan waits for POST /v1/code/plans/{plan_id}/decision. A big change gets one, and so can a simple request for a new feature that collects structured input (a form, a booking, a menu to order from), because such a feature can always be sent to planning first: be ready for this status on any build. `needs_input`: answer `question` with another POST /v1/code.","uniqueKey":"data.status","typeLabel":"enum\u003cstring>"},"engine":{"type":"string","enum":["v2"],"description":"v2 engine only: which engine ran the build.","uniqueKey":"data.engine","typeLabel":"enum\u003cstring>"},"turn_id":{"oneOf":[{"type":"string","description":"v2 engine only: the turn id (matches its trace and its credit-ledger row).","uniqueKey":"data.turn_id.oneOf.0","typeLabel":"string"},{"type":"null","description":"v2 engine only: the turn id (matches its trace and its credit-ledger row).","uniqueKey":"data.turn_id.oneOf.1","typeLabel":"null"}],"uniqueKey":"data.turn_id","typeLabel":"string | null"},"plan_id":{"type":"string","description":"With `needs_confirmation` (and on an approved build): the plan id.","uniqueKey":"data.plan_id","typeLabel":"string"},"plan":{"oneOf":[{"type":"object","properties":{},"description":"With `needs_confirmation`: the proposed plan — `goal`, `approach`, `build_choice` (`kind` flow / code / both, `reason`, `flows` (each `flow_name`, `mode` static / dynamic, `table`), `verification` verified / unverified / unknown, `messages_fallback`; absent on plans saved before it existed, or when the planner gave no usable one), `steps` (each `id`, `title`, `files`, `checks`), `risks`, `complexity` (1-4), `touches` (`deploy` / `data` / `broadcasts`), optional `contract_notes`, optional `literals` (each `kind` field_name / body / header / key_format / url_path / reply_text, `value` exactly as the request gave it, `context`: the exact details the build is checked against), optional `dashboard` (`title`, `request`: a dashboard the user chose, which this plan does not build: ask for it in a new request once the build is done).","uniqueKey":"data.plan.oneOf.0","typeLabel":"object"},{"type":"null","properties":{},"description":"With `needs_confirmation`: the proposed plan — `goal`, `approach`, `build_choice` (`kind` flow / code / both, `reason`, `flows` (each `flow_name`, `mode` static / dynamic, `table`), `verification` verified / unverified / unknown, `messages_fallback`; absent on plans saved before it existed, or when the planner gave no usable one), `steps` (each `id`, `title`, `files`, `checks`), `risks`, `complexity` (1-4), `touches` (`deploy` / `data` / `broadcasts`), optional `contract_notes`, optional `literals` (each `kind` field_name / body / header / key_format / url_path / reply_text, `value` exactly as the request gave it, `context`: the exact details the build is checked against), optional `dashboard` (`title`, `request`: a dashboard the user chose, which this plan does not build: ask for it in a new request once the build is done).","uniqueKey":"data.plan.oneOf.1","typeLabel":"null"}],"uniqueKey":"data.plan","typeLabel":"object | null"},"confirm_path":{"type":"string","description":"With `needs_confirmation`: where to send the decision.","uniqueKey":"data.confirm_path","typeLabel":"string"},"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).","uniqueKey":"data.question","typeLabel":"string"},"options":{"type":"array","items":{"type":"object","properties":{"label":{"type":"string","description":"The choice, in a few words. Send it back as the answer.","isRequired":true,"uniqueKey":"data.options.items.[INDEX].label","typeLabel":"string"},"description":{"type":"string","description":"What choosing it means, in one line.","uniqueKey":"data.options.items.[INDEX].description","typeLabel":"string"}},"required":["label"],"uniqueKey":"data.options.items.[INDEX]","typeLabel":"object"},"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.","uniqueKey":"data.options","typeLabel":"object[]"},"allow_other":{"type":"boolean","description":"With `options`: true when an answer other than the listed labels is welcome.","uniqueKey":"data.allow_other","typeLabel":"boolean"},"questions":{"type":"array","items":{"type":"object","properties":{"question":{"type":"string","description":"What Paige asked.","isRequired":true,"uniqueKey":"data.questions.items.[INDEX].question","typeLabel":"string"},"options":{"type":"array","items":{"type":"object","properties":{"label":{"type":"string","description":"The choice, in a few words. Send it back as the answer.","isRequired":true,"uniqueKey":"data.questions.items.[INDEX].options.items.[INDEX].label","typeLabel":"string"},"description":{"type":"string","description":"What choosing it means, in one line.","uniqueKey":"data.questions.items.[INDEX].options.items.[INDEX].description","typeLabel":"string"}},"required":["label"],"uniqueKey":"data.questions.items.[INDEX].options.items.[INDEX]","typeLabel":"object"},"description":"2 to 4 choices. Answer with one `label`, or with your own words when `allow_other` is true.","isRequired":true,"uniqueKey":"data.questions.items.[INDEX].options","typeLabel":"object[]"},"allow_other":{"type":"boolean","description":"True when an answer other than the listed labels is welcome.","isRequired":true,"uniqueKey":"data.questions.items.[INDEX].allow_other","typeLabel":"boolean"}},"required":["question","options","allow_other"],"uniqueKey":"data.questions.items.[INDEX]","typeLabel":"object"},"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.","uniqueKey":"data.questions","typeLabel":"object[]"},"tests":{"type":"object","properties":{"status":{"type":"string","enum":["passed","failed","inconclusive","skipped","aborted"],"isRequired":true,"uniqueKey":"data.tests.status","typeLabel":"enum\u003cstring>"},"reason":{"oneOf":[{"type":"string","description":"Why the run was skipped or not conclusive (e.g. `insufficient_credits`, `run_in_progress`, `ai_step_cap`, `missing_secrets`), or null.","isRequired":true,"uniqueKey":"data.tests.reason.oneOf.0","typeLabel":"string"},{"type":"null","description":"Why the run was skipped or not conclusive (e.g. `insufficient_credits`, `run_in_progress`, `ai_step_cap`, `missing_secrets`), or null.","isRequired":true,"uniqueKey":"data.tests.reason.oneOf.1","typeLabel":"null"}],"isRequired":true,"uniqueKey":"data.tests.reason","typeLabel":"string | null"},"scenarios":{"type":"array","items":{"type":"object","properties":{"id":{"type":"string","isRequired":true,"uniqueKey":"data.tests.scenarios.items.[INDEX].id","typeLabel":"string"},"status":{"type":"string","enum":["passed","failed","inconclusive","skipped","aborted"],"isRequired":true,"uniqueKey":"data.tests.scenarios.items.[INDEX].status","typeLabel":"enum\u003cstring>"},"reason":{"oneOf":[{"type":"string","isRequired":true,"uniqueKey":"data.tests.scenarios.items.[INDEX].reason.oneOf.0","typeLabel":"string"},{"type":"null","isRequired":true,"uniqueKey":"data.tests.scenarios.items.[INDEX].reason.oneOf.1","typeLabel":"null"}],"isRequired":true,"uniqueKey":"data.tests.scenarios.items.[INDEX].reason","typeLabel":"string | null"},"steps":{"type":"integer","isRequired":true,"uniqueKey":"data.tests.scenarios.items.[INDEX].steps","typeLabel":"integer"},"attempts":{"type":"integer","isRequired":true,"uniqueKey":"data.tests.scenarios.items.[INDEX].attempts","typeLabel":"integer"}},"required":["id","status","reason","steps","attempts"],"uniqueKey":"data.tests.scenarios.items.[INDEX]","typeLabel":"object"},"isRequired":true,"uniqueKey":"data.tests.scenarios","typeLabel":"object[]"},"jev_calls":{"type":"integer","isRequired":true,"uniqueKey":"data.tests.jev_calls","typeLabel":"integer"},"ai_steps":{"type":"integer","isRequired":true,"uniqueKey":"data.tests.ai_steps","typeLabel":"integer"},"run_id":{"oneOf":[{"type":"string","isRequired":true,"uniqueKey":"data.tests.run_id.oneOf.0","typeLabel":"string"},{"type":"null","isRequired":true,"uniqueKey":"data.tests.run_id.oneOf.1","typeLabel":"null"}],"isRequired":true,"uniqueKey":"data.tests.run_id","typeLabel":"string | null"},"duration_ms":{"type":"integer","isRequired":true,"uniqueKey":"data.tests.duration_ms","typeLabel":"integer"},"missing_secrets":{"type":"array","items":{"type":"string","uniqueKey":"data.tests.missing_secrets.items.[INDEX]","typeLabel":"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.","uniqueKey":"data.tests.missing_secrets","typeLabel":"string[]"}},"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.","uniqueKey":"data.tests","typeLabel":"object"},"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).","isRequired":true,"uniqueKey":"data.unfinished.reason","typeLabel":"enum\u003cstring>"},"open_steps":{"type":"array","items":{"type":"object","properties":{"id":{"type":"string","isRequired":true,"uniqueKey":"data.unfinished.open_steps.items.[INDEX].id","typeLabel":"string"},"title":{"type":"string","isRequired":true,"uniqueKey":"data.unfinished.open_steps.items.[INDEX].title","typeLabel":"string"}},"required":["id","title"],"uniqueKey":"data.unfinished.open_steps.items.[INDEX]","typeLabel":"object"},"isRequired":true,"uniqueKey":"data.unfinished.open_steps","typeLabel":"object[]"},"completed_steps":{"type":"array","items":{"type":"string","uniqueKey":"data.unfinished.completed_steps.items.[INDEX]","typeLabel":"string"},"isRequired":true,"uniqueKey":"data.unfinished.completed_steps","typeLabel":"string[]"},"total_steps":{"type":"integer","isRequired":true,"uniqueKey":"data.unfinished.total_steps","typeLabel":"integer"},"plan_id":{"type":"string","description":"The saved plan: approve it again (the confirm call) to build only the open steps.","uniqueKey":"data.unfinished.plan_id","typeLabel":"string"}},"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.","uniqueKey":"data.unfinished","typeLabel":"object"}},"required":["summary","files_changed","cancelled"],"isRequired":true,"uniqueKey":"data","typeLabel":"object"}},"required":["success","data"],"uniqueKey":"","typeLabel":"object"},"examples":{"Example":{"title":"Example","value":{"success":true,"data":{"summary":"\u003cstring>","files_changed":["\u003cstring>"],"cancelled":true,"status":"completed","engine":"v2","turn_id":"\u003cstring>","plan_id":"\u003cstring>","plan":{},"confirm_path":"\u003cstring>","question":"\u003cstring>","options":[{"label":"\u003cstring>","description":"\u003cstring>"}],"allow_other":true,"questions":[{"question":"\u003cstring>","options":[{"label":"\u003cstring>","description":"\u003cstring>"}],"allow_other":true}],"tests":{"status":"passed","reason":"\u003cstring>","scenarios":[{"id":"\u003cstring>","status":"passed","reason":"\u003cstring>","steps":123,"attempts":123}],"jev_calls":123,"ai_steps":123,"run_id":"\u003cstring>","duration_ms":123,"missing_secrets":["\u003cstring>"]},"unfinished":{"reason":"unfinished","open_steps":[{"id":"\u003cstring>","title":"\u003cstring>"}],"completed_steps":["\u003cstring>"],"total_steps":123,"plan_id":"\u003cstring>"}}}}},"exampleType":"generated"}},"exampleType":"generated"},"8ce14133-cf1f-4b05-a962-07b2471a473a":{"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":{"type":"object","properties":{"success":{"type":"boolean","enum":[false],"isRequired":true,"uniqueKey":"success","typeLabel":"enum\u003cboolean>"},"error":{"type":"object","properties":{"code":{"type":"string","description":"Stable, machine-readable error code.","example":"invalid_request","isRequired":true,"uniqueKey":"error.code","typeLabel":"string"},"message":{"type":"string","description":"Human-readable message (safe to surface).","example":"Invalid request body","isRequired":true,"uniqueKey":"error.message","typeLabel":"string"},"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.","uniqueKey":"error.details","typeLabel":"object"}},"required":["code","message"],"isRequired":true,"uniqueKey":"error","typeLabel":"object"},"request_id":{"type":"string","description":"Per-request id, also returned as the X-Request-Id header.","isRequired":true,"uniqueKey":"request_id","typeLabel":"string"}},"required":["success","error","request_id"],"uniqueKey":"","typeLabel":"object"},"examples":{"Example":{"title":"Example","value":{"success":false,"error":{"code":"invalid_request","message":"Invalid request body","details":{}},"request_id":"\u003cstring>"}}},"exampleType":"generated"}},"exampleType":"generated"},"412a5187-93ac-494f-99f3-d0c40b5bf423":{"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":{"type":"object","properties":{"success":{"type":"boolean","enum":[false],"isRequired":true,"uniqueKey":"success","typeLabel":"enum\u003cboolean>"},"error":{"type":"object","properties":{"code":{"type":"string","description":"Stable, machine-readable error code.","example":"invalid_request","isRequired":true,"uniqueKey":"error.code","typeLabel":"string"},"message":{"type":"string","description":"Human-readable message (safe to surface).","example":"Invalid request body","isRequired":true,"uniqueKey":"error.message","typeLabel":"string"},"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.","uniqueKey":"error.details","typeLabel":"object"}},"required":["code","message"],"isRequired":true,"uniqueKey":"error","typeLabel":"object"},"request_id":{"type":"string","description":"Per-request id, also returned as the X-Request-Id header.","isRequired":true,"uniqueKey":"request_id","typeLabel":"string"}},"required":["success","error","request_id"],"uniqueKey":"","typeLabel":"object"},"examples":{"Example":{"title":"Example","value":{"success":false,"error":{"code":"invalid_request","message":"Invalid request body","details":{}},"request_id":"\u003cstring>"}}},"exampleType":"generated"}},"exampleType":"generated"},"b408dde4-967b-46df-b25a-a6b3e81f0a68":{"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":{"type":"object","properties":{"success":{"type":"boolean","enum":[false],"isRequired":true,"uniqueKey":"success","typeLabel":"enum\u003cboolean>"},"error":{"type":"object","properties":{"code":{"type":"string","description":"Stable, machine-readable error code.","example":"invalid_request","isRequired":true,"uniqueKey":"error.code","typeLabel":"string"},"message":{"type":"string","description":"Human-readable message (safe to surface).","example":"Invalid request body","isRequired":true,"uniqueKey":"error.message","typeLabel":"string"},"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.","uniqueKey":"error.details","typeLabel":"object"}},"required":["code","message"],"isRequired":true,"uniqueKey":"error","typeLabel":"object"},"request_id":{"type":"string","description":"Per-request id, also returned as the X-Request-Id header.","isRequired":true,"uniqueKey":"request_id","typeLabel":"string"}},"required":["success","error","request_id"],"uniqueKey":"","typeLabel":"object"},"examples":{"Example":{"title":"Example","value":{"success":false,"error":{"code":"invalid_request","message":"Invalid request body","details":{}},"request_id":"\u003cstring>"}}},"exampleType":"generated"}},"exampleType":"generated"},"ffc28878-3a92-42b1-b0dc-f8c5764fc90c":{"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":{"type":"object","properties":{"success":{"type":"boolean","enum":[false],"isRequired":true,"uniqueKey":"success","typeLabel":"enum\u003cboolean>"},"error":{"type":"object","properties":{"code":{"type":"string","description":"Stable, machine-readable error code.","example":"invalid_request","isRequired":true,"uniqueKey":"error.code","typeLabel":"string"},"message":{"type":"string","description":"Human-readable message (safe to surface).","example":"Invalid request body","isRequired":true,"uniqueKey":"error.message","typeLabel":"string"},"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.","uniqueKey":"error.details","typeLabel":"object"}},"required":["code","message"],"isRequired":true,"uniqueKey":"error","typeLabel":"object"},"request_id":{"type":"string","description":"Per-request id, also returned as the X-Request-Id header.","isRequired":true,"uniqueKey":"request_id","typeLabel":"string"}},"required":["success","error","request_id"],"uniqueKey":"","typeLabel":"object"},"examples":{"Example":{"title":"Example","value":{"success":false,"error":{"code":"invalid_request","message":"Invalid request body","details":{}},"request_id":"\u003cstring>"}}},"exampleType":"generated"}},"exampleType":"generated"},"dd2b0a20-202f-472b-a11d-a692fc6eefe8":{"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":{"type":"object","properties":{"success":{"type":"boolean","enum":[false],"isRequired":true,"uniqueKey":"success","typeLabel":"enum\u003cboolean>"},"error":{"type":"object","properties":{"code":{"type":"string","description":"Stable, machine-readable error code.","example":"invalid_request","isRequired":true,"uniqueKey":"error.code","typeLabel":"string"},"message":{"type":"string","description":"Human-readable message (safe to surface).","example":"Invalid request body","isRequired":true,"uniqueKey":"error.message","typeLabel":"string"},"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.","uniqueKey":"error.details","typeLabel":"object"}},"required":["code","message"],"isRequired":true,"uniqueKey":"error","typeLabel":"object"},"request_id":{"type":"string","description":"Per-request id, also returned as the X-Request-Id header.","isRequired":true,"uniqueKey":"request_id","typeLabel":"string"}},"required":["success","error","request_id"],"uniqueKey":"","typeLabel":"object"},"examples":{"Example":{"title":"Example","value":{"success":false,"error":{"code":"invalid_request","message":"Invalid request body","details":{}},"request_id":"\u003cstring>"}}},"exampleType":"generated"}},"exampleType":"generated"},"0aed04ec-7f14-45ab-acae-faa58a84ce49":{"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":{"type":"object","properties":{"success":{"type":"boolean","enum":[false],"isRequired":true,"uniqueKey":"success","typeLabel":"enum\u003cboolean>"},"error":{"type":"object","properties":{"code":{"type":"string","description":"Stable, machine-readable error code.","example":"invalid_request","isRequired":true,"uniqueKey":"error.code","typeLabel":"string"},"message":{"type":"string","description":"Human-readable message (safe to surface).","example":"Invalid request body","isRequired":true,"uniqueKey":"error.message","typeLabel":"string"},"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.","uniqueKey":"error.details","typeLabel":"object"}},"required":["code","message"],"isRequired":true,"uniqueKey":"error","typeLabel":"object"},"request_id":{"type":"string","description":"Per-request id, also returned as the X-Request-Id header.","isRequired":true,"uniqueKey":"request_id","typeLabel":"string"}},"required":["success","error","request_id"],"uniqueKey":"","typeLabel":"object"},"examples":{"Example":{"title":"Example","value":{"success":false,"error":{"code":"invalid_request","message":"Invalid request body","details":{}},"request_id":"\u003cstring>"}}},"exampleType":"generated"}},"exampleType":"generated"},"7817aaaf-fdeb-4791-9cd7-621c998a1cf0":{"description":"Unexpected server error (`server_error`).","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean","enum":[false],"isRequired":true,"uniqueKey":"success","typeLabel":"enum\u003cboolean>"},"error":{"type":"object","properties":{"code":{"type":"string","description":"Stable, machine-readable error code.","example":"invalid_request","isRequired":true,"uniqueKey":"error.code","typeLabel":"string"},"message":{"type":"string","description":"Human-readable message (safe to surface).","example":"Invalid request body","isRequired":true,"uniqueKey":"error.message","typeLabel":"string"},"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.","uniqueKey":"error.details","typeLabel":"object"}},"required":["code","message"],"isRequired":true,"uniqueKey":"error","typeLabel":"object"},"request_id":{"type":"string","description":"Per-request id, also returned as the X-Request-Id header.","isRequired":true,"uniqueKey":"request_id","typeLabel":"string"}},"required":["success","error","request_id"],"uniqueKey":"","typeLabel":"object"},"examples":{"Example":{"title":"Example","value":{"success":false,"error":{"code":"invalid_request","message":"Invalid request body","details":{}},"request_id":"\u003cstring>"}}},"exampleType":"generated"}},"exampleType":"generated"},"8e6d5dbd-1cb0-4de5-b850-919963923f27":{"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":{"type":"object","properties":{"success":{"type":"boolean","enum":[false],"isRequired":true,"uniqueKey":"success","typeLabel":"enum\u003cboolean>"},"error":{"type":"object","properties":{"code":{"type":"string","description":"Stable, machine-readable error code.","example":"invalid_request","isRequired":true,"uniqueKey":"error.code","typeLabel":"string"},"message":{"type":"string","description":"Human-readable message (safe to surface).","example":"Invalid request body","isRequired":true,"uniqueKey":"error.message","typeLabel":"string"},"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.","uniqueKey":"error.details","typeLabel":"object"}},"required":["code","message"],"isRequired":true,"uniqueKey":"error","typeLabel":"object"},"request_id":{"type":"string","description":"Per-request id, also returned as the X-Request-Id header.","isRequired":true,"uniqueKey":"request_id","typeLabel":"string"}},"required":["success","error","request_id"],"uniqueKey":"","typeLabel":"object"},"examples":{"Example":{"title":"Example","value":{"success":false,"error":{"code":"invalid_request","message":"Invalid request body","details":{}},"request_id":"\u003cstring>"}}},"exampleType":"generated"}},"exampleType":"generated"},"5f8932b1-77ea-4e2f-a1f6-1483b4c0176f":{"description":"Temporarily unavailable — try again (`credit_check_failed`, `plan_build_unavailable`, `plans_unavailable`).","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean","enum":[false],"isRequired":true,"uniqueKey":"success","typeLabel":"enum\u003cboolean>"},"error":{"type":"object","properties":{"code":{"type":"string","description":"Stable, machine-readable error code.","example":"invalid_request","isRequired":true,"uniqueKey":"error.code","typeLabel":"string"},"message":{"type":"string","description":"Human-readable message (safe to surface).","example":"Invalid request body","isRequired":true,"uniqueKey":"error.message","typeLabel":"string"},"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.","uniqueKey":"error.details","typeLabel":"object"}},"required":["code","message"],"isRequired":true,"uniqueKey":"error","typeLabel":"object"},"request_id":{"type":"string","description":"Per-request id, also returned as the X-Request-Id header.","isRequired":true,"uniqueKey":"request_id","typeLabel":"string"}},"required":["success","error","request_id"],"uniqueKey":"","typeLabel":"object"},"examples":{"Example":{"title":"Example","value":{"success":false,"error":{"code":"invalid_request","message":"Invalid request body","details":{}},"request_id":"\u003cstring>"}}},"exampleType":"generated"}},"exampleType":"generated"}},"security":{"1f0a3921-581d-4579-9edc-6750446c0dbf":{"ApiKeyAuth":{"type":"http","scheme":"bearer","bearerFormat":"API key","description":"Project API key issued in Settings → API keys. Send it as `Authorization: Bearer pk_live_…`.","scopes":[],"schemeName":"ApiKeyAuth"}}},"servers":{"2f61f958-73d8-4f9e-a417-8b9b7e2662ed":{"url":"https://api.paigeme.dev","description":"Production"}},"processedSecurityOptions":[{"schemes":[{"scheme":{"type":"http","scheme":"bearer","bearerFormat":"API key","description":"Project API key issued in Settings → API keys. Send it as `Authorization: Bearer pk_live_…`.","scopes":[],"schemeName":"ApiKeyAuth"},"schema":{"title":"Bearer Auth","type":"string","isRequired":true,"description":"Project API key issued in Settings → API keys. Send it as `Authorization: Bearer pk_live_…`.","format":"bearer","typeLabel":"string\u003cbearer>","deprecated":false},"schemeName":"ApiKeyAuth","name":"Authorization"}],"title":"ApiKeyAuth"}]},"originalFileLocation":"api-reference/openapi.json"},"subdomain":"greenpages","siteName":"paige","title":"Author or edit bot code via the code agent - paige","navMaps":{"firstHrefInVersion":{},"firstHrefInLanguage":{}},"lastModified":"2026-11-20T16:58:05.258Z","originalFileLocation":"api-reference/endpoints/build/author-or-edit-bot-code-via-the-code-agent.mdx"},"headHtml":"\u003cscript data-mint-head>(function(){var d=document.documentElement,p=null;if(!p){try{p=localStorage.getItem(\"isDarkMode\")}catch(e){}if(p==='true')p='dark';else if(p==='false')p='light';if(p!=='light'\u0026\u0026p!=='dark'\u0026\u0026p!=='system')p=\"system\"}var r=p==='system'?(matchMedia(\"(prefers-color-scheme: dark)\").matches?'dark':'light'):p;d.classList.remove(r==='dark'?'light':'dark');d.classList.add(r);d.setAttribute(\"data-theme-preference\",p)})();\u003c/script>\u003cmeta data-mint-head name=\"description\" content=\"Runs Paige\u0026#x27;s code agent (its system prompt, scaffold + connector awareness, and guardrails) in a bounded headless loop to write/edit the bot\u0026#x27;s code from a natural-language instruction — the higher-quality counterpart to PUT /v1/files/{path}. Flow JSON is rejected (use the flow endpoints). Frozen/injected/auto-generated files (e.g. services/messages.js, config/mediaAssets.js, package.json, .paige/) are refused (the validated test scenarios save is the one exception to .paige/), while the agent still authors the bot wiring it owns (routes/*, app.js, config/db.js). Consumes credits; rejected with 402 insufficient_credits when out of balance. A truncated or failed agent run returns 502 build_failed. Projects on the new AI engine (v2) answer with a status (GRE-1040). The request runs on the same engine as the dashboard chat, with nobody watching: it is routed (a question about the bot is answered, a change is built, a big change is planned first; every one of these is charged at its real cost), it may change WhatsApp Flows too when the key also holds flows:write (and read templates, broadcasts or conversation states only with templates:read / broadcasts:read / conversations:read; it never sends, never tags and never reads contacts — use those endpoints). Each credential (API key, or MCP connection) has its OWN build conversation: a build sees that credential\u0026#x27;s earlier builds, never the dashboard chat or another key\u0026#x27;s builds, and it never appears in the dashboard chat. One build per project at a time: a second POST /v1/code (or a plan approval) while a build is running on the project — or while the key owner has a chat turn running in the dashboard — answers 409 build_in_progress; retry when it has finished. A build that reaches its step or token limit stops there (it is never resumed automatically); send another call to carry on. Read status before anything else: - completed — done; summary and files_changed as before (cancelled: true when the run hit its time limit or you disconnected: what it wrote is kept). - needs_confirmation — a big change was PLANNED and nothing was built. A simple request for a new feature that collects structured input (a form, a booking, a menu to order from) can land here too, because such a feature can be sent to planning first so that a WhatsApp Flow is chosen where one fits: handle this status on every build. plan holds the plan (goal, approach, steps, risks, complexity, what it touches) and plan_id its id. Show it to your user, then call POST /v1/code/plans/{plan_id}/decision (confirm_path) with approve, reject or revise. - needs_input — Paige needs an answer before it can work; question is what it asked, and options (2 to 4, each a label and an optional description) when it asked one multiple-choice question: answer with one label, or with your own words when allow_other is true. When it asked several things at once, questions has them with their choices (and question lists them all): answer every one in the same message. Send the answer as the instruction of another POST /v1/code call: the question is part of the conversation that call reads. Projects on the current engine never send status, engine, turn_id or the fields after them: their response is exactly the three fields it has always been. Required scope: code:write\">\u003cmeta data-mint-head name=\"application-name\" content=\"paige\">\u003cmeta data-mint-head name=\"generator\" content=\"Mintlify\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/greenpages/x5PgeW5NAYRfgbaO/_generated/favicon/android-chrome-192x192.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"apple-touch-icon\" type=\"image/png\" sizes=\"180x180\" href=\"/mintlify-assets/_mintlify/favicons/greenpages/x5PgeW5NAYRfgbaO/_generated/favicon/apple-touch-icon.png\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/greenpages/x5PgeW5NAYRfgbaO/_generated/favicon/favicon-16x16.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/greenpages/x5PgeW5NAYRfgbaO/_generated/favicon/favicon-32x32.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/greenpages/x5PgeW5NAYRfgbaO/_generated/favicon/favicon.ico\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/greenpages/x5PgeW5NAYRfgbaO/_generated/favicon-dark/android-chrome-192x192.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/greenpages/x5PgeW5NAYRfgbaO/_generated/favicon-dark/favicon-16x16.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/greenpages/x5PgeW5NAYRfgbaO/_generated/favicon-dark/favicon-32x32.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/greenpages/x5PgeW5NAYRfgbaO/_generated/favicon-dark/favicon.ico\" media=\"(prefers-color-scheme: dark)\">\u003cmeta data-mint-head property=\"og:title\" content=\"Author or edit bot code via the code agent - paige\">\u003cmeta data-mint-head property=\"og:description\" content=\"Runs Paige\u0026#x27;s code agent (its system prompt, scaffold + connector awareness, and guardrails) in a bounded headless loop to write/edit the bot\u0026#x27;s code from a natural-language instruction — the higher-quality counterpart to PUT /v1/files/{path}. Flow JSON is rejected (use the flow endpoints). Frozen/injected/auto-generated files (e.g. services/messages.js, config/mediaAssets.js, package.json, .paige/) are refused (the validated test scenarios save is the one exception to .paige/), while the agent still authors the bot wiring it owns (routes/*, app.js, config/db.js). Consumes credits; rejected with 402 insufficient_credits when out of balance. A truncated or failed agent run returns 502 build_failed. Projects on the new AI engine (v2) answer with a status (GRE-1040). The request runs on the same engine as the dashboard chat, with nobody watching: it is routed (a question about the bot is answered, a change is built, a big change is planned first; every one of these is charged at its real cost), it may change WhatsApp Flows too when the key also holds flows:write (and read templates, broadcasts or conversation states only with templates:read / broadcasts:read / conversations:read; it never sends, never tags and never reads contacts — use those endpoints). Each credential (API key, or MCP connection) has its OWN build conversation: a build sees that credential\u0026#x27;s earlier builds, never the dashboard chat or another key\u0026#x27;s builds, and it never appears in the dashboard chat. One build per project at a time: a second POST /v1/code (or a plan approval) while a build is running on the project — or while the key owner has a chat turn running in the dashboard — answers 409 build_in_progress; retry when it has finished. A build that reaches its step or token limit stops there (it is never resumed automatically); send another call to carry on. Read status before anything else: - completed — done; summary and files_changed as before (cancelled: true when the run hit its time limit or you disconnected: what it wrote is kept). - needs_confirmation — a big change was PLANNED and nothing was built. A simple request for a new feature that collects structured input (a form, a booking, a menu to order from) can land here too, because such a feature can be sent to planning first so that a WhatsApp Flow is chosen where one fits: handle this status on every build. plan holds the plan (goal, approach, steps, risks, complexity, what it touches) and plan_id its id. Show it to your user, then call POST /v1/code/plans/{plan_id}/decision (confirm_path) with approve, reject or revise. - needs_input — Paige needs an answer before it can work; question is what it asked, and options (2 to 4, each a label and an optional description) when it asked one multiple-choice question: answer with one label, or with your own words when allow_other is true. When it asked several things at once, questions has them with their choices (and question lists them all): answer every one in the same message. Send the answer as the instruction of another POST /v1/code call: the question is part of the conversation that call reads. Projects on the current engine never send status, engine, turn_id or the fields after them: their response is exactly the three fields it has always been. Required scope: code:write\">\u003cmeta data-mint-head property=\"og:site_name\" content=\"paige\">\u003cmeta data-mint-head property=\"og:url\" content=\"https://howto.paigeme.dev/api-reference/endpoints/build/author-or-edit-bot-code-via-the-code-agent\">\u003cmeta data-mint-head property=\"og:type\" content=\"website\">\u003cmeta data-mint-head property=\"og:image\" content=\"https://greenpages.mintlify.site/_mintlify/api/og/v2?division=Build\u0026amp;title=Author+or+edit+bot+code+via+the+code+agent\u0026amp;description=Runs+Paige%27s+code+agent+%28its+system+prompt%2C+scaffold+%2B+connector+awareness%2C+and+guardrails%29+in+a+bounded+headless+loop+to+write%2Fedit+the+bot%27s+code+from+a+natur\u0026amp;theme=c4f8b57fd839e0b00425ea76\u0026amp;signature=df72ee3a1a54acd3ac1a31b1b8e1bf9adf81459d37dddba3aaf80f4103c9017d\">\u003cmeta data-mint-head property=\"og:image:width\" content=\"1200\">\u003cmeta data-mint-head property=\"og:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"twitter:card\" content=\"summary_large_image\">\u003cmeta data-mint-head name=\"twitter:title\" content=\"Author or edit bot code via the code agent - paige\">\u003cmeta data-mint-head name=\"twitter:description\" content=\"Runs Paige\u0026#x27;s code agent (its system prompt, scaffold + connector awareness, and guardrails) in a bounded headless loop to write/edit the bot\u0026#x27;s code from a natural-language instruction — the higher-quality counterpart to PUT /v1/files/{path}. Flow JSON is rejected (use the flow endpoints). Frozen/injected/auto-generated files (e.g. services/messages.js, config/mediaAssets.js, package.json, .paige/) are refused (the validated test scenarios save is the one exception to .paige/), while the agent still authors the bot wiring it owns (routes/*, app.js, config/db.js). Consumes credits; rejected with 402 insufficient_credits when out of balance. A truncated or failed agent run returns 502 build_failed. Projects on the new AI engine (v2) answer with a status (GRE-1040). The request runs on the same engine as the dashboard chat, with nobody watching: it is routed (a question about the bot is answered, a change is built, a big change is planned first; every one of these is charged at its real cost), it may change WhatsApp Flows too when the key also holds flows:write (and read templates, broadcasts or conversation states only with templates:read / broadcasts:read / conversations:read; it never sends, never tags and never reads contacts — use those endpoints). Each credential (API key, or MCP connection) has its OWN build conversation: a build sees that credential\u0026#x27;s earlier builds, never the dashboard chat or another key\u0026#x27;s builds, and it never appears in the dashboard chat. One build per project at a time: a second POST /v1/code (or a plan approval) while a build is running on the project — or while the key owner has a chat turn running in the dashboard — answers 409 build_in_progress; retry when it has finished. A build that reaches its step or token limit stops there (it is never resumed automatically); send another call to carry on. Read status before anything else: - completed — done; summary and files_changed as before (cancelled: true when the run hit its time limit or you disconnected: what it wrote is kept). - needs_confirmation — a big change was PLANNED and nothing was built. A simple request for a new feature that collects structured input (a form, a booking, a menu to order from) can land here too, because such a feature can be sent to planning first so that a WhatsApp Flow is chosen where one fits: handle this status on every build. plan holds the plan (goal, approach, steps, risks, complexity, what it touches) and plan_id its id. Show it to your user, then call POST /v1/code/plans/{plan_id}/decision (confirm_path) with approve, reject or revise. - needs_input — Paige needs an answer before it can work; question is what it asked, and options (2 to 4, each a label and an optional description) when it asked one multiple-choice question: answer with one label, or with your own words when allow_other is true. When it asked several things at once, questions has them with their choices (and question lists them all): answer every one in the same message. Send the answer as the instruction of another POST /v1/code call: the question is part of the conversation that call reads. Projects on the current engine never send status, engine, turn_id or the fields after them: their response is exactly the three fields it has always been. Required scope: code:write\">\u003cmeta data-mint-head name=\"twitter:image\" content=\"https://greenpages.mintlify.site/_mintlify/api/og/v2?division=Build\u0026amp;title=Author+or+edit+bot+code+via+the+code+agent\u0026amp;description=Runs+Paige%27s+code+agent+%28its+system+prompt%2C+scaffold+%2B+connector+awareness%2C+and+guardrails%29+in+a+bounded+headless+loop+to+write%2Fedit+the+bot%27s+code+from+a+natur\u0026amp;theme=c4f8b57fd839e0b00425ea76\u0026amp;signature=df72ee3a1a54acd3ac1a31b1b8e1bf9adf81459d37dddba3aaf80f4103c9017d\">\u003cmeta data-mint-head name=\"twitter:image:width\" content=\"1200\">\u003cmeta data-mint-head name=\"twitter:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"msapplication-config\" content=\"/mintlify-assets/_mintlify/favicons/greenpages/x5PgeW5NAYRfgbaO/_generated/favicon/browserconfig.xml\">\u003cmeta data-mint-head name=\"apple-mobile-web-app-title\" content=\"paige\">\u003cmeta data-mint-head name=\"msapplication-TileColor\" content=\"#81D741\">\u003clink data-mint-head rel=\"canonical\" href=\"https://howto.paigeme.dev/api-reference/endpoints/build/author-or-edit-bot-code-via-the-code-agent\">\u003clink data-mint-head rel=\"alternate\" type=\"application/xml\" href=\"/sitemap.xml\">\u003clink data-mint-head rel=\"alternate\" type=\"text/markdown\" href=\"/api-reference/endpoints/build/author-or-edit-bot-code-via-the-code-agent.md\">\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https://howto.paigeme.dev/#organization\",\"name\":\"paige\",\"url\":\"https://howto.paigeme.dev\",\"logo\":{\"@type\":\"ImageObject\",\"url\":\"https://mintcdn.com/greenpages/SGZewfX5ti1H1LmZ/logo/green-pages-logo.png?fit=max\u0026auto=format\u0026n=SGZewfX5ti1H1LmZ\u0026q=85\u0026s=9b5fbf18d11676f6513a94ed3366cb7f\"}},{\"@type\":\"WebSite\",\"@id\":\"https://howto.paigeme.dev#website\",\"name\":\"paige\",\"url\":\"https://howto.paigeme.dev\",\"publisher\":{\"@id\":\"https://howto.paigeme.dev/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https://howto.paigeme.dev/api-reference/endpoints/build/author-or-edit-bot-code-via-the-code-agent#webpage\",\"url\":\"https://howto.paigeme.dev/api-reference/endpoints/build/author-or-edit-bot-code-via-the-code-agent\",\"name\":\"Author or edit bot code via the code agent\",\"description\":\"Runs Paige's code agent (its system prompt, scaffold + connector awareness, and guardrails) in a bounded headless loop to write/edit the bot's code from a natural-language instruction — the higher-quality counterpart to PUT /v1/files/{path}. Flow JSON is rejected (use the flow endpoints). Frozen/injected/auto-generated files (e.g. services/messages.js, config/mediaAssets.js, package.json, .paige/) are refused (the validated test scenarios save is the one exception to .paige/), while the agent still authors the bot wiring it owns (routes/*, app.js, config/db.js). Consumes credits; rejected with 402 insufficient_credits when out of balance. A truncated or failed agent run returns 502 build_failed. Projects on the new AI engine (v2) answer with a status (GRE-1040). The request runs on the same engine as the dashboard chat, with nobody watching: it is routed (a question about the bot is answered, a change is built, a big change is planned first; every one of these is charged at its real cost), it may change WhatsApp Flows too when the key also holds flows:write (and read templates, broadcasts or conversation states only with templates:read / broadcasts:read / conversations:read; it never sends, never tags and never reads contacts — use those endpoints). Each credential (API key, or MCP connection) has its OWN build conversation: a build sees that credential's earlier builds, never the dashboard chat or another key's builds, and it never appears in the dashboard chat. One build per project at a time: a second POST /v1/code (or a plan approval) while a build is running on the project — or while the key owner has a chat turn running in the dashboard — answers 409 build_in_progress; retry when it has finished. A build that reaches its step or token limit stops there (it is never resumed automatically); send another call to carry on. Read status before anything else: - completed — done; summary and files_changed as before (cancelled: true when the run hit its time limit or you disconnected: what it wrote is kept). - needs_confirmation — a big change was PLANNED and nothing was built. A simple request for a new feature that collects structured input (a form, a booking, a menu to order from) can land here too, because such a feature can be sent to planning first so that a WhatsApp Flow is chosen where one fits: handle this status on every build. plan holds the plan (goal, approach, steps, risks, complexity, what it touches) and plan_id its id. Show it to your user, then call POST /v1/code/plans/{plan_id}/decision (confirm_path) with approve, reject or revise. - needs_input — Paige needs an answer before it can work; question is what it asked, and options (2 to 4, each a label and an optional description) when it asked one multiple-choice question: answer with one label, or with your own words when allow_other is true. When it asked several things at once, questions has them with their choices (and question lists them all): answer every one in the same message. Send the answer as the instruction of another POST /v1/code call: the question is part of the conversation that call reads. Projects on the current engine never send status, engine, turn_id or the fields after them: their response is exactly the three fields it has always been. Required scope: code:write\",\"dateModified\":\"2026-11-20T16:58:05.258Z\",\"isPartOf\":{\"@id\":\"https://howto.paigeme.dev#website\"},\"breadcrumb\":{\"@id\":\"https://howto.paigeme.dev/api-reference/endpoints/build/author-or-edit-bot-code-via-the-code-agent#breadcrumb\"}},{\"@type\":\"BreadcrumbList\",\"@id\":\"https://howto.paigeme.dev/api-reference/endpoints/build/author-or-edit-bot-code-via-the-code-agent#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Endpoints\",\"item\":\"https://howto.paigeme.dev/api-reference/endpoints/meta/the-openapi-31-spec-for-this-api-no-auth\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Build\",\"item\":\"https://howto.paigeme.dev/api-reference/endpoints/build/list-the-bot-code-files\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Author or edit bot code via the code agent\",\"item\":\"https://howto.paigeme.dev/api-reference/endpoints/build/author-or-edit-bot-code-via-the-code-agent\"}]},{\"@type\":[\"TechArticle\",\"APIReference\"],\"@id\":\"https://howto.paigeme.dev/api-reference/endpoints/build/author-or-edit-bot-code-via-the-code-agent#apireference\",\"headline\":\"Author or edit bot code via the code agent\",\"name\":\"Author or edit bot code via the code agent\",\"description\":\"Runs Paige's code agent (its system prompt, scaffold + connector awareness, and guardrails) in a bounded headless loop to write/edit the bot's code from a natural-language instruction — the higher-quality counterpart to PUT /v1/files/{path}. Flow JSON is rejected (use the flow endpoints). Frozen/injected/auto-generated files (e.g. services/messages.js, config/mediaAssets.js, package.json, .paige/) are refused (the validated test scenarios save is the one exception to .paige/), while the agent still authors the bot wiring it owns (routes/*, app.js, config/db.js). Consumes credits; rejected with 402 insufficient_credits when out of balance. A truncated or failed agent run returns 502 build_failed. Projects on the new AI engine (v2) answer with a status (GRE-1040). The request runs on the same engine as the dashboard chat, with nobody watching: it is routed (a question about the bot is answered, a change is built, a big change is planned first; every one of these is charged at its real cost), it may change WhatsApp Flows too when the key also holds flows:write (and read templates, broadcasts or conversation states only with templates:read / broadcasts:read / conversations:read; it never sends, never tags and never reads contacts — use those endpoints). Each credential (API key, or MCP connection) has its OWN build conversation: a build sees that credential's earlier builds, never the dashboard chat or another key's builds, and it never appears in the dashboard chat. One build per project at a time: a second POST /v1/code (or a plan approval) while a build is running on the project — or while the key owner has a chat turn running in the dashboard — answers 409 build_in_progress; retry when it has finished. A build that reaches its step or token limit stops there (it is never resumed automatically); send another call to carry on. Read status before anything else: - completed — done; summary and files_changed as before (cancelled: true when the run hit its time limit or you disconnected: what it wrote is kept). - needs_confirmation — a big change was PLANNED and nothing was built. A simple request for a new feature that collects structured input (a form, a booking, a menu to order from) can land here too, because such a feature can be sent to planning first so that a WhatsApp Flow is chosen where one fits: handle this status on every build. plan holds the plan (goal, approach, steps, risks, complexity, what it touches) and plan_id its id. Show it to your user, then call POST /v1/code/plans/{plan_id}/decision (confirm_path) with approve, reject or revise. - needs_input — Paige needs an answer before it can work; question is what it asked, and options (2 to 4, each a label and an optional description) when it asked one multiple-choice question: answer with one label, or with your own words when allow_other is true. When it asked several things at once, questions has them with their choices (and question lists them all): answer every one in the same message. Send the answer as the instruction of another POST /v1/code call: the question is part of the conversation that call reads. Projects on the current engine never send status, engine, turn_id or the fields after them: their response is exactly the three fields it has always been. Required scope: code:write\",\"url\":\"https://howto.paigeme.dev/api-reference/endpoints/build/author-or-edit-bot-code-via-the-code-agent\",\"mainEntityOfPage\":{\"@id\":\"https://howto.paigeme.dev/api-reference/endpoints/build/author-or-edit-bot-code-via-the-code-agent#webpage\"},\"dateModified\":\"2026-11-20T16:58:05.258Z\",\"publisher\":{\"@id\":\"https://howto.paigeme.dev/#organization\"},\"isPartOf\":{\"@id\":\"https://howto.paigeme.dev#website\"}}]}\u003c/script>\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@type\":\"WebSite\",\"name\":\"paige\",\"publisher\":{\"@type\":\"Organization\",\"name\":\"paige\"},\"provider\":{\"@type\":\"Organization\",\"name\":\"Mintlify\",\"url\":\"https://mintlify.com\"}}\u003c/script>","agentPointerHref":"/api-reference/endpoints/build/author-or-edit-bot-code-via-the-code-agent.md","siteName":"paige","nav":{"global":null,"tabs":[{"tab":"Introduction","icon":"rocket","pages":[{"title":"Introduction","href":""}]},{"tab":"Learn","icon":"graduation-cap","pages":[{"title":"Learn","href":"/learn/foundations/what-is-an-llm"}]},{"tab":"Features","icon":"sparkles","pages":[{"title":"Features","href":"/agents/overview"}]},{"tab":"API","icon":"code","groups":[{"group":"Getting started","pages":[{"title":"The Paige API","sidebarTitle":"Introduction","href":"/api-reference/introduction"},{"title":"Authentication","href":"/api-reference/authentication"},{"title":"Scopes","href":"/api-reference/scopes"},{"title":"API conventions","sidebarTitle":"Conventions","href":"/api-reference/conventions"},{"title":"Errors","href":"/api-reference/errors"},{"title":"Rate limits","href":"/api-reference/rate-limits"},{"title":"Idempotency","href":"/api-reference/idempotency"},{"title":"Webhooks","href":"/api-reference/webhooks"}]},{"group":"Endpoints","pages":[{"group":"Meta","pages":[{"title":"The OpenAPI 3.1 spec for this API (no auth)","deprecated":null,"version":null,"openapi":"/api-reference/openapi.json get /v1/openapi.json","href":"/api-reference/endpoints/meta/the-openapi-31-spec-for-this-api-no-auth"},{"title":"The pasteable Paige integration agent skill (no auth)","deprecated":null,"version":null,"openapi":"/api-reference/openapi.json get /v1/skill.md","href":"/api-reference/endpoints/meta/the-pasteable-paige-integration-agent-skill-no-auth"},{"title":"Smoke check, echoing the resolved project and scopes","deprecated":null,"version":null,"openapi":"/api-reference/openapi.json get /v1/ping","href":"/api-reference/endpoints/meta/smoke-check-echoing-the-resolved-project-and-scopes"},{"title":"The projects this credential may act on","deprecated":null,"version":null,"openapi":"/api-reference/openapi.json get /v1/projects","href":"/api-reference/endpoints/meta/the-projects-this-credential-may-act-on"}]},{"group":"Messages","pages":[{"title":"Send a message (session, template, or interactive)","deprecated":null,"version":null,"openapi":"/api-reference/openapi.json post /v1/messages","href":"/api-reference/endpoints/messages/send-a-message-session-template-or-interactive"},{"title":"Delivery status for one message","deprecated":null,"version":null,"openapi":"/api-reference/openapi.json get /v1/messages/{id}","href":"/api-reference/endpoints/messages/delivery-status-for-one-message"},{"title":"Retrieve the media attached to a message","deprecated":null,"version":null,"openapi":"/api-reference/openapi.json get /v1/messages/{id}/media","href":"/api-reference/endpoints/messages/retrieve-the-media-attached-to-a-message"}]},{"group":"Templates","pages":[{"title":"List message templates + approval status","deprecated":null,"version":null,"openapi":"/api-reference/openapi.json get /v1/templates","href":"/api-reference/endpoints/templates/list-message-templates-+-approval-status"},{"title":"Create a WhatsApp message template","deprecated":null,"version":null,"openapi":"/api-reference/openapi.json post /v1/templates","href":"/api-reference/endpoints/templates/create-a-whatsapp-message-template"},{"title":"Upload the sample file a media header needs","deprecated":null,"version":null,"openapi":"/api-reference/openapi.json post /v1/templates/header-sample","href":"/api-reference/endpoints/templates/upload-the-sample-file-a-media-header-needs"},{"title":"Delete a template (all localizations, or a single language)","deprecated":null,"version":null,"openapi":"/api-reference/openapi.json delete /v1/templates/{name}","href":"/api-reference/endpoints/templates/delete-a-template-all-localizations-or-a-single-language"}]},{"group":"Conversations","pages":[{"title":"List conversations (state + archive filter, keyset cursor)","deprecated":null,"version":null,"openapi":"/api-reference/openapi.json get /v1/conversations","href":"/api-reference/endpoints/conversations/list-conversations-state-+-archive-filter-keyset-cursor"},{"title":"Messages in a conversation (keyset cursor)","deprecated":null,"version":null,"openapi":"/api-reference/openapi.json get /v1/conversations/{id}/messages","href":"/api-reference/endpoints/conversations/messages-in-a-conversation-keyset-cursor"},{"title":"Set a conversation's state (validated against known states)","deprecated":null,"version":null,"openapi":"/api-reference/openapi.json patch /v1/conversations/{id}","href":"/api-reference/endpoints/conversations/set-a-conversations-state-validated-against-known-states"}]},{"group":"Contacts","pages":[{"title":"All messages for a contact (phone or BSUID)","deprecated":null,"version":null,"openapi":"/api-reference/openapi.json get /v1/contacts/{id}/messages","href":"/api-reference/endpoints/contacts/all-messages-for-a-contact-phone-or-bsuid"},{"title":"Update a contact name, tags or custom attributes","deprecated":null,"version":null,"openapi":"/api-reference/openapi.json patch /v1/contacts/{id}","href":"/api-reference/endpoints/contacts/update-a-contact-name-tags-or-custom-attributes"},{"title":"Archive a contact's chat","deprecated":null,"version":null,"openapi":"/api-reference/openapi.json post /v1/contacts/{id}/archive","href":"/api-reference/endpoints/contacts/archive-a-contacts-chat"},{"title":"Bring a contact's chat back from Archived","deprecated":null,"version":null,"openapi":"/api-reference/openapi.json post /v1/contacts/{id}/unarchive","href":"/api-reference/endpoints/contacts/bring-a-contacts-chat-back-from-archived"}]},{"group":"Build","pages":[{"title":"List the bot code files","deprecated":null,"version":null,"openapi":"/api-reference/openapi.json get /v1/files","href":"/api-reference/endpoints/build/list-the-bot-code-files"},{"title":"Read one bot code file","deprecated":null,"version":null,"openapi":"/api-reference/openapi.json get /v1/files/{path}","href":"/api-reference/endpoints/build/read-one-bot-code-file"},{"title":"Create or edit a file via the code agent","description":"**Send exactly one of two forms** — a whole-file write (`content`) **or** one exact replacement (`old_string` **and** `new_string`, both required together). The choice is enforced by a cross-field rule the schema below cannot express: sending neither, or both, is `400 invalid_request`. An `old_string` that matches zero or more than one location in the file is also rejected, so make it long enough to be unique. Flow JSON is rejected — use the flow endpoints. Platform-critical / injected / auto-generated files (e.g. `routes/whatsapp_webhook.js`, `app.js`, `config/db.js`, `services/messages.js`, `config/mediaAssets.js`, matched across both flat and `src/` layouts) are rejected with `403 protected_file`; the file is left unchanged. Reads (`GET /v1/files`, `GET /v1/files/{path}`) are NOT restricted.\n\n**Required scope:** `code:write`","deprecated":null,"version":null,"openapi":"/api-reference/openapi.json put /v1/files/{path}","href":"/api-reference/endpoints/build/create-or-edit-a-file-via-the-code-agent"},{"title":"Author or edit bot code via the code agent","deprecated":null,"version":null,"openapi":"/api-reference/openapi.json post /v1/code","href":"/api-reference/endpoints/build/author-or-edit-bot-code-via-the-code-agent"},{"title":"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`.\n\n- `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.\n- `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\"`.\n\nRepeating 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`.\n\n**Required scope:** `code:write`","deprecated":null,"version":null,"openapi":"/api-reference/openapi.json post /v1/code/plans/{id}/decision","href":"/api-reference/endpoints/build/confirm-reject-or-revise-a-build-plan"},{"title":"Promote dev to production","deprecated":null,"version":null,"openapi":"/api-reference/openapi.json post /v1/deploy","href":"/api-reference/endpoints/build/promote-dev-to-production"},{"title":"List the project's WhatsApp Flows","deprecated":null,"version":null,"openapi":"/api-reference/openapi.json get /v1/flows","href":"/api-reference/endpoints/build/list-the-projects-whatsapp-flows"},{"title":"Generate a new WhatsApp Flow via the flows sub-agent","deprecated":null,"version":null,"openapi":"/api-reference/openapi.json post /v1/flows","href":"/api-reference/endpoints/build/generate-a-new-whatsapp-flow-via-the-flows-sub-agent"},{"title":"Read one flow, including its JSON definition","deprecated":null,"version":null,"openapi":"/api-reference/openapi.json get /v1/flows/{id}","href":"/api-reference/endpoints/build/read-one-flow-including-its-json-definition"},{"title":"Update a flow via the flows sub-agent","deprecated":null,"version":null,"openapi":"/api-reference/openapi.json patch /v1/flows/{id}","href":"/api-reference/endpoints/build/update-a-flow-via-the-flows-sub-agent"}]},{"group":"Chat","pages":[{"title":"Send Paige a message and get its reply","deprecated":null,"version":null,"openapi":"/api-reference/openapi.json post /v1/chat","href":"/api-reference/endpoints/chat/send-paige-a-message-and-get-its-reply"}]},{"group":"Broadcasts","pages":[{"title":"Create + save a reusable audience segment","deprecated":null,"version":null,"openapi":"/api-reference/openapi.json post /v1/segments","href":"/api-reference/endpoints/broadcasts/create-+-save-a-reusable-audience-segment"},{"title":"Live contact count for a filter (no save)","deprecated":null,"version":null,"openapi":"/api-reference/openapi.json post /v1/segments/preview","href":"/api-reference/endpoints/broadcasts/live-contact-count-for-a-filter-no-save"},{"title":"Assemble a broadcast for approval","deprecated":null,"version":null,"openapi":"/api-reference/openapi.json post /v1/broadcasts","href":"/api-reference/endpoints/broadcasts/assemble-a-broadcast-for-approval"},{"title":"Broadcast status + rollup counts","deprecated":null,"version":null,"openapi":"/api-reference/openapi.json get /v1/broadcasts/{id}","href":"/api-reference/endpoints/broadcasts/broadcast-status-+-rollup-counts"},{"title":"Per-recipient drill-down","deprecated":null,"version":null,"openapi":"/api-reference/openapi.json get /v1/broadcasts/{id}/recipients","href":"/api-reference/endpoints/broadcasts/per-recipient-drill-down"}]},{"group":"Tables","pages":[{"title":"List the project's own database tables","deprecated":null,"version":null,"openapi":"/api-reference/openapi.json get /v1/tables","href":"/api-reference/endpoints/tables/list-the-projects-own-database-tables"},{"title":"Read one table's columns, types and primary key","deprecated":null,"version":null,"openapi":"/api-reference/openapi.json get /v1/tables/{table}/schema","href":"/api-reference/endpoints/tables/read-one-tables-columns-types-and-primary-key"},{"title":"Read rows from one of your tables","deprecated":null,"version":null,"openapi":"/api-reference/openapi.json get /v1/tables/{table}/rows","href":"/api-reference/endpoints/tables/read-rows-from-one-of-your-tables"},{"title":"Insert rows into one of your tables","deprecated":null,"version":null,"openapi":"/api-reference/openapi.json post /v1/tables/{table}/rows","href":"/api-reference/endpoints/tables/insert-rows-into-one-of-your-tables"},{"title":"Delete the rows matching a filter","deprecated":null,"version":null,"openapi":"/api-reference/openapi.json delete /v1/tables/{table}/rows","href":"/api-reference/endpoints/tables/delete-the-rows-matching-a-filter"},{"title":"Update the rows matching a filter","deprecated":null,"version":null,"openapi":"/api-reference/openapi.json patch /v1/tables/{table}/rows","href":"/api-reference/endpoints/tables/update-the-rows-matching-a-filter"}]},{"group":"Media","pages":[{"title":"List the project's media assets","deprecated":null,"version":null,"openapi":"/api-reference/openapi.json get /v1/media","href":"/api-reference/endpoints/media/list-the-projects-media-assets"},{"title":"Upload a media asset","deprecated":null,"version":null,"openapi":"/api-reference/openapi.json post /v1/media","href":"/api-reference/endpoints/media/upload-a-media-asset"},{"title":"Retrieve one media asset and a signed URL","deprecated":null,"version":null,"openapi":"/api-reference/openapi.json get /v1/media/{slug}","href":"/api-reference/endpoints/media/retrieve-one-media-asset-and-a-signed-url"},{"title":"Delete a media asset","deprecated":null,"version":null,"openapi":"/api-reference/openapi.json delete /v1/media/{slug}","href":"/api-reference/endpoints/media/delete-a-media-asset"}]},{"group":"Webhooks","pages":[{"title":"List webhook registrations (never the secret)","deprecated":null,"version":null,"openapi":"/api-reference/openapi.json get /v1/webhooks","href":"/api-reference/endpoints/webhooks/list-webhook-registrations-never-the-secret"},{"title":"Register an outbound webhook","deprecated":null,"version":null,"openapi":"/api-reference/openapi.json post /v1/webhooks","href":"/api-reference/endpoints/webhooks/register-an-outbound-webhook"},{"title":"Retrieve one webhook registration (never the secret)","deprecated":null,"version":null,"openapi":"/api-reference/openapi.json get /v1/webhooks/{id}","href":"/api-reference/endpoints/webhooks/retrieve-one-webhook-registration-never-the-secret"},{"title":"Delete a webhook registration","deprecated":null,"version":null,"openapi":"/api-reference/openapi.json delete /v1/webhooks/{id}","href":"/api-reference/endpoints/webhooks/delete-a-webhook-registration"},{"title":"Partial update of a webhook registration","deprecated":null,"version":null,"openapi":"/api-reference/openapi.json patch /v1/webhooks/{id}","href":"/api-reference/endpoints/webhooks/partial-update-of-a-webhook-registration"}]}]}]},{"tab":"Integrations","icon":"plug","pages":[{"title":"Integrations","href":"/integrations"}]},{"tab":"Tips \u0026 Tricks","icon":"lightbulb","pages":[{"title":"Tips \u0026 Tricks","href":"/guides/prompting"}]},{"tab":"Changelog","icon":"history","pages":[{"title":"Changelog","href":"/changelog"}]}]},"basePath":"","title":"Author or edit bot code via the code agent - paige","deploymentId":"dpl_G6E2ur2Zjq51xGTVZPSFXsWoTxCu","buildId":"dpl_G6E2ur2Zjq51xGTVZPSFXsWoTxCu","dynamics":["c2aa737661","2b790eda92","b0f84f53ff","a9bb46feb3"],"chunks":["OpenApiReferenceProvider-x4vGgoST.js","snippetPresets-BGlsYH49.js","utils-D225GpYB.js","style-to-object-BY3JEAdk.js","utils-fb7dxv-3.js","v4-DIgz8zy6.js","addUniqueKeysToSchema-D0sNzoEe.js","conditional-requirements-CFM0id0Q.js","cloneDeep-C4iMfrOs.js","_Uint8Array-DDor1j2p.js","isObject-FP1Yky1u.js","ApiExamples-Bw_TWYoP.js","usePlaygroundInputsStore-DLRpNM_Z.js","shallow-DCZ_mvT2.js","isEqual-BZMHHGz2.js","CodeSnippets-CqYNT6UN.js","CodeSnippet-AsYrl7_f.js","getApiPlaygroundDisplay-B1HdZsAn.js","Page-COAeG2by.js","DynamicMarkdown-Bg54PExR.js","SectionHeading-BVOfbSTS.js","icon-Bwg0LftJ.js","MethodPill-ETXe5J4U.js","getPastedJson-6m1DH7UM.js","Check2Icon-Bz4v4IkN.js","axios-CsQoIw0U.js","Markdown-CYkmN8yk.js","AssistantPageLink-BZUrxqjy.js","dist-C-58LlaB.js","lib-DMeTj1gb.js","lib-B8HbPgcC.js","katex-Dbtb6Wk7.js","html-void-elements-mCSPHezU.js","marked.esm-CZWythHk.js"]}