Skip to main content

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.

Overview

The VideoBGRemoverClient handles all communication with the VideoBGRemover API for background removal operations. This is the API layer of the SDK - it handles authentication, job management, and credit tracking.
API Layer: This class makes HTTP requests to our servers and consumes credits. For local video composition (no credits), see Composition.

Constructor

import { VideoBGRemoverClient } from '@videobgremover/sdk'

// Basic initialization
const client = new VideoBGRemoverClient('vbr_your_api_key')

// With custom options
const client = new VideoBGRemoverClient('vbr_your_api_key', {
  baseUrl: 'https://api.videobgremover.com', // Custom API endpoint
  timeout: 60000, // 60 second timeout
  headers: { 'Custom-Header': 'value' }
})

Parameters

ParameterTypeDescription
api_keystringYour VideoBGRemover API key (format: vbr_ + 32 characters)
options.baseUrlstringAPI base URL (default: production)
options.timeoutnumberRequest timeout in milliseconds (Node.js) or seconds (Python)
options.headersobjectAdditional HTTP headers

Methods

credits()

Check your current credit balance.
const credits = await client.credits()

console.log(`Total: ${credits.totalCredits}`)
console.log(`Remaining: ${credits.remainingCredits}`)
console.log(`Used: ${credits.usedCredits}`)
Returns: Promise<Credits>
interface Credits {
  totalCredits: number
  remainingCredits: number
  usedCredits: number
}

Low-Level API Methods

These methods provide direct access to the REST API. Most users should use the high-level Video.removeBackground() method instead.

createJobFile()

Create a job for file upload.
const job = await client.createJobFile({
  filename: 'my-video.mp4',
  content_type: 'video/mp4'
})

console.log('Job ID:', job.id)
console.log('Upload URL:', job.upload_url)
console.log('Expires:', job.expires_at)

createJobUrl()

Create a job for URL download.
const job = await client.createJobUrl({
  video_url: 'https://example.com/video.mp4'
})

console.log('Job ID:', job.id)
// Video downloads automatically

startJob()

Start processing a job.
// Start with default settings (green screen)
const result = await client.startJob(jobId)

// Start with transparent output
const result = await client.startJob(jobId, {
  background: {
    type: 'transparent',
    transparent_format: 'webm_vp9'
  }
})

// Start with color background
const result = await client.startJob(jobId, {
  background: {
    type: 'color',
    color: '#FF0000'
  }
})

status()

Check job processing status.
const status = await client.status(jobId)

console.log('Status:', status.status) // 'created', 'processing', 'completed', 'failed'
console.log('Message:', status.message)

if (status.status === 'completed') {
  console.log('Download URL:', status.processed_video_url)
}

wait()

Wait for a job to complete with polling.
// Wait with default settings
const finalStatus = await client.wait(jobId)

// Wait with custom options
const finalStatus = await client.wait(jobId, {
  pollSeconds: 3.0,     // Check every 3 seconds
  timeout: 300,         // 5 minute timeout
  onStatus: (status) => {
    console.log(`Current status: ${status}`)
  }
})

deleteJob()

Delete a job and all associated files.
This action is permanent and cannot be undone. No credit refunds are provided.
const result = await client.deleteJob(jobId)

console.log('Deleted:', result.id)
console.log('Message:', result.message)
Returns: { id: string, message: string }
FieldTypeDescription
idstringID of the deleted job
messagestringConfirmation message

Error Handling

The client throws specific exceptions for different error conditions:
import { 
  ApiError, 
  InsufficientCreditsError, 
  JobNotFoundError, 
  ProcessingError 
} from '@videobgremover/sdk'

try {
  const transparent = await video.removeBackground({ client })
} catch (error) {
  if (error instanceof InsufficientCreditsError) {
    console.log('❌ Not enough credits')
    console.log('Remaining:', error.remainingCredits)
  } else if (error instanceof JobNotFoundError) {
    console.log('❌ Job not found')
  } else if (error instanceof ProcessingError) {
    console.log('❌ Processing failed:', error.message)
  } else if (error instanceof ApiError) {
    console.log('❌ API error:', error.message)
  }
}

Usage with Video Class

The recommended way to use the client is through the Video class:
import { VideoBGRemoverClient, Video, RemoveBGOptions, Prefer } from '@videobgremover/sdk'

const client = new VideoBGRemoverClient('your_api_key')
const video = Video.open('path/to/video.mp4')

// High-level method (recommended)
const transparent = await video.removeBackground({ client })

// With options
const options = new RemoveBGOptions(Prefer.WEBM_VP9)
const transparent = await video.removeBackground({ client, options })

Best Practices

Credit Management

// Always check credits before processing
const credits = await client.credits()
if (credits.remainingCredits < videoLengthInSeconds) {
  throw new Error('Not enough credits for this video')
}

Error Recovery

// Implement retry logic for network issues
async function removeBackgroundWithRetry(video, client, maxRetries = 3) {
  for (let i = 0; i < maxRetries; i++) {
    try {
      return await video.removeBackground({ client })
    } catch (error) {
      if (error instanceof InsufficientCreditsError) {
        throw error // Don't retry credit issues
      }
      if (i === maxRetries - 1) throw error
      await new Promise(resolve => setTimeout(resolve, 1000 * (i + 1)))
    }
  }
}

Timeout Handling

// Use appropriate timeouts for long videos
const client = new VideoBGRemoverClient('your_key', {
  timeout: 120000 // 2 minutes for long videos
})