### Example Usage of Sandbox Provider
Source: https://context7.com/firecrawl/open-lovable/llms.txt
Demonstrates how to use the SandboxProvider interface with the E2B provider to create a sandbox, write files, run commands, install packages, and restart the Vite server. Ensure proper cleanup by terminating the sandbox.
```typescript
// Example usage with E2B provider
const provider = SandboxFactory.create('e2b');
const info = await provider.createSandbox();
await provider.writeFile('src/App.jsx', "
function App() {
return
Hello World
;
}
export default App;
");
const result = await provider.runCommand('npm run build');
console.log(result.stdout, result.exitCode);
await provider.installPackages(['axios', 'lodash']);
await provider.restartViteServer();
// Cleanup
await provider.terminate();
```
--------------------------------
### Install Packages API
Source: https://context7.com/firecrawl/open-lovable/llms.txt
Installs npm packages in the active sandbox with real-time progress streaming.
```APIDOC
## POST /api/install-packages
### Description
Installs npm packages in the active sandbox with real-time progress streaming.
### Method
POST
### Endpoint
/api/install-packages
### Parameters
#### Request Body
- **packages** (array[string]) - Required - An array of package names to install.
### Request Example
```json
{
"packages": ["framer-motion", "@heroicons/react", "recharts"]
}
```
### Response
#### Success Response (200)
- **success** (boolean) - Indicates if the operation was successful.
- **message** (string) - A message describing the outcome of the operation.
- **installedPackages** (array[string]) - A list of packages that were successfully installed.
#### Response Example (SSE Stream)
```
data: {"type":"start","message":"Installing 3 packages...","packages":["framer-motion","@heroicons/react","recharts"]}
data: {"type":"status","message":"Stopping development server..."}
data: {"type":"status","message":"Checking installed packages..."}
data: {"type":"info","message":"Installing 3 new package(s): framer-motion, @heroicons/react, recharts"}
data: {"type":"success","message":"Successfully installed: framer-motion, @heroicons/react, recharts","installedPackages":["framer-motion","@heroicons/react","recharts"]}
data: {"type":"status","message":"Restarting development server..."}
data: {"type":"complete","message":"Package installation complete and dev server restarted!","installedPackages":["framer-motion","@heroicons/react","recharts"]}
```
```
--------------------------------
### Clone and Install Dependencies
Source: https://github.com/firecrawl/open-lovable/blob/main/README.md
Clone the Open Lovable repository and install its dependencies using pnpm. Alternatively, npm or yarn can be used.
```bash
git clone https://github.com/firecrawl/open-lovable.git
cd open-lovable
pnpm install # or npm install / yarn install
```
--------------------------------
### Run Development Server
Source: https://github.com/firecrawl/open-lovable/blob/main/README.md
Start the Open Lovable development server using pnpm. The application will be accessible at http://localhost:3000.
```bash
pnpm dev # or npm run dev / yarn dev
```
--------------------------------
### Install npm Packages with SSE
Source: https://context7.com/firecrawl/open-lovable/llms.txt
Use this endpoint to install npm packages in the active sandbox. It streams real-time progress updates via Server-Sent Events (SSE).
```bash
curl -X POST http://localhost:3000/api/install-packages \
-H "Content-Type: application/json" \
-d '{
"packages": ["framer-motion", "@heroicons/react", "recharts"]
}'
```
```text
data: {"type":"start","message":"Installing 3 packages...","packages":["framer-motion","@heroicons/react","recharts"]}
data: {"type":"status","message":"Stopping development server..."}
data: {"type":"status","message":"Checking installed packages..."}
data: {"type":"info","message":"Installing 3 new package(s): framer-motion, @heroicons/react, recharts"}
data: {"type":"success","message":"Successfully installed: framer-motion, @heroicons/react, recharts","installedPackages":["framer-motion","@heroicons/react","recharts"]}
data: {"type":"status","message":"Restarting development server..."}
data: {"type":"complete","message":"Package installation complete and dev server restarted!","installedPackages":["framer-motion","@heroicons/react","recharts"]}
```
--------------------------------
### Get All Sandbox Files
Source: https://context7.com/firecrawl/open-lovable/llms.txt
Retrieves all files from the active sandbox, including parsed component information and a file manifest. This is useful for analyzing the sandbox's contents.
```bash
curl -X GET http://localhost:3000/api/get-sandbox-files
```
```json
{
"success": true,
"files": {
"src/App.jsx": "import Hero from './components/Hero';\nimport Header from './components/Header';\n...",
"src/components/Hero.jsx": "function Hero() { return ...
}",
"src/components/Header.jsx": "function Header() { return }",
"src/index.css": "@tailwind base;\n@tailwind components;\n@tailwind utilities;"
},
"structure": ".\n./src\n./src/components\n./public",
"fileCount": 4,
"manifest": {
"files": {
"/src/App.jsx": {
"content": "...",
"type": "component",
"path": "/src/App.jsx",
"relativePath": "src/App.jsx",
"imports": ["./components/Hero", "./components/Header"],
"exports": ["default"]
}
},
"routes": [],
"componentTree": {
"App": ["Hero", "Header"]
},
"entryPoint": "/src/main.jsx",
"styleFiles": ["/src/index.css"],
"timestamp": 1704067200000
}
}
```
--------------------------------
### Get Sandbox Files API
Source: https://context7.com/firecrawl/open-lovable/llms.txt
Retrieves all files from the active sandbox with parsed component information and file manifest.
```APIDOC
## GET /api/get-sandbox-files
### Description
Retrieves all files from the active sandbox, including parsed component information and a file manifest.
### Method
GET
### Endpoint
/api/get-sandbox-files
### Response
#### Success Response (200)
- **success** (boolean) - Indicates if the files were retrieved successfully.
- **files** (object) - An object where keys are file paths and values are file contents.
- **structure** (string) - A string representing the directory structure of the sandbox.
- **fileCount** (integer) - The total number of files in the sandbox.
- **manifest** (object) - An object containing parsed information about the files, routes, component tree, entry point, and style files.
#### Response Example
```json
{
"success": true,
"files": {
"src/App.jsx": "import Hero from './components/Hero';\nimport Header from './components/Header';\n...",
"src/components/Hero.jsx": "function Hero() { return ...
}",
"src/components/Header.jsx": "function Header() { return }",
"src/index.css": "@tailwind base;\n@tailwind components;\n@tailwind utilities;"
},
"structure": ".\n./src\n./src/components\n./public",
"fileCount": 4,
"manifest": {
"files": {
"/src/App.jsx": {
"content": "...",
"type": "component",
"path": "/src/App.jsx",
"relativePath": "src/App.jsx",
"imports": ["./components/Hero", "./components/Header"],
"exports": ["default"]
}
},
"routes": [],
"componentTree": {
"App": ["Hero", "Header"]
},
"entryPoint": "/src/main.jsx",
"styleFiles": ["/src/index.css"],
"timestamp": 1704067200000
}
}
```
```
--------------------------------
### Get Available Sandbox Providers
Source: https://context7.com/firecrawl/open-lovable/llms.txt
Retrieves a list of all available sandbox providers that can be used with the SandboxFactory. This helps in determining which providers are supported.
```typescript
// Check available providers
const providers = SandboxFactory.getAvailableProviders();
// Returns: ['e2b', 'vercel']
```
--------------------------------
### Apply AI Code to Sandbox
Source: https://context7.com/firecrawl/open-lovable/llms.txt
Applies AI-generated code to the active sandbox, handling file creation/updates, package installation, and Vite server restarts. Specify the response containing code and any new packages.
```bash
curl -X POST http://localhost:3000/api/apply-ai-code \
-H "Content-Type: application/json" \
-d '{
"response": "function Hero() { return Welcome
}import Hero from \"./components/Hero\"; function App() { return } export default App;",
"isEdit": false,
"packages": ["framer-motion"]
}'
```
```json
{
"success": true,
"results": {
"filesCreated": ["src/components/Hero.jsx", "src/App.jsx"],
"filesUpdated": [],
"packagesInstalled": ["framer-motion"],
"packagesAlreadyInstalled": [],
"packagesFailed": [],
"commandsExecuted": [],
"errors": []
},
"explanation": "Code generated successfully!",
"message": "Applied 2 files successfully"
}
```
--------------------------------
### AI Code Application API
Source: https://context7.com/firecrawl/open-lovable/llms.txt
Applies AI-generated code to the active sandbox, handling file creation/updates, package installation, and server restarts.
```APIDOC
## POST /api/apply-ai-code
### Description
Parses AI-generated code and writes files to the active sandbox. Handles package detection, installation, and automatic Vite server restart.
### Method
POST
### Endpoint
/api/apply-ai-code
### Parameters
#### Request Body
- **response** (string) - Required - The AI-generated code, typically in a format with file path indicators.
- **isEdit** (boolean) - Required - A flag indicating if this is an edit operation.
- **packages** (array of strings) - Optional - A list of npm packages to install.
### Request Example
```json
{
"response": "function Hero() { return Welcome
}import Hero from \"./components/Hero\"; function App() { return } export default App;",
"isEdit": false,
"packages": ["framer-motion"]
}
```
### Response
#### Success Response (200)
- **success** (boolean) - Indicates if the code application was successful.
- **results** (object) - Details about the applied code.
- **filesCreated** (array of strings) - List of files created.
- **filesUpdated** (array of strings) - List of files updated.
- **packagesInstalled** (array of strings) - List of packages successfully installed.
- **packagesAlreadyInstalled** (array of strings) - List of packages that were already installed.
- **packagesFailed** (array of strings) - List of packages that failed to install.
- **commandsExecuted** (array of strings) - List of commands executed.
- **errors** (array of strings) - List of any errors encountered.
- **explanation** (string) - An explanation of the operation.
- **message** (string) - A summary message.
#### Response Example
```json
{
"success": true,
"results": {
"filesCreated": ["src/components/Hero.jsx", "src/App.jsx"],
"filesUpdated": [],
"packagesInstalled": ["framer-motion"],
"packagesAlreadyInstalled": [],
"packagesFailed": [],
"commandsExecuted": [],
"errors": []
},
"explanation": "Code generated successfully!",
"message": "Applied 2 files successfully"
}
```
```
--------------------------------
### Create AI Sandbox (v1 - Vercel)
Source: https://context7.com/firecrawl/open-lovable/llms.txt
Creates a new isolated sandbox environment specifically for Vercel. This endpoint is for Vercel-only sandbox creation.
```bash
curl -X POST http://localhost:3000/api/create-ai-sandbox
```
```json
{
"success": true,
"sandboxId": "vercel-xyz789",
"url": "https://xyz789.vercel-sandbox.dev:3000",
"message": "Vercel sandbox created and Vite React app initialized"
}
```
--------------------------------
### Create AI Sandbox (v2)
Source: https://context7.com/firecrawl/open-lovable/llms.txt
Creates a new isolated sandbox environment with a pre-configured Vite + React + Tailwind CSS application. The sandbox provider is determined by the SANDBOX_PROVIDER environment variable.
```bash
curl -X POST http://localhost:3000/api/create-ai-sandbox-v2
```
```json
{
"success": true,
"sandboxId": "sandbox-abc123",
"url": "https://abc123.e2b.dev:5173",
"provider": "e2b",
"message": "Sandbox created and Vite React app initialized"
}
```
--------------------------------
### Create Sandbox with Environment-Configured Provider
Source: https://context7.com/firecrawl/open-lovable/llms.txt
Instantiates a sandbox using the SandboxFactory. The factory automatically selects the provider based on environment variables. The `createSandbox` method returns information about the newly created sandbox.
```typescript
import { SandboxFactory } from '@/lib/sandbox/factory';
// Create sandbox using environment-configured provider
const provider = SandboxFactory.create();
const sandboxInfo = await provider.createSandbox();
// Returns: { sandboxId, url, provider, createdAt }
```
--------------------------------
### Create Sandbox with Explicit Provider
Source: https://context7.com/firecrawl/open-lovable/llms.txt
Demonstrates how to explicitly specify the sandbox provider (e.g., 'e2b' or 'vercel') when creating a sandbox using the SandboxFactory.
```typescript
// Explicitly specify provider
const e2bProvider = SandboxFactory.create('e2b');
const vercelProvider = SandboxFactory.create('vercel');
```
--------------------------------
### Run Command in Sandbox (v2)
Source: https://context7.com/firecrawl/open-lovable/llms.txt
Executes shell commands in the active sandbox environment using the v2 endpoint, which supports provider abstraction. Ensure the command is a string.
```bash
curl -X POST http://localhost:3000/api/run-command-v2 \
-H "Content-Type: application/json" \
-d '{
"command": "ls -la src/components"
}'
```
```json
{
"success": true,
"output": "total 24\ndrwxr-xr-x 2 user user 4096 Jan 1 12:00 .\n-rw-r--r-- 1 user user 1234 Jan 1 12:00 Hero.jsx\n-rw-r--r-- 1 user user 567 Jan 1 12:00 Header.jsx",
"error": "",
"exitCode": 0,
"message": "Command executed successfully"
}
```
--------------------------------
### Run Command API
Source: https://context7.com/firecrawl/open-lovable/llms.txt
Executes shell commands in the active sandbox environment.
```APIDOC
## POST /api/run-command-v2
### Description
Executes shell commands in the active sandbox environment using the v2 endpoint with provider abstraction.
### Method
POST
### Endpoint
/api/run-command-v2
### Parameters
#### Request Body
- **command** (string) - Required - The shell command to execute.
### Request Example
```json
{
"command": "ls -la src/components"
}
```
### Response
#### Success Response (200)
- **success** (boolean) - Indicates if the command executed successfully.
- **output** (string) - The standard output of the command.
- **error** (string) - Any error messages produced by the command.
- **exitCode** (integer) - The exit code of the command.
- **message** (string) - A message describing the outcome of the command execution.
#### Response Example
```json
{
"success": true,
"output": "total 24\ndrwxr-xr-x 2 user user 4096 Jan 1 12:00 .\n-rw-r--r-- 1 user user 1234 Jan 1 12:00 Hero.jsx\n-rw-r--r-- 1 user user 567 Jan 1 12:00 Header.jsx",
"error": "",
"exitCode": 0,
"message": "Command executed successfully"
}
```
## POST /api/run-command
### Description
Executes shell commands in the active sandbox environment (v1 endpoint - Vercel sandbox only).
### Method
POST
### Endpoint
/api/run-command
### Parameters
#### Request Body
- **command** (string) - Required - The shell command to execute.
### Request Example
```json
{
"command": "npm run build"
}
```
```
--------------------------------
### Application Configuration Access
Source: https://context7.com/firecrawl/open-lovable/llms.txt
Shows how to access and use application configuration settings for sandbox timeouts, AI models, and other behaviors. Use `getConfig` for type-safe access to configuration sections and `getConfigValue` for specific nested values.
```typescript
import { appConfig, getConfig, getConfigValue } from '@/config/app.config';
// Access configuration sections
const vercelConfig = appConfig.vercelSandbox;
// { timeoutMinutes: 15, devPort: 3000, devServerStartupDelay: 7000, ... }
const e2bConfig = appConfig.e2b;
// { timeoutMinutes: 30, vitePort: 5173, viteStartupDelay: 10000, ... }
const aiConfig = appConfig.ai;
// { defaultModel: 'google/gemini-3-pro-preview', maxTokens: 8000, ... }
// Available AI models
const models = appConfig.ai.availableModels;
// ['openai/gpt-5', 'moonshotai/kimi-k2-instruct-0905', 'anthropic/claude-sonnet-4-20250514', 'google/gemini-3-pro-preview']
// Type-safe config getter
const uiConfig = getConfig('ui');
// { showModelSelector: true, toastDuration: 3000, maxChatMessages: 100, ... }
// Nested value access
const timeout = getConfigValue('vercelSandbox.timeoutMs');
// 900000 (15 minutes in milliseconds)
```
--------------------------------
### Environment Configuration for Open Lovable
Source: https://github.com/firecrawl/open-lovable/blob/main/README.md
Configure your environment variables in a .env.local file. This includes API keys for Firecrawl, AI providers (Gemini, Anthropic, OpenAI, Groq), an optional key for Morph, and settings for the sandbox provider (Vercel or E2B).
```env
# =================================================================
# REQUIRED
# =================================================================
FIRECRAWL_API_KEY=your_firecrawl_api_key # https://firecrawl.dev
# =================================================================
# AI PROVIDER - Choose your LLM
# =================================================================
GEMINI_API_KEY=your_gemini_api_key # https://aistudio.google.com/app/apikey
ANTHROPIC_API_KEY=your_anthropic_api_key # https://console.anthropic.com
OPENAI_API_KEY=your_openai_api_key # https://platform.openai.com
GROQ_API_KEY=your_groq_api_key # https://console.groq.com
# =================================================================
# FAST APPLY (Optional - for faster edits)
# =================================================================
MORPH_API_KEY=your_morphllm_api_key # https://morphllm.com/dashboard
# =================================================================
# SANDBOX PROVIDER - Choose ONE: Vercel (default) or E2B
# =================================================================
SANDBOX_PROVIDER=vercel # or 'e2b'
# Option 1: Vercel Sandbox (default)
# Choose one authentication method:
# Method A: OIDC Token (recommended for development)
# Run `vercel link` then `vercel env pull` to get VERCEL_OIDC_TOKEN automatically
VERCEL_OIDC_TOKEN=auto_generated_by_vercel_env_pull
# Method B: Personal Access Token (for production or when OIDC unavailable)
# VERCEL_TEAM_ID=team_xxxxxxxxx # Your Vercel team ID
# VERCEL_PROJECT_ID=prj_xxxxxxxxx # Your Vercel project ID
# VERCEL_TOKEN=vercel_xxxxxxxxxxxx # Personal access token from Vercel dashboard
# Option 2: E2B Sandbox
# E2B_API_KEY=your_e2b_api_key # https://e2b.dev
```
--------------------------------
### Run Command in Sandbox (v1 - Vercel only)
Source: https://context7.com/firecrawl/open-lovable/llms.txt
Executes shell commands in the active sandbox environment using the v1 endpoint. This endpoint is specific to the Vercel sandbox.
```bash
curl -X POST http://localhost:3000/api/run-command \
-H "Content-Type: application/json" \
-d '{
"command": "npm run build"
}'
```
--------------------------------
### Sandbox Creation API
Source: https://context7.com/firecrawl/open-lovable/llms.txt
Endpoints for creating isolated sandbox environments for React application development.
```APIDOC
## POST /api/create-ai-sandbox-v2
### Description
Creates a new isolated sandbox environment with a pre-configured Vite + React + Tailwind CSS application. The sandbox provider is determined by the `SANDBOX_PROVIDER` environment variable (defaults to E2B).
### Method
POST
### Endpoint
/api/create-ai-sandbox-v2
### Response
#### Success Response (200)
- **success** (boolean) - Indicates if the sandbox creation was successful.
- **sandboxId** (string) - The unique identifier for the created sandbox.
- **url** (string) - The URL to access the sandbox environment.
- **provider** (string) - The sandbox provider used (e.g., 'e2b').
- **message** (string) - A confirmation message.
#### Response Example
```json
{
"success": true,
"sandboxId": "sandbox-abc123",
"url": "https://abc123.e2b.dev:5173",
"provider": "e2b",
"message": "Sandbox created and Vite React app initialized"
}
```
## POST /api/create-ai-sandbox
### Description
Creates a new isolated sandbox environment specifically for Vercel. This is a legacy endpoint.
### Method
POST
### Endpoint
/api/create-ai-sandbox
### Response
#### Success Response (200)
- **success** (boolean) - Indicates if the sandbox creation was successful.
- **sandboxId** (string) - The unique identifier for the created sandbox.
- **url** (string) - The URL to access the sandbox environment.
- **message** (string) - A confirmation message.
#### Response Example
```json
{
"success": true,
"sandboxId": "vercel-xyz789",
"url": "https://xyz789.vercel-sandbox.dev:3000",
"message": "Vercel sandbox created and Vite React app initialized"
}
```
```
--------------------------------
### Sandbox Provider Interface Definition
Source: https://context7.com/firecrawl/open-lovable/llms.txt
Defines the abstract interface for sandbox providers, outlining methods for file operations, command execution, and package management. Use this interface to implement custom sandbox providers.
```typescript
import { SandboxProvider, SandboxInfo, CommandResult } from '@/lib/sandbox/types';
// Provider interface methods
abstract class SandboxProvider {
// Create and initialize sandbox
abstract createSandbox(): Promise;
// Execute shell command
abstract runCommand(command: string): Promise;
// File operations
abstract writeFile(path: string, content: string): Promise;
abstract readFile(path: string): Promise;
abstract listFiles(directory?: string): Promise;
// Package management
abstract installPackages(packages: string[]): Promise;
// Sandbox lifecycle
abstract getSandboxUrl(): string | null;
abstract getSandboxInfo(): SandboxInfo | null;
abstract terminate(): Promise;
abstract isAlive(): boolean;
// Vite-specific operations
async setupViteApp(): Promise;
async restartViteServer(): Promise;
}
```
--------------------------------
### Sandbox Provider Factory
Source: https://context7.com/firecrawl/open-lovable/llms.txt
The SandboxFactory class abstracts sandbox creation across different providers (E2B and Vercel).
```APIDOC
## SandboxFactory Class
### Description
Abstracts sandbox creation across different providers (E2B and Vercel).
### Methods
- **create(provider?: 'e2b' | 'vercel')**: Creates a sandbox instance using the specified provider or the environment-configured provider.
- Returns: `{ sandboxId, url, provider, createdAt }`
- **getAvailableProviders()**: Returns a list of available sandbox providers.
- Returns: `['e2b', 'vercel']`
- **isProviderAvailable(provider: 'e2b' | 'vercel')**: Checks if the specified provider has the required credentials configured.
- Returns: `boolean`
### Usage Example (TypeScript)
```typescript
import { SandboxFactory } from '@/lib/sandbox/factory';
// Create sandbox using environment-configured provider
const provider = SandboxFactory.create();
const sandboxInfo = await provider.createSandbox();
// Returns: { sandboxId, url, provider, createdAt }
// Explicitly specify provider
const e2bProvider = SandboxFactory.create('e2b');
const vercelProvider = SandboxFactory.create('vercel');
// Check available providers
const providers = SandboxFactory.getAvailableProviders();
// Returns: ['e2b', 'vercel']
// Check if provider has required credentials
const e2bAvailable = SandboxFactory.isProviderAvailable('e2b');
// Checks for E2B_API_KEY env var
const vercelAvailable = SandboxFactory.isProviderAvailable('vercel');
// Checks for VERCEL_OIDC_TOKEN or (VERCEL_TOKEN + VERCEL_TEAM_ID + VERCEL_PROJECT_ID)
```
```
--------------------------------
### Check Provider Availability
Source: https://context7.com/firecrawl/open-lovable/llms.txt
Checks if a specific sandbox provider is available by verifying the presence of required environment variables. For E2B, it checks for E2B_API_KEY. For Vercel, it checks for VERCEL_OIDC_TOKEN or a combination of VERCEL_TOKEN, VERCEL_TEAM_ID, and VERCEL_PROJECT_ID.
```typescript
const e2bAvailable = SandboxFactory.isProviderAvailable('e2b');
// Checks for E2B_API_KEY env var
const vercelAvailable = SandboxFactory.isProviderAvailable('vercel');
// Checks for VERCEL_OIDC_TOKEN or (VERCEL_TOKEN + VERCEL_TEAM_ID + VERCEL_PROJECT_ID)
```
--------------------------------
### Generate AI Code Stream (New App)
Source: https://context7.com/firecrawl/open-lovable/llms.txt
Streams AI-generated React code for creating a new application based on a natural language prompt. Specify the desired model and sandbox context.
```bash
curl -X POST http://localhost:3000/api/generate-ai-code-stream \
-H "Content-Type: application/json" \
-d '{
"prompt": "Create a landing page with a hero section, features grid, and footer",
"model": "anthropic/claude-sonnet-4-20250514",
"context": {
"sandboxId": "sandbox-abc123"
},
"isEdit": false
}'
```
--------------------------------
### AI Code Generation API
Source: https://context7.com/firecrawl/open-lovable/llms.txt
Endpoints for streaming AI-generated React code based on natural language prompts, supporting both new application generation and existing application edits.
```APIDOC
## POST /api/generate-ai-code-stream
### Description
Streams AI-generated React code based on a natural language prompt. Supports multiple AI providers and includes intelligent edit detection for modifying existing applications.
### Method
POST
### Endpoint
/api/generate-ai-code-stream
### Parameters
#### Request Body
- **prompt** (string) - Required - The natural language prompt describing the desired code.
- **model** (string) - Required - The AI model to use for generation (e.g., 'anthropic/claude-sonnet-4-20250514').
- **context** (object) - Optional - Context for the generation.
- **sandboxId** (string) - Required if context is provided - The ID of the sandbox to use.
- **currentFiles** (object) - Optional - A map of file paths to their current content, used for edits.
- **isEdit** (boolean) - Required - A flag indicating whether this is an edit operation (true) or a new generation (false).
### Request Example
```json
{
"prompt": "Create a landing page with a hero section, features grid, and footer",
"model": "anthropic/claude-sonnet-4-20250514",
"context": {
"sandboxId": "sandbox-abc123"
},
"isEdit": false
}
```
### Response
#### Success Response (200)
This endpoint uses Server-Sent Events (SSE) to stream responses.
- **type** (string) - The type of event ('status' or 'stream' or 'complete').
- **message** (string) - Status message (for 'status' type).
- **text** (string) - Generated code snippet or file path (for 'stream' type).
- **raw** (boolean) - Indicates if the text is raw code (for 'stream' type).
- **type** (string) - The type of event ('component' for component data).
- **name** (string) - The name of the component.
- **path** (string) - The file path of the component.
- **index** (number) - The index of the component.
- **type** (string) - The type of event ('complete' for completion).
- **generatedCode** (string) - The complete generated code.
- **files** (number) - The total number of files generated.
- **components** (number) - The total number of components generated.
- **model** (string) - The AI model used for generation.
#### Response Example (SSE Stream)
```
data: {"type":"status","message":"Initializing AI..."}
data: {"type":"status","message":"Planning application structure..."}
data: {"type":"stream","text":"","raw":true}
data: {"type":"component","name":"Hero","path":"src/components/Hero.jsx","index":1}
data: {"type":"complete","generatedCode":"...","files":5,"components":4,"model":"anthropic/claude-sonnet-4-20250514"}
```
```
--------------------------------
### Generate AI Code Stream (Edit App)
Source: https://context7.com/firecrawl/open-lovable/llms.txt
Streams AI-generated code to edit an existing application. Provide the prompt, model, sandbox context, and current file contents for intelligent edits.
```bash
curl -X POST http://localhost:3000/api/generate-ai-code-stream \
-H "Content-Type: application/json" \
-d '{
"prompt": "Change the hero background color to blue and update the headline",
"model": "google/gemini-3-pro-preview",
"context": {
"sandboxId": "sandbox-abc123",
"currentFiles": {
"src/components/Hero.jsx": "function Hero() { return ...
}"
}
},
"isEdit": true
}'
```
--------------------------------
### Server-Sent Events Stream Response Format
Source: https://context7.com/firecrawl/open-lovable/llms.txt
Illustrates the format of Server-Sent Events (SSE) responses during AI code generation, including status updates, code streams, and completion details.
```text
data: {"type":"status","message":"Initializing AI..."}
data: {"type":"status","message":"Planning application structure..."}
data: {"type":"stream","text":"","raw":true}
data: {"type":"component","name":"Hero","path":"src/components/Hero.jsx","index":1}
data: {"type":"complete","generatedCode":"...","files":5,"components":4,"model":"anthropic/claude-sonnet-4-20250514"}
```
--------------------------------
### Scrape Website Content
Source: https://context7.com/firecrawl/open-lovable/llms.txt
Scrapes a website using Firecrawl to extract content in specified formats. Configure options like `onlyMainContent`, `waitFor`, and `timeout` for precise scraping.
```bash
curl -X POST http://localhost:3000/api/scrape-website \
-H "Content-Type: application/json" \
-d '{
"url": "https://example.com",
"formats": ["markdown", "html"],
"options": {
"onlyMainContent": true,
"waitFor": 2000,
"timeout": 30000
}
}'
```
--------------------------------
### Website Scraping API
Source: https://context7.com/firecrawl/open-lovable/llms.txt
Endpoint for scraping website content using Firecrawl, useful for cloning websites or content analysis.
```APIDOC
## POST /api/scrape-website
### Description
Scrapes a website using Firecrawl to extract content for website cloning or content analysis.
### Method
POST
### Endpoint
/api/scrape-website
### Parameters
#### Request Body
- **url** (string) - Required - The URL of the website to scrape.
- **formats** (array of strings) - Optional - The desired output formats (e.g., 'markdown', 'html'). Defaults to ['html'].
- **options** (object) - Optional - Scraping options.
- **onlyMainContent** (boolean) - Optional - If true, only extracts the main content of the page.
- **waitFor** (number) - Optional - Time in milliseconds to wait for the page to load.
- **timeout** (number) - Optional - Maximum time in milliseconds to wait for the scrape operation.
### Request Example
```json
{
"url": "https://example.com",
"formats": ["markdown", "html"],
"options": {
"onlyMainContent": true,
"waitFor": 2000,
"timeout": 30000
}
}
```
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.