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

# How to Remove Video Background | Guide

> Step-by-step guide to remove video backgrounds with AI. Learn SDK methods, API calls, and troubleshooting for professional video background removal.

## Choose Your Approach

There are two main ways to remove backgrounds from videos:

> [card] 🛠️ SDK Method
>
> **Best for**: Complete workflows, video composition
> **Language**: Node.js, Python
> **Features**: Automatic error handling, progress tracking

> [card] 🌐 Direct API
>
> **Best for**: Simple scripts, custom integrations
> **Language**: Any (HTTP requests)
> **Features**: Full control, webhook integration

## SDK Method (Recommended)

The easiest way to get started with background removal:

> [tab] Node.js
>
> ```typescript theme={"dark"}
> import { VideoBGRemoverClient, Video, RemoveBGOptions, Prefer } from '@videobgremover/sdk'
>
> const client = new VideoBGRemoverClient('vbr_your_api_key')
>
> // Load video from file or URL
> const video = Video.open('https://example.com/video.mp4')
>
> // Configure output format (optional)
> const options = new RemoveBGOptions(Prefer.WEBM_VP9)
>
> // Remove background (handles everything automatically)
> const transparent = await video.removeBackground({ client, options })
>
> console.log('Background removed! Download URL:', transparent.primaryPath)
> console.log('Format:', transparent.getFormat())
> ```

> [tab] Python
>
> ```python theme={"dark"}
> from videobgremover import VideoBGRemoverClient, Video, RemoveBGOptions, Prefer
> import os
>
> client = VideoBGRemoverClient(os.getenv('VIDEOBGREMOVER_API_KEY'))
>
> # Load video from file or URL
> video = Video.open('https://example.com/video.mp4')
>
> # Configure output format (optional)
> options = RemoveBGOptions(prefer=Prefer.WEBM_VP9)
>
> # Remove background (handles everything automatically)
> transparent = video.remove_background(client, options)
>
> print(f'Background removed! Download URL: {transparent.primary_path}')
> print(f'Format: {transparent.format}')
> ```

### SDK Features

* **Automatic Error Handling**: SDK catches and explains common errors
* **Progress Tracking**: Optional callbacks for processing status
* **Format Selection**: Easy format configuration
* **File Management**: Handles uploads and downloads automatically

## Direct API Method

For custom integrations and maximum control:

### URL Workflow

Perfect when your videos are already hosted online:

**1. Create Job from URL**

```json theme={"dark"}
POST /v1/jobs
{
  "video_url": "https://example.com/video.mp4"
}
```

**Response:** Job ID with `uploaded` status (ready to process)

**2. Start Processing**

```json theme={"dark"}
POST /v1/jobs/{id}/start
{
  "background": {
    "type": "transparent",
    "transparent_format": "webm_vp9"
  }
}
```

**Credits deducted here** based on video length

**3. Monitor & Download**

```bash theme={"dark"}
GET /v1/jobs/{id}/status
```

Poll until status is `completed`, then download from provided URLs

## Real-time Notifications with Webhooks

Instead of polling the status endpoint, get instant notifications when processing completes:

```typescript Node.js SDK theme={"dark"}
// Start processing with webhook notification
const result = await video.removeBackground({
  client,
  options: new RemoveBGOptions(Prefer.WEBM_VP9),
  webhookUrl: 'https://your-app.com/api/webhooks'
})

console.log('✅ Job started! Webhook will notify when complete')
```

```python Python SDK theme={"dark"}
# Start processing with webhook notification
result = video.remove_background(client, RemoveBGOptions(
    webhook_url='https://your-app.com/api/webhooks',
    background_type='transparent',
    transparent_format='webm_vp9'
))

print('✅ Job started! Webhook will notify when complete')
```

```bash cURL theme={"dark"}
curl -X POST https://api.videobgremover.com/v1/jobs/$JOB_ID/start \
  -H "X-Api-Key: $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "webhook_url": "https://your-app.com/api/webhooks",
    "background": {
      "type": "transparent",
      "transparent_format": "webm_vp9"
    }
  }'
```

**Webhook Payload:**

```json theme={"dark"}
{
  "event": "job.completed",
  "timestamp": "2025-10-02T10:30:00Z",
  "job": {
    "id": "550e8400-e29b-41d4-a716-446655440000",
    "status": "completed",
    "processed_video_url": "https://storage.googleapis.com/.../video.webm",
    // ... full job status (same as GET /v1/jobs/{id}/status)
  }
}
```

