See how Frete cut frontend build time by 70%

Announcing Visual Copilot - Figma to production in half the time

Builder.io
Builder.io
Contact sales

See how Frete cut frontend build time by 70%

Announcing Visual Copilot - Figma to production in half the time

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. The agent creates a new Project, runs your prompt, and returns a link to the Visual Editor where you can monitor progress.

  1. Builder creates a new Project in your Space with an auto-generated name based on your prompt.
  2. Builder creates a branch on that Project and provisions a cloud container.
  3. The AI agent begins working on your prompt in the background.
  4. Open the url from the response to observe the agent work in real time in the Visual Editor.

The response returns as soon as the branch is create—typically a few seconds—while the AI agent continues working independently.

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

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

Authenticate with your Builder Private API Key using a Bearer token.

Authorization: Bearer bpk-YOUR_PRIVATE_KEY

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.

userId

String

Conditional

The Builder user ID to associate with this run. Provide userId or userEmail.

userEmail

String

Conditional

The email of a Builder user in your Space. Provide userId or userEmail.

You must provide either userId or userEmail to identify which Builder user the agent acts on behalf of. The user must be a member of the Space identified by the apiKey.

  • userId is the Builder user ID. Find the user ID in the Space Settings.
  • userEmail is the email address associated with the user's Builder account.

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

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..."
}

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"
}

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"
  }
]

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 newly created project.

url

String

Direct link to the Builder Visual Editor for this branch.

status

String

Always "processing".

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

curl -X POST "https://api.builder.io/agents/run?apiKey=YOUR_SPACE_ID" \
  -H "Authorization: Bearer bpk-YOUR_PRIVATE_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "userMessage": {
      "userPrompt": "Build a landing page with a hero section, feature grid, and contact form"
    },
    "userEmail": "developer@yourcompany.com"
  }'
{
  "branchName": "landing-page-hero-a1b2",
  "projectId": "abc123def456",
  "url": "https://builder.io/app/projects/abc123def456/landing-page-hero-a1b2",
  "status": "processing"
}
curl -X POST "https://api.builder.io/agents/run?apiKey=YOUR_SPACE_ID" \
  -H "Authorization: Bearer bpk-YOUR_PRIVATE_KEY" \
  -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"
        }
      ]
    },
    "userEmail": "developer@yourcompany.com",
  }'

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

StatusMeaningExample

400

Missing or invalid fields.

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

400

No user identifier provided.

{ "error": "Either userId or userEmail is required" }

403

Invalid private key, mismatched Space, or user not in space.

{ "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?

Product

Visual CMS

Theme Studio for Shopify

Sign up

Login

Featured Integrations

React

Angular

Next.js

Gatsby

Get In Touch

Chat With Us

Twitter

Linkedin

Careers

© 2020 Builder.io, Inc.

Security

Privacy Policy

Terms of Service

Get the latest from Builder.io

By submitting, you agree to our Privacy Policy

  • Fusion

  • Publish

  • Product Updates

  • Figma to Code Guide

  • Headless CMS Guide

  • Headless Commerce Guide

  • Composable DXP Guide

Security

Privacy Policy

SaaS Terms

Trust Center

Cookie Preferences