Submit a prompt; the agent runs in the background.
POST/ai-builder-api/projects/{projectId}/runs
Returns runId at once; the run goes on in the background. An agent outside the builder (an
MCP client) writes the app's code first: POST .../sandbox/edit for each file (and, for a
React Native app, POST .../sandbox/extension-routes for its screens), then
POST .../sandbox/checkpoint to save them, then this call with externalAgent: true, which
checks, builds and deploys the preview. Without externalAgent, the builder's own agent
writes the code from prompt.
Poll GET .../runs/{runId} until status is ready or failed. A first build may stop at
needs_input with pendingQuestions: answer them with POST .../runs/{runId}/answers/batch.
Problems a passing build still has are in checkProblems.
Idempotency: send an Idempotency-Key header on every retry. The same key and body
replays the original runId for 24 hours; the same key with a different body answers
409 idempotency_conflict.
Authorizations
Authorizationstringheaderrequired
Bearer authentication header of the form Bearer <token>, where <token> is your access token.
Caller-generated key (UUID-v4 recommended) that makes this POST
safe to retry. Must match the prior request body byte-for-byte
on replay. Reused with a different body → 409.
Possible values:non-empty and <= 255 characters
Example:6d2f0a8e-1b3c-4d5e-8f9a-0b1c2d3e4f5a
X-Correlation-Idstring
Optional caller-supplied trace id. When omitted, the API mints
cid_<uuid> and echoes it back via the response
X-Correlation-Id header. Threaded through audit rows + logs.
Possible values:non-empty and <= 64 characters
Example:cid_7d9e2f1a
Versionstringrequired
The API version.
Available optionsv3
Example:v3
Path Parameters
projectIdstringrequired
The project's id.
Possible values: Value must match regular expression ^prj_[A-Za-z0-9_-]+$
Example:prj_5f0c2a3e
Body
application/json
promptstringrequired
What to build or change.
Possible values:non-empty and <= 20000 characters
Example:Add a page listing upcoming events
displayTextstring
What the creator's chat bubble shows for this run instead of
prompt, when the client sends an instruction the creator did not
type (for example a suggestion chip, whose full text carries
verifier output or a planner directive for the agent). One plain
line. Omitted for typed messages, whose bubble is the prompt.
Possible values:non-empty and <= 200 characters, Value must match regular expression ^(?=.*\S)[^\p{Cc}]+$
Example:Fix these issues
productTargetProductTarget
What the project builds; the project's own by default.
Available optionsfull_stackmobilelanding_page
customCodeboolean
For the builder's own agent on a ClientPortal app: true lets it change the app's code, false limits it to the app's settings. Not used with externalAgent.
Default:false
Example:false
clientPortalSurfacestring
ClientPortal-only context captured from the selected builder surface.
Unqualified follow-ups default to this lane; explicit web, mobile,
or web-and-mobile wording in the prompt takes precedence.
Available optionswebmobile
Example:web
externalAgentboolean
An agent outside the builder (an MCP client) writes this run's code in
the project's sandbox. The run skips the builder's agent: a first build
asks the builder's intake questions (answered through the answers
API), then every run checks, delivers, registers the sandbox with
ClientPortal, and seals a publishable release.
Default:false
Example:true
summaryobject
With externalAgent only: what the agent changed, in the words its creator would use. The builder's chat shows it as the run's summary, beside the files the agent changed in the sandbox. Without it, the chat lists those files.
summary.titlestringrequired
One line naming the change.
Possible values:non-empty and <= 120 characters
Example:Dark mode on every page
summary.outcomesstring[]required
What the creator gets, one change per item, in plain words.
Possible values:<= 6
Example:["A light/dark switch in the header of every page","Dark values for the community rail and avatars"]
mobilePipelinestring
Deprecated compatibility field for older mobile clients. New mobile
runs use the standard builder flow with the React Native app kernel.
Available optionsv2-simple
Example:v2-simple
mobilePipelineSpeedstring
Deprecated: accepted from older mobile clients and ignored.
Available optionsfastslow
Example:fast
modelIdstring
The model the builder's own agent uses for every step of this run; omitted, the platform picks one per step. Not used with externalAgent.
Possible values:non-empty and <= 200 characters
Example:claude-sonnet-4-5
agentIdstring
An agent profile the creator set up in the builder, for the builder's own agent. Not used with externalAgent.
Possible values: Value must match regular expression ^agt_[A-Za-z0-9_-]+$
Example:agt_4c2d1e
modestring
How the builder's own agent works: auto (it decides), plan (it proposes a plan and waits for the creator's approval in the builder) or build (straight to code); plan_first is plan. Not used with externalAgent.
Available optionsautoplanbuildplan_first
Example:auto
attachmentIdsstring[]
Files the creator uploaded in the builder, given to the builder's own agent as context. Not used with externalAgent.
Possible values:<= 10
Example:["att_1a2b3c"]
selectedElementsobject[]
Visual edits (vibe apps): the elements the creator selected in the
live preview before sending. The agent receives them as a
<selected-elements> block after the prompt, so "this" means the
element on screen. Context only: file and line are hints the agent
checks against the workspace.
Possible values:<= 20
selectedElements[].elementTypestringrequired
Lower-case tag name of the element, e.g. h1.
Possible values: Value must match regular expression ^[a-z][a-z0-9-]{0,39}$
Example:h1
selectedElements[].filePathstring
Where the element is written, relative to the app root (no .. segment, not absolute; Nuxt route characters such as [id] and (group) allowed).
Possible values:<= 300 characters, Value must match regular expression ^(?!.*(?:^|/)\.\.(?:/|$))[A-Za-z0-9_@.()\[\]+~$ -][A-Za-z0-9_@.()\[\]+~$ /-]*$
Example:pages/index.vue
selectedElements[].lineNumberinteger
The element's line in filePath.
Possible values:>= 1 and <= 1000000
Example:12
selectedElements[].ownerFilePathstring
The page that renders the design-system component this element is the root of. Same rule as filePath.
Possible values:<= 300 characters, Value must match regular expression ^(?!.*(?:^|/)\.\.(?:/|$))[A-Za-z0-9_@.()\[\]+~$ -][A-Za-z0-9_@.()\[\]+~$ /-]*$
Example:pages/index.vue
selectedElements[].ownerLineNumberinteger
The line in ownerFilePath.
Possible values:>= 1 and <= 1000000
Example:8
selectedElements[].textContentstring
The element's visible text, with emails and phone numbers redacted by the preview.
Possible values:<= 500 characters
Example:Welcome back
selectedElements[].classNamestring
The element's CSS classes.
Possible values:<= 2000 characters
Example:text-3xl font-bold
selectedElements[].attrsobject
A small set of the element's HTML attributes (id, role, type, name, links without their query, aria-*…).
selectedElements[].attrs.property name*string
Possible values:<= 500 characters
Response
application/json
Accepted; agent is running.
X-Correlation-Id
Correlation id used for log + audit stitching.
runIdstringrequired
The run that started.
Possible values: Value must match regular expression ^run_[A-Za-z0-9_-]+$
Example:run_8f3c2a91
stateobjectrequired
The run as it starts.
state.runIdstringrequired
The run.
Example:run_8f3c2a91
state.projectIdstringrequired
The project the run belongs to.
Example:prj_5f0c2a3e
state.promptstringrequired
What the run was asked to build or change.
Example:Add a page listing upcoming events
state.displayTextstring
The creator-facing text of this run's user bubble when it differs from prompt (see SubmitAgentRunRequest.displayText).
Example:Fix these issues
state.promptAuthorobject
Who sent the prompt.
state.promptAuthor.idstringrequired
Authenticated user id captured when the prompt was submitted.
Example:usr_9a8b7c
state.promptAuthor.namestringrequired
Display-name snapshot captured when the prompt was submitted.
Example:Jane Doe
state.promptAuthor.avatarUrlstring<uri>
Profile-image snapshot captured when the prompt was submitted.
app when an app sent the prompt rather than a person: an MCP client (name is "Claude", "Cursor"…) or an integration.
Available optionsapp
Example:app
state.statusAgentRunStatusrequired
The run's status.
Available optionsqueuedrunningdeployingreadyfailedcancelledneeds_input
state.phasestring
Internal Spec Kit phase for the active builder run. Stream-v6 maps this to user-facing data-status.data.phase values such as planning, clarifying, coding, and building.
Available optionsinitconstitutionspecifyclarifyplantasksanalyzeimplementindexingbuilddeployready
Example:plan
state.phaseStatusstring
Phase-local status for the active Spec Kit phase.
Available optionsqueuedrunningawaiting_inputterminal
Example:running
state.awaitingQuestionobject
The question the run is paused on, while it waits for the creator.
state.awaitingQuestion.capIdstringrequired
The question's id: send it back as capId with the answer.
Example:cap_portal_modules
state.awaitingQuestion.questionstringrequired
The question to put to the creator.
Example:Which areas should your portal have?
state.awaitingQuestion.choicesstring[]
The answers to offer, when it is a choice.
Example:["Courses","Communities"]
state.awaitingQuestion.formobject
Set when the answer is a form (record fields or media) rather than a choice; its kind says which.
oneOf
RecordQuestionForm
MediaQuestionForm
The record-fields form on awaitingQuestion.form. The answer value
is JSON.stringify({ fields: [{ label, type, options? }], show: [label, …] })
(fields = the NEW fields, show = every field clients see); as the
editor (edit: true) it also carries edits and has show only when
what clients see changed.
The questions a first build asks before it starts, while status is needs_input: answer them all with POST .../runs/{runId}/answers/batch, each by its capId.
state.pendingQuestions[].capIdstringrequired
The question's id: send it back as capId with its answer.
Example:clarify.cp.name
state.pendingQuestions[].displayNamestring
What kind of question it is.
Example:Planning question
state.pendingQuestions[].textstringrequired
The question.
Example:What should we call it?
state.pendingQuestions[].optionsobject[]required
The answers to pick from; empty when freeText asks for a typed answer.
Example:The name your customers see when they sign in.
state.pendingQuestions[].groupstring
The page of the intake form it belongs to.
Example:app
state.pendingQuestions[].controlstring
How the builder draws it: cards, swatches, fonts, text and so on.
Example:text
state.pendingQuestions[].platformsstring[]
The platforms the question exists on, when not all.
Example:["mobile"]
state.publicPhaseStateobject
Where the run is, in the words the builder shows the creator.
state.publicPhaseState.phasestringrequired
The step the run is on.
Example:clarifying
state.publicPhaseState.phaseStatusstringrequired
Where that step is.
Available optionsqueuedrunningawaiting_inputterminal
Example:awaiting_input
state.publicPhaseState.messagestring
The step in one sentence for the creator.
Example:Answer the planning question to continue.
state.publicPhaseState.phaseIndexinteger
The step's position, from 0.
Example:2
state.publicPhaseState.phaseTotalinteger
How many steps the run has.
Example:6
state.publicPhaseState.tsstring<date-time>
When the run reached this state.
Example:2026-10-23T12:57:27.435Z
state.createdAtstring<date-time>required
When the run was created.
Example:2026-10-15T09:30:00.000Z
state.updatedAtstring<date-time>required
When the run last changed.
Example:2026-10-15T09:41:12.000Z
state.checkProblemsstring[]
Problems the check found in a build written by an outside agent (externalAgent: true)
that still built and deployed. Fix them with another set of edits and run.
Example:["pages/learn.vue: 'courses' is possibly undefined"]
state.previewUrlstring<uri>
Convenience field equal to preview.primaryUrl. Kept for
single-service callers; multi-service callers should read
preview.services[] for per-service URLs. This is the
durable customer-facing preview URL produced after a
successful build/deploy, not the live sandbox edit URL.
Example:https://preview.example.com/my-portal
state.previewobject
Where to see what the run built.
state.preview.primaryUrlstring<uri>required
The URL the user opens — for multi-service web stacks, this is the primary (frontend) URL.
Deprecated 2026-05-17. Will be removed 2026-11-17.
Use sandboxUrl instead — same value, accurate name.
Misleadingly named: this is the SANDBOX URL (the agent's
HMR/edit workshop), not the customer-facing preview. The
customer preview lives at previewUrl. Co-populated with
sandboxUrl for the deprecation window; readers should
migrate to sandboxUrl.
Example:https://sbx-prj-5f0c2a3e.example.com
state.livePreviewStatusstringdeprecated
Deprecated 2026-05-17. Will be removed 2026-11-17.
Use sandboxStatus instead.
Available optionsstartingreadyfailedstopped
Example:ready
state.sandboxUrlstring<uri>
URL of the project sandbox runtime.
This is the agent's compile + HMR workshop — NOT the
customer-facing preview. The customer preview is at
previewUrl, which surfaces in the builder UI's right
pane after the deploy gate succeeds.
Example:https://sbx-prj-5f0c2a3e.example.com
state.sandboxStatusstring
Current state of the sandbox dev server.
Available optionsstartingreadyfailedstopped
Example:ready
state.publishedUrlstring<uri>
URL of the production ("Published") runtime service for this project.
Populated when the project has
been explicitly published at least once. Distinct from
previewUrl/preview.primaryUrl, which always point at the
durable customer preview service that auto-updates on every
successful agent run. Absent for projects that have never
been published — the FE renders "Not published" in that case.
Example:https://my-portal.example.com
state.publishedAtstring<date-time>
ISO-8601 timestamp of the most recent publish, snapshotted
onto the run at the moment it reached ready. Used by the
FE to render staleness like "Last published 5 hours ago".
Example:2026-10-14T18:02:00.000Z
state.runsSinceLastPublishinteger
Number of successful (status=ready) runs completed since
the project was last published. Reset to 0 by publish.
Snapshotted onto each ready run so the FE can render a
staleness indicator without an extra round-trip. Absent
for projects that have never been published.
Possible values:>= 0
Example:2
state.summarystring
AI-generated 1-line checkpoint description, snapshotted onto
the run record at setStatus("ready") time. Sourced from
the agent's completion narrator event when present,
otherwise falls back to a deterministic prompt-derived
stub. Read by Timeline + chat UI so users see "what
changed in this checkpoint" at a glance. Absent on
non-terminal or legacy runs.
Example:Added an events page
state.imageUristringdeprecated
Deprecated: no longer returned. It named the builder's own image registry.
Deprecated: no longer returned. It named the builder's own image.
Example:sha256:3b1f0c9e2d7a
state.failureMessagestring
Why the run failed, in one line.
Example:The build failed: pages/events.vue has a type error
state.failureobject
Structured failure taxonomy for a terminated run. Set in
tandem with failureMessage (which is the human-readable
derivation). Discriminated by category; consumers should
branch on category + code to render an actionable hint
instead of a generic "Internal error".
state.failure.categorystringrequired
What kind of failure it was.
Available optionsuser_inputconfigmodelbuildinfraspec_kittransportruntimeinternal
Example:build
state.failure.codestringrequired
Category-specific failure code. See the run-runtime
RunFailure discriminated union for the per-category
code enum.
Example:build_failed
state.failure.retryablebooleanrequired
Sending the same request again may succeed.
Example:false
state.failure.responsibleModulestringrequired
The part of the builder that failed.
Available optionsruntimedispatcherplannerclassifierspec_kitdesignerscaffolderbuilderverifierdeployerinframodel_provider
Example:runtime
state.failure.userMessagestring
For category=user_input — text safe to show the user verbatim.
Example:Describe the page you want in a sentence or two.
state.failure.detailsstring
For category=config / spec_kit — operator-facing detail.
Example:No stack manifest for this template
state.failure.providerstring
For category=model — provider identifier (e.g. anthropic, openai).
Example:anthropic
state.failure.attemptinteger
For category=model — retry attempt index that ultimately gave up.
Example:3
state.failure.failureHeadstring
For category=build — first chunk of compiler/test stderr.
Example:pages/events.vue(12,5): error TS2339
state.failure.failureTailstring
For category=build — last chunk of compiler/test stderr.
Example:Found 1 error.
state.failure.causestring
For category=infra — short cause description.
Example:The sandbox did not become ready in time
state.failure.phasestring
For category=spec_kit — phase id where the orchestrator halted.
Example:plan
state.failure.stackstring
For category=internal — first lines of the stack trace. Never sent to a sub-account token.
Example:TypeError: Cannot read properties of undefined
state.failure.messagestring
For category=runtime — text safe to show the user verbatim.
Example:The preview could not start.
state.metadataobjectdeprecated
Deprecated: no longer returned. It held the builder's own debugging state.
state.metadata.generationFailureobject
Why generating the app failed, when it did.
state.metadata.generationFailure.codestring
The failure code.
Available optionsprovider_transientdispatch_failedscaffold_failedinfra_failedagent_failedbuild_faileddeploy_failedrun_stalledpipeline_failed
Example:provider_transient
state.metadata.generationFailure.retryableboolean
Retrying may succeed.
Example:true
state.metadata.generationFailure.sourcestring
Where it failed.
Available optionsproviderdispatchplanningscaffoldinfraagentbuilddeploypipeline