Your webhook endpoint must return a 2xx status code within 30 seconds. For delivery behavior and history, see the [webhook guide](https://docs.videobgremover.com/guides/webhooks.md).

### File Upload Workflow

For local video files:

**1. Create Job**

```json theme={"dark"}
POST /v1/jobs
{
  "filename": "my-video.mp4",
  "content_type": "video/mp4"
}
```

**Response:** Upload URL and job ID

**2. Upload Video**

```bash theme={"dark"}
PUT [upload_url]
Content-Type: video/mp4
[Raw video file bytes]
```

**Note:** This is a direct upload to cloud storage

**3. Start Processing**

```json theme={"dark"}
POST /v1/jobs/{id}/start
{
  "background": {
    "type": "transparent",
    "transparent_format": "webm_vp9"
  }
}
```

**Credits deducted here** based on video length

**4. Monitor & Download**

```bash theme={"dark"}
GET /v1/jobs/{id}/status
```

Poll until status is `completed`, then download from provided URLs

### Complete Examples

> [tab] cURL - URL Workflow
>
> ```bash theme={"dark"}
> # 1. Create job from URL
> JOB_RESPONSE=$(curl -s -X POST https://api.videobgremover.com/v1/jobs \
>   -H "X-Api-Key: $API_KEY" \
>   -H "Content-Type: application/json" \
>   -d '{"video_url": "https://example.com/video.mp4"}')
>
> JOB_ID=$(echo $JOB_RESPONSE | jq -r '.id')
>
> # 2. Start processing with color background
> curl -X POST https://api.videobgremover.com/v1/jobs/$JOB_ID/start \
>   -H "X-Api-Key: $API_KEY" \
>   -H "Content-Type: application/json" \
>   -d '{
>     "background": {
>       "type": "color",
>       "color": "#FF0000"
>     }
>   }'
>
> # 3. Check status
> curl -X GET https://api.videobgremover.com/v1/jobs/$JOB_ID/status \
>   -H "X-Api-Key: $API_KEY"
> ```

> [tab] cURL - File Upload Workflow
>
> ```bash theme={"dark"}
> # 1. Create job for file upload
> JOB_RESPONSE=$(curl -s -X POST https://api.videobgremover.com/v1/jobs \
>   -H "X-Api-Key: $API_KEY" \
>   -H "Content-Type: application/json" \
>   -d '{"filename": "my-video.mp4", "content_type": "video/mp4"}')
>
> JOB_ID=$(echo $JOB_RESPONSE | jq -r '.id')
> UPLOAD_URL=$(echo $JOB_RESPONSE | jq -r '.upload_url')
>
> # 2. Upload video file
> curl -X PUT "$UPLOAD_URL" \
>   -H "Content-Type: video/mp4" \
>   --data-binary @my-video.mp4
>
> # 3. Start processing with transparent background
> curl -X POST https://api.videobgremover.com/v1/jobs/$JOB_ID/start \
>   -H "X-Api-Key: $API_KEY" \
>   -H "Content-Type: application/json" \
>   -d '{
>     "background": {
>       "type": "transparent",
>       "transparent_format": "webm_vp9"
>     }
>   }'
>
> # 4. Check status
> curl -X GET https://api.videobgremover.com/v1/jobs/$JOB_ID/status \
>   -H "X-Api-Key: $API_KEY"
> ```

> [tab] Node.js SDK - URL Workflow
>
> ```typescript theme={"dark"}
> import { VideoBGRemoverClient, Video } from '@videobgremover/sdk'
>
> const client = new VideoBGRemoverClient('vbr_your_api_key')
> const video = Video.open('https://example.com/video.mp4')
>
> const transparent = await video.removeBackground({ client })
>
> console.log('Background removed! Download URL:', transparent.primaryPath)
> console.log('Format:', transparent.getFormat())
> ```

> [tab] Node.js SDK - File Workflow
>
> ```typescript theme={"dark"}
> import { VideoBGRemoverClient, Video } from '@videobgremover/sdk'
>
> const client = new VideoBGRemoverClient('vbr_your_api_key')
> const video = Video.open('path/to/local/video.mp4')
>
> const transparent = await video.removeBackground({ client })
>
> console.log('Background removed! Download URL:', transparent.primaryPath)
> console.log('Format:', transparent.getFormat())
> ```

> [tab] Python SDK - URL Workflow
>
> ```python theme={"dark"}
> from videobgremover import VideoBGRemoverClient, Video
> import os
>
> client = VideoBGRemoverClient(os.getenv('VIDEOBGREMOVER_API_KEY'))
> video = Video.open(src='https://example.com/video.mp4')
>
> transparent = video.remove_background(client)
>
> print(f'Background removed! Download URL: {transparent.primary_path}')
> print(f'Format: {transparent.format}')
> ```

> [tab] Python SDK - File Workflow
>
> ```python theme={"dark"}
> from videobgremover import VideoBGRemoverClient, Video
> import os
>
> client = VideoBGRemoverClient(os.getenv('VIDEOBGREMOVER_API_KEY'))
> video = Video.open(src='path/to/local/video.mp4')
>
> transparent = video.remove_background(client)
>
> print(f'Background removed! Download URL: {transparent.primary_path}')
> print(f'Format: {transparent.format}')
> ```

## Error Handling

### Common Issues

> [tab] Insufficient Credits
>
> ```typescript theme={"dark"}
> try {
>   const transparent = await video.removeBackground({ client })
> } catch (error) {
>   if (error.message.includes('credits')) {
>     console.log('❌ Not enough credits. Please top up your account.')
>   }
> }
> ```
>
> ```python theme={"dark"}
> try:
>     transparent = video.remove_background(client)
> except Exception as e:
>     if 'credits' in str(e).lower():
>         print('❌ Not enough credits. Please top up your account.')
> ```

> [tab] Invalid API Key
>
> ```typescript theme={"dark"}
> try {
>   const transparent = await video.removeBackground({ client })
> } catch (error) {
>   if (error.message.includes('API key')) {
>     console.log('❌ Invalid API key. Check your credentials.')
>   }
> }
> ```
>
> ```python theme={"dark"}
> try:
>     transparent = video.remove_background(client)
> except Exception as e:
>     if 'api key' in str(e).lower():
>         print('❌ Invalid API key. Check your credentials.')
> ```

> [tab] File Too Large
>
> ```bash theme={"dark"}
> # Check file size before processing
> FILE_SIZE=$(stat -f%z video.mp4 2>/dev/null || stat -c%s video.mp4)
> MAX_SIZE=$((100*1024*1024)) # 100MB in bytes
>
> if [ "$FILE_SIZE" -gt "$MAX_SIZE" ]; then
>   echo "❌ File too large: $FILE_SIZE bytes (max: $MAX_SIZE)"
>   exit 1
> fi
> ```

### API-Specific Errors

| Error Code | Description | Solution |
| - | - | - |
| `401` | Invalid API key | Check key format and permissions |
| `402` | Insufficient credits | Top up your account |
| `413` | File too large | Reduce file size or use URL workflow |
| `404` | Job not found | Verify job ID and API key match |
| `422` | Invalid parameters | Check request format |

## Background Options with cURL

Here are the correct cURL commands for different background types:

> [tab] Color Backgrounds
>
> ```bash theme={"dark"}
> # Choose one color for this job. Replace #FF0000 with another hex color if needed.
> curl -X POST https://api.videobgremover.com/v1/jobs/$JOB_ID/start \
>   -H "X-Api-Key: $API_KEY" \
>   -H "Content-Type: application/json" \
>   -d '{
>     "background": {
>       "type": "color",
>       "color": "#FF0000"
>     }
>   }'
> ```

> [tab] Transparent Backgrounds
>
> ```bash theme={"dark"}
> # Choose one format for this job. Other values include mov_prores and stacked_video.
> curl -X POST https://api.videobgremover.com/v1/jobs/$JOB_ID/start \
>   -H "X-Api-Key: $API_KEY" \
>   -H "Content-Type: application/json" \
>   -d '{
>     "background": {
>       "type": "transparent",
>       "transparent_format": "webm_vp9"
>     }
>   }'
> ```

## Format Selection

Choose the format that best fits your workflow:

| Format | Best For | File Size | SDK Support |
| - | - | - | - |
| **WebM VP9** | Web apps, APIs | Small | ✅ Full support |
| **MOV ProRes** | Professional editing | Large | ✅ Full support |
| **Stacked Video** | Universal compatibility | Medium | ✅ Full support |
| **Pro Bundle** | Advanced workflows | Medium | ✅ Full support |
| **PNG Sequence** | Frame-by-frame work | Large | ✅ Full support |

**Note**: For detailed technical usage of each format, see the [Output Formats Guide](https://docs.videobgremover.com/video-background-removal/output-formats.md).

## Performance Tips

### For Large Files

* Keep each input within the current 1 GB limit
* Use the signed-upload workflow for local files and the URL workflow for publicly accessible remote files
* Consider reducing resolution when the source exceeds your output requirements

### For Batch Processing

* Keep concurrency within the limits for your endpoint and account
* Implement retry logic for network issues
* Monitor credit usage to avoid depletion

### For Production Use

* Use webhooks for real-time notifications (see above)
* Use background threads for processing
* Implement proper error handling and retry logic
* Store job IDs for status tracking
* Monitor your credit usage and balance

## What's Next?

> [card] [🎨 Add Custom Backgrounds](https://docs.videobgremover.com/video-composition/backgrounds.md)
>
> Layer your transparent video with colors, images, or videos

> [card] [📖 Output Formats Guide](https://docs.videobgremover.com/video-background-removal/output-formats.md)
>
> Technical details for using different transparent video formats


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.