ghl_clientportal_submit_agent_run
Submits a prompt to start an AI agent run that builds or edits project code in the background. Returns a runId for polling progress.
Instructions
CLIENT PORTAL AI BUILDER API (/ai-builder-api) — side-effecting: opens/edits sandboxes and starts builds. Edit a sandbox only once sandbox.status is ready; checkpoint after edits and before starting the run that builds them; 409 means a cloud build owns the sandbox or it is not running.
Submit a prompt; the agent runs in the background.
Returns runId immediately. A sub-account token builds with its own agent: it writes the code
with POST .../sandbox/edit (and registers a React Native app's screens with
POST .../sandbox/extension-routes), saves the files with POST .../sandbox/checkpoint, then
starts the run with externalAgent: true, which checks, builds and deploys them. Poll
GET .../runs/{runId}: problems a passing build still has are in checkProblems.
The builder's own agent executes asynchronously:
attempt workspace restore from project's prior run → materialise
scaffold (only if no prior workspace) → loop tool calls → preflight
pnpm build → flush workspace to GCS → deploy via Cloud Build →
managed runtime revision replace → mark ready with a preview URL.
Per-project runtime services receive a stable public app hostname so the iframe URL works without platform-session auth.
Idempotency: callers SHOULD send an Idempotency-Key header on
every retry. The server stores (locationId, projectId, key) →
runId for 24 h. Same key + same body → the original runId is
replayed. Same key + different body → 409 idempotency_conflict.
Modeled after standard idempotent POST contracts; safe for browser
retries, network blips, and double-click submits.
Attachment scope: when attachmentIds are present, each id is
verified against the caller's tenant + project. Cross-project or
cross-tenant reuse is rejected with 403 attachment_not_owned.
Endpoint: POST /ai-builder-api/projects/{projectId}/runs (Version header: v3; source: v3/clientportal-ai-v3.json)
OAuth scopes: clientportal-ai.write
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| body | Yes | Request body (schema carried verbatim from the official OpenAPI spec). | |
| projectId | Yes | The project's id. | |
| Idempotency-Key | No | 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`. | |
| X-Correlation-Id | No | 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. |