> ## Documentation Index
> Fetch the complete documentation index at: https://docs.babou.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Start Export

> Export a video project to a downloadable video file

## Overview

Starts the export process for a complete video project. All chapters are rendered and combined into a single video file. The export typically takes 2-5 minutes depending on project complexity.

<Warning>
  Ensure all chapter prompts have completed processing before exporting. The export will only include completed chapters.
</Warning>

## Request

### Path Parameters

<ParamField path="projectId" type="string" required>
  The project ID to export
</ParamField>

### Headers

<ParamField header="Authorization" type="string" required>
  Bearer token with your API key
</ParamField>

## Response

<ResponseField name="status" type="string">
  Export status: `queued`, `processing`, `completed`, or `failed`
</ResponseField>

<ResponseField name="message" type="string">
  Human-readable status message
</ResponseField>

<ResponseField name="estimated_time" type="string">
  Estimated completion time (e.g., "2-5 minutes")
</ResponseField>

## Examples

<CodeGroup>
  ```bash curl theme={null}
  curl -X POST https://api.babou.ai/api/v1/projects/prj_abc123xyz/export \
    -H "Authorization: Bearer $BABOU_API_KEY"
  ```

  ```typescript TypeScript theme={null}
  async function startExport(projectId: string) {
    const response = await fetch(
      `https://api.babou.ai/api/v1/projects/${projectId}/export`,
      {
        method: 'POST',
        headers: {
          'Authorization': `Bearer ${process.env.BABOU_API_KEY}`
        }
      }
    );

    if (!response.ok) {
      const error = await response.json();
      throw new Error(`Export failed: ${error.error}`);
    }

    const result = await response.json();
    console.log(`Export started: ${result.status}`);
    console.log(`Estimated time: ${result.estimated_time}`);
    return result;
  }

  await startExport('prj_abc123xyz');
  ```

  ```python Python theme={null}
  import os
  import requests

  def start_export(project_id):
      response = requests.post(
          f'https://api.babou.ai/api/v1/projects/{project_id}/export',
          headers={'Authorization': f'Bearer {os.environ["BABOU_API_KEY"]}'}
      )

      if not response.ok:
          error = response.json()
          raise Exception(f'Export failed: {error["error"]}')

      result = response.json()
      print(f'Export started: {result["status"]}')
      print(f'Estimated time: {result["estimated_time"]}')
      return result

  start_export('prj_abc123xyz')
  ```
</CodeGroup>

## Response Example

```json theme={null}
{
  "status": "queued",
  "message": "Export started",
  "estimated_time": "2-5 minutes"
}
```

## Error Responses

<ResponseField name="CONFLICT" type="409">
  Export already in progress for this project

  ```json theme={null}
  {
    "error": "An export is already in progress for this project",
    "code": "CONFLICT",
    "hint": "Wait for the current export to complete or check its status"
  }
  ```
</ResponseField>

<ResponseField name="NOT_FOUND" type="404">
  Project not found

  ```json theme={null}
  {
    "error": "Project not found",
    "code": "NOT_FOUND"
  }
  ```
</ResponseField>

<ResponseField name="VALIDATION_ERROR" type="400">
  Project has no completed chapters to export

  ```json theme={null}
  {
    "error": "Project has no completed chapters",
    "code": "VALIDATION_ERROR",
    "hint": "Add chapters and submit prompts before exporting"
  }
  ```
</ResponseField>

## Best Practices

<AccordionGroup>
  <Accordion title="Verify chapters are ready before exporting">
    Check that all chapters have completed processing:

    ```typescript theme={null}
    async function ensureChaptersReady(projectId: string) {
      const { chapters } = await listChapters(projectId);

      if (chapters.length === 0) {
        throw new Error('Project has no chapters');
      }

      for (const chapter of chapters) {
        const fullChapter = await getChapter(projectId, chapter.id);
        const latestPrompt = fullChapter.prompts?.[fullChapter.prompts.length - 1];

        if (!latestPrompt || latestPrompt.status !== 'completed') {
          throw new Error(`Chapter "${chapter.name}" is not ready for export`);
        }
      }

      return true;
    }

    // Use before exporting
    await ensureChaptersReady('prj_abc123xyz');
    await startExport('prj_abc123xyz');
    ```
  </Accordion>

  <Accordion title="Handle existing exports">
    If an export is already in progress, wait for it to complete:

    ```typescript theme={null}
    async function startExportSafe(projectId: string) {
      try {
        return await startExport(projectId);
      } catch (error: any) {
        if (error.message.includes('already in progress')) {
          console.log('Export already running, checking status...');
          return await getExportStatus(projectId);
        }
        throw error;
      }
    }
    ```
  </Accordion>

  <Accordion title="Poll for completion">
    After starting an export, poll the status endpoint:

    ```python theme={null}
    import time

    def wait_for_export(project_id, max_wait=600):
        """Wait up to 10 minutes for export to complete"""
        start_export(project_id)

        start_time = time.time()
        while time.time() - start_time < max_wait:
            status = get_export_status(project_id)

            if status['status'] == 'completed':
                print(f'✓ Export complete: {status["download_url"]}')
                return status

            if status['status'] == 'failed':
                raise Exception('Export failed')

            print(f'Still processing... ({status["status"]})')
            time.sleep(10)  # Check every 10 seconds

        raise Exception('Export timeout')
    ```
  </Accordion>
</AccordionGroup>

## Next Steps

<CardGroup cols={2}>
  <Card title="Get Export Status" icon="circle-check" href="/api-reference/exports/status">
    Check export progress and get download URL
  </Card>

  <Card title="List Chapters" icon="list" href="/api-reference/chapters/list">
    View chapters included in the export
  </Card>
</CardGroup>
