Skip to main content

POST /api/apply/stream

Applies generated files to a sandbox and installs required npm packages. Returns a server-sent events (SSE) stream with progress updates.

Request body

sandboxId
string
The target sandbox ID. If not provided, operations apply to the active sandbox
files
array
required
Array of files to apply to the sandbox
packages
array
Array of npm package names to install (e.g., ["react-router-dom", "axios"])

Response

Returns a server-sent events (SSE) stream with Content-Type: text/event-stream. Events are sent as JSON objects prefixed with data: .

Stream event types

status
object
Progress updates during the apply operation
package
object
Emitted for each successfully installed package
file
object
Emitted for each successfully applied file
complete
object
Final event indicating the operation is complete
error
object
Error event if the operation fails

Error codes

400
Bad Request
Invalid JSON body or missing/empty files array

Example request

curl -X POST https://your-domain.com/api/apply/stream \
  -H "Content-Type: application/json" \
  -d '{
    "sandboxId": "sb_abc123",
    "files": [
      {
        "path": "src/components/Button.tsx",
        "content": "export default function Button() { return <button>Click me</button>; }"
      },
      {
        "path": "src/App.tsx",
        "content": "import Button from './components/Button';\n\nexport default function App() { return <Button />; }"
      }
    ],
    "packages": ["react", "react-dom"]
  }'

Example SSE response

data: {"type":"status","message":"Installing packages..."}

data: {"type":"status","message":"Installing 2 package(s)..."}

data: {"type":"package","data":{"name":"react"}}

data: {"type":"package","data":{"name":"react-dom"}}

data: {"type":"status","message":"Applying 2 file(s)..."}

data: {"type":"status","message":"Applying 1/2: Button.tsx"}

data: {"type":"file","data":{"path":"src/components/Button.tsx","status":"applied"}}

data: {"type":"status","message":"Applying 2/2: App.tsx"}

data: {"type":"file","data":{"path":"src/App.tsx","status":"applied"}}

data: {"type":"complete","data":{"appliedFiles":["src/components/Button.tsx","src/App.tsx"],"installedPackages":["react","react-dom"],"success":true}}

Operation order

The apply endpoint executes operations in this order:
  1. Install packages (if provided)
  2. Apply files to the sandbox with progress callbacks
  3. Emit completion event with summary
Package installation failures are reported but do not halt file application.

Build docs developers (and LLMs) love