Skip to content
Skip to main content
CONTACT SALESSTART BUILDING

Agents Run API

Use the Agents Run API to trigger Builder's AI agent programmatically from your own systems—for example, from a CI pipeline, an internal tool, or an automated workflow.

Use the API to create a new Project, or add a branch to an existing Project, with your prompt. A link to the Visual Editor, where you can monitor progress, is returned in the response.

Overview of the Agents Run API workflow

  1. Builder creates a new Project in your Space or adds a branch to an existing Project.
  2. The AI agent begins working on your prompt in the background.
  3. Open the url from the response to observe the agent work in real time in the Visual Editor.

The response is returned as soon as the Project branch is created—typically within a few seconds—while the AI agent continues working independently.

Endpoint

Send a POST request to this URL, replacing {spaceId} with your Builder Public API Key.

POST https://api.builder.io/agents/run?apiKey={spaceId}

Authentication

Authenticate with a Builder Personal Access Token sent as a Bearer token. Create one in Account Settings > Personal Access Tokens with the write scope. If you restrict the token to specific Spaces, include the Space you are calling.

The apiKey query parameter is required with a Personal Access Token, and the token's owner must be a member of that Space. The agent runs as the token's owner.

Private API Keys (bpk-) are not accepted and return 403.

Authorization: Bearer btk-YOUR_PERSONAL_ACCESS_TOKEN

Request body

The request body is a JSON object with the following fields.

FieldTypeRequiredDescription

userMessage

object

 Yes

The message to send to the AI agent.

userMessage.userPrompt

String

 Yes

The prompt describing what you want the agent to build.

userMessage.attachments

array

No

File or image attachments for context. See Attachments.

projectId

String

No

ID of an existing project to run the task in. If omitted, a new project is created automatically.

branchName

String

No

A friendly name for the new branch. Also used as the project name when creating a new project.

userId

String

No

Your Builder user ID. Optional; if sent, it must match the token's owner.

userEmail

String

No

Your Builder email. Optional; if sent, it must match the token's owner.

User identification

The agent always runs as the user who owns the Personal Access Token, so you don't need to identify the user in the request body. If you do send userId or userEmail, it must name the token's owner. Naming any other member returns 403.

Specify an existing Project

To run the agent in an existing project, pass the project's ID in the projectId field:

{ "projectId": "<your-project-id>", "userMessage": { "userPrompt": "Add a dark mode toggle to the settings page" } }

The provided Project must belong to the Space in the apiKey query parameter.

To find your Project's ID, go to your Project settings, as shown in the video below.

Attachments

Provide images, files, or URLs as context for the AI agent. The attachments array supports several attachment types, each suited to different use cases.

File upload (type: "upload")

Upload an image, PDF, JSON file, or plain text file. The agent uses these as visual or textual context when generating code.

FieldTypeRequiredDescription

type

String

 Yes

Must be "upload".

name

String

 Yes

The filename; for example, "mockup.png".

contentType

String

Yes

The MIME type of the file. See supported content types below.

dataUrl

String

Yes

A data URL containing the base64-encoded file content; for example, "data:image/png;base64,iVBOR...".

size

Number

Yes

File size in bytes.

id

String

Yes

A unique identifier for this attachment; for example, a UUID.

text

String

No

Extracted text content. Useful for PDFs or text files where you want to provide the raw text alongside the file.

Supported content types:

Content typeUse case

image/png

Screenshots, design mockups, UI references

image/jpeg

Photos, compressed screenshots

image/webp

Modern image format, smaller file sizes

image/gif

Animated examples, short interaction demos

application/pdf

Design specs, requirements documents

application/json

API response samples, configuration files

text/plain

Plain text files, logs, specs

Image upload example:

{ "type": "upload", "name": "hero-mockup.png", "contentType": "image/png", "dataUrl": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUg...", "size": 204800, "id": "att-001" }

PDF spec example:

{ "type": "upload", "name": "requirements.pdf", "contentType": "application/pdf", "dataUrl": "data:application/pdf;base64,JVBERi0xLjQK...", "size": 512000, "id": "att-002", "text": "The landing page should include a hero section with..." }

URL reference (type: "url")

Point the agent to a live webpage for inspiration or reference. The agent fetches and analyzes the page before generating code.

FieldTypeRequiredDescription

type

String

 Yes

Must be "url".

value

String

 Yes

A fully qualified URL; for example, "https://example.com/inspiration".

For example:

{ "type": "url", "value": "https://stripe.com/pricing" }

Mixing attachment types

You can combine different attachment types in a single request. For example, provide a design mockup image alongside a reference URL:

"attachments": [ { "type": "upload", "name": "design.png", "contentType": "image/png", "dataUrl": "data:image/png;base64,iVBORw0KGgo...", "size": 150000, "id": "att-001" }, { "type": "url", "value": "https://example.com/style-guide" } ]

Response

The endpoint returns 202 Accepted with a JSON body once the branch is created. The AI agent continues working in the background.

FieldTypeDescription

branchName

String

The generated branch name where the agent is working.

projectId

String

The ID of the Project.

url

String

Direct link to the Builder Visual Editor for this branch.

status

String

Always "processing".

Examples

The following examples show a minimal request and a request with attachments.

Minimal request

curl -X POST "https://api.builder.io/agents/run?apiKey=YOUR_SPACE_ID" \ -H "Authorization: Bearer btk-YOUR_PERSONAL_ACCESS_TOKEN" \ -H "Content-Type: application/json" \ -d '{ "userMessage": { "userPrompt": "Build a landing page with a hero section, feature grid, and contact form" } }'

Response

{ "branchName": "landing-page-hero-a1b2", "projectId": "abc123def456", "url": "https://builder.io/app/projects/abc123def456/landing-page-hero-a1b2", "status": "processing" }

Request with attachments

curl -X POST "https://api.builder.io/agents/run?apiKey=YOUR_SPACE_ID" \ -H "Authorization: Bearer btk-YOUR_PERSONAL_ACCESS_TOKEN" \ -H "Content-Type: application/json" \ -d '{ "userMessage": { "userPrompt": "Recreate this design as a responsive landing page", "attachments": [ { "type": "upload", "name": "design-mockup.png", "contentType": "image/png", "dataUrl": "data:image/png;base64,iVBORw0KGgo...", "size": 204800, "id": "att-001" } ] } }'

Error responses

If the request fails, the API returns one of the following error responses.

StatusMeaningExample

400

Missing or invalid fields.

{ "error": "userMessage.userPrompt is required" }

401

The token doesn't belong to a user.

{ "error": "User authentication required" }

403

Missing apiKey; an invalid Personal Access Token or one without the write scope; a Private API Key was used; the token's owner isn't in the Space; or userId/userEmail names a different user.

{ "error": "User does not belong to this space" }

404

User not found.

{ "error": "User not found for the provided email" }

500

Unexpected server error.

{ "error": "Internal server error" }

Was this article helpful?