Skip to content
Back

AI Generation

AI-powered folio creation and co-authoring — generate folios from prompts, stream AI completions, and use tool-augmented generation.

Overview

LiveFolio provides three AI endpoints for different generation workflows:

EndpointUse case
POST /api/files/ai-createCreate a brand-new folio from a natural language prompt
POST /api/files/{id}/aiCo-author an existing folio with AI (conversation + tool use)
POST /api/files/{id}/ai-streamStreaming AI co-authoring with real-time text output

All AI endpoints require authentication. In Cloud mode, they count against your workspace's monthly message quota and are subject to storage limits.

AI Create (New Folio)

POST /api/files/ai-create
Authorization: Bearer lf_live_xxxxxxxxxxxx
Content-Type: application/json

Creates a complete folio from a natural language description. The AI classifies the project mode, generates a title, and produces a production-ready index.html.

Availability: Cloud mode only. OSS users should use the MCP server for AI folio creation.

Request Body:

FieldTypeRequiredDescription
promptstringYesNatural language description of the desired folio
modelstringNoOverride the managed AI model (OSS only)
apiKeystringNoBring your own API key (OSS only)
designPreferencesobjectNoTheme, typography, palette, libraries
titlestringNoOverride the AI-generated title
isPrivatebooleanNoRequire access key
accessKeystringNoPassword for private folios
allowCommentsbooleanNoEnable comments (default: true)
presentationModeOnlybooleanNoFullscreen mode only
referenceFilesarrayNoReference documents for AI context
statusstringNodraft or published

Example Request:

curl -X POST https://livefolio.cloud/api/files/ai-create \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer lf_live_xxxxxxxxxxxx" \
  -d '{
    "prompt": "Create a startup pitch deck for an AI-powered gardening app called GrowSync. Include problem slide, solution, market size, traction, and team.",
    "designPreferences": {
      "theme": "Premium SaaS Deck",
      "palette": "Sage Forest"
    }
  }'

Response (201):

{
  "project": {
    "id": "a1b2c3d",
    "title": "GrowSync Pitch Deck",
    "description": "Startup pitch deck for AI-powered gardening app",
    "projectMode": "deck",
    "createdAt": "2025-06-20T14:22:00.000Z"
  }
}

The folio is created with index.html containing the generated content and an AI-generated title/description.

Error Responses:

StatusErrorDescription
400A non-empty prompt is required.Missing or empty prompt
400No AI model configured.No provider available
401UnauthorizedNo valid auth context
402STORAGE_EXCEEDEDOver storage quota
403Endpoint not available in OSSOSS mode restriction
500AI failed to generate HTML content.Generation produced no output
500AI is not configured for this workspace.No API keys configured

AI Co-Author (Existing Folio)

POST /api/files/{id}/ai
Authorization: Bearer lf_live_xxxxxxxxxxxx
Content-Type: application/json

The primary AI interaction endpoint. Supports multiple actions:

  • Conversational generation — chat with AI about your folio
  • Commit proposals — apply AI-suggested file changes as new versions
  • Tool execution — web search, web fetch, element editing, page management
  • Clear chat — reset conversation history

Action: Conversational Generation (default)

Send a user prompt and receive AI analysis, suggestions, or code changes.

Fields:

FieldTypeRequiredDescription
userPromptstringYesThe user's message or instruction
chatHistoryarrayNoPrevious messages for context
pageContextstringNo"Whole Project" or "Current Screen" (default: Whole Project)
activeFilenamestringNoActive file when pageContext is "Current Screen"
targetVersionIdstringNoVersion to base changes on (default: latest)
designSystemobjectNoOverride design preferences for this request
selectedModelstringNoAI model to use
apiKeystringNoBring your own API key
ollamaHoststringNoOllama host URL (for local models)
targetedElementobjectNoElement to surgically edit ({selector, tagName, outerHTML})
attachedFilesarrayNoReference files for this prompt
executeImmediatelybooleanNoAuto-commit changes as a new version
simulatedAuthorstringNoAuthor name for auto-committed versions

Example — Chat with AI:

curl -X POST https://livefolio.cloud/api/files/a1b2c3d/ai \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer lf_live_xxxxxxxxxxxx" \
  -d '{
    "userPrompt": "Make the hero section more impactful with a gradient background"
  }'

Response (planning mode — no auto-commit):

{
  "success": true,
  "explanation": "I will update the hero section with a gradient background that transitions from deep indigo to teal...",
  "isProposal": true,
  "proposedFiles": {
    "index.html": "<!DOCTYPE html>...updated..."
  }
}

Response (with tool calls — Cloud mode):

When the AI uses tools (web search, web fetch, etc.), the response includes tool call metadata:

{
  "success": true,
  "explanation": "I found the latest stats and updated the market size slide...",
  "toolCalls": [
    {
      "id": "call_abc123",
      "name": "web_search",
      "arguments": { "query": "AI gardening market size 2025" },
      "status": "done"
    }
  ]
}

Action: Commit Proposal

Apply AI-proposed file changes as a new version.

curl -X POST https://livefolio.cloud/api/files/a1b2c3d/ai \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer lf_live_xxxxxxxxxxxx" \
  -d '{
    "action": "commit-proposal",
    "proposedFiles": {
      "index.html": "<!DOCTYPE html>...updated..."
    },
    "proposedExplanation": "Updated hero section with gradient",
    "simulatedAuthor": "AI Co-pilot"
  }'

Response:

{
  "success": true,
  "newVersionId": "v5",
  "project": { ... }
}

Action: Clear Chat

Reset the conversation history for a folio.

curl -X POST https://livefolio.cloud/api/files/a1b2c3d/ai \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer lf_live_xxxxxxxxxxxx" \
  -d '{"action": "clear-chat"}'

Response:

{
  "success": true,
  "project": { ... }
}

Action: Tool Response

Feed tool execution results back to the AI for follow-up. Used by the client when tool calls require client-side execution.

Error Responses

StatusErrorDescription
400Various validation errorsMissing required fields or invalid input
401UnauthorizedNo valid auth context
402QUOTA_EXCEEDEDMonthly AI prompt limit reached
402STORAGE_EXCEEDEDOver storage quota
404Project not foundFolio does not exist

AI Stream (Real-Time)

POST /api/files/{id}/ai-stream
Authorization: Bearer lf_live_xxxxxxxxxxxx
Content-Type: application/json

Streaming variant of the AI co-author endpoint. Returns Server-Sent Events (SSE) with real-time text chunks as the AI generates.

Request Body: Same as the conversational generation action of /api/files/{id}/ai.

Response: SSE stream (text/event-stream).

SSE Event Types:

TypeDescription
statusProgress update (e.g., "Synthesizing design strategy...")
chunkText tokens streaming in real-time
doneGeneration complete with full result
errorError during generation

Example — Consume the stream:

const response = await fetch('https://livefolio.cloud/api/files/a1b2c3d/ai-stream', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer lf_live_xxxxxxxxxxxx'
  },
  body: JSON.stringify({
    userPrompt: 'Add a pricing table with three tiers',
    executeImmediately: true
  })
});

const reader = response.body.getReader();
const decoder = new TextDecoder();

while (true) {
  const { done, value } = await reader.read();
  if (done) break;
  const text = decoder.decode(value);
  const lines = text.split('\n');
  for (const line of lines) {
    if (line.startsWith('data: ')) {
      const event = JSON.parse(line.slice(6));
      switch (event.type) {
        case 'chunk':
          process.stdout.write(event.text); // Stream text to console
          break;
        case 'done':
          console.log('\nComplete!', event.explanation);
          break;
        case 'error':
          console.error('Error:', event.message);
          break;
      }
    }
  }
}

Note: The streaming endpoint is Gemini-only and uses a two-stage pipeline (planning + generation) for higher quality output.