@poof-bg/js 1.0.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -12,22 +12,53 @@ interface PoofOptions {
12
12
  }
13
13
  /** Output image format */
14
14
  type ImageFormat = 'png' | 'jpg' | 'webp';
15
+ /** Output video format: VP9 WebM (alpha or opaque), ProRes MOV (alpha or opaque) or H.264 MP4 (opaque) */
16
+ type VideoFormat = 'webm' | 'mov' | 'mp4';
15
17
  /** Output color channels */
16
- type Channels = 'rgba' | 'rgb';
18
+ type Channels = 'rgba' | 'rgb' | 'alpha';
17
19
  /** Output image size preset */
18
- type ImageSize = 'full' | 'preview' | 'small' | 'medium' | 'large';
20
+ type ImageSize = 'full' | 'preview' | 'medium' | 'hd';
21
+ /**
22
+ * How the image is fitted into a fixed width/height (never stretched):
23
+ * 'contain' scales to fit inside and pads the rest, 'cover' scales to fill and
24
+ * crops the overflow around the subject, 'scale-down' is contain without ever
25
+ * enlarging a smaller image.
26
+ */
27
+ type FitMode = 'contain' | 'cover' | 'scale-down';
28
+ /** Options for waiting on a video job */
29
+ interface WaitForJobOptions {
30
+ /** Delay between status polls in milliseconds (default: 3000) */
31
+ pollIntervalMs?: number;
32
+ /** Give up after this many milliseconds (default: 600000, i.e. 10 minutes) */
33
+ timeoutMs?: number;
34
+ /** Called after every poll with the latest job state */
35
+ onProgress?: (job: Job) => void;
36
+ }
19
37
  /** Options for background removal */
20
38
  interface RemoveBackgroundOptions {
21
- /** Output format (default: png) */
22
- format?: ImageFormat;
23
- /** Color channels - rgba for transparency, rgb for opaque (default: rgba) */
39
+ /** Output format: png, jpg or webp for images (default: png); webm, mov or mp4 for videos (default: webm) */
40
+ format?: ImageFormat | VideoFormat;
41
+ /** Color channels - rgba for transparency, rgb for opaque, alpha for the grayscale mask only (default: rgba) */
24
42
  channels?: Channels;
25
- /** Background color (hex, rgb, or color name). Only applies when channels is 'rgb' */
43
+ /** Background color (hex, rgb, or color name). Applies when channels is 'rgb' or 'rgba' */
26
44
  bgColor?: string;
27
45
  /** Output size preset (default: full) */
28
46
  size?: ImageSize;
29
- /** Crop to subject bounds (default: false) */
30
- crop?: boolean;
47
+ /** Crop to subject bounds: true/false or an aspect ratio like '1:1', '4:3', '16:9' (default: false) */
48
+ crop?: boolean | string;
49
+ /** Padding around the subject when crop is enabled, as a fraction ('0.1') or percentage ('10%') */
50
+ padding?: string;
51
+ /** Output width in pixels (1-6000). On its own, the height follows the aspect ratio. Overrides size */
52
+ width?: number;
53
+ /** Output height in pixels (1-6000). On its own, the width follows the aspect ratio. Overrides size */
54
+ height?: number;
55
+ /** How to fit into width x height without stretching (default: contain) */
56
+ fit?: FitMode;
57
+ /**
58
+ * Videos only: wait for the job to finish and return the completed Job
59
+ * instead of the queued one. Pass an object to tune polling.
60
+ */
61
+ wait?: boolean | WaitForJobOptions;
31
62
  }
32
63
  /** Metadata returned with processed images */
33
64
  interface ProcessingMetadata {
@@ -41,6 +72,16 @@ interface ProcessingMetadata {
41
72
  height: number;
42
73
  /** Content type of the result */
43
74
  contentType: string;
75
+ /**
76
+ * Confidence in the alpha matte, 0-1. 1 means a fully decisive mask; lower
77
+ * values mean the model hedged. Heuristic, not a calibrated probability.
78
+ */
79
+ matteConfidence?: number;
80
+ /**
81
+ * Fraction of pixels with alpha between 0.1 and 0.9, 0-1. High values
82
+ * indicate large uncertain regions - useful for flagging results for review.
83
+ */
84
+ matteAmbiguousRatio?: number;
44
85
  }
45
86
  /** Result of background removal including image data and metadata */
46
87
  interface RemoveBackgroundResult {
@@ -49,6 +90,59 @@ interface RemoveBackgroundResult {
49
90
  /** Processing metadata */
50
91
  metadata: ProcessingMetadata;
51
92
  }
93
+ /** State of a video job */
94
+ type JobStatus = 'queued' | 'processing' | 'completed' | 'failed';
95
+ /** Why a video job failed */
96
+ interface JobError {
97
+ /** Machine-readable error code, e.g. processing_failed */
98
+ code: string;
99
+ /** Human-readable description */
100
+ message: string;
101
+ }
102
+ /**
103
+ * A video background removal job. Returned with status 'queued' when a video
104
+ * is submitted; poll with getJob() or waitForJob() until it is 'completed'.
105
+ */
106
+ interface Job {
107
+ /** Job ID, prefixed with job_ */
108
+ id: string;
109
+ /** queued and processing are transient; completed and failed are terminal */
110
+ status: JobStatus;
111
+ /** Fraction of the video processed so far, 0 to 1 */
112
+ progress: number;
113
+ /** When the job was accepted (ISO 8601) */
114
+ createdAt: string;
115
+ /** When processing began; null while queued */
116
+ startedAt: string | null;
117
+ /** When the job reached completed or failed; null until then */
118
+ completedAt: string | null;
119
+ /** Source video duration in seconds */
120
+ durationSeconds: number;
121
+ /** Source frame rate */
122
+ fps: number;
123
+ /** Source video width in pixels */
124
+ width: number;
125
+ /** Source video height in pixels */
126
+ height: number;
127
+ /** Number of frames in the source video */
128
+ frames: number;
129
+ /** Credits charged for this job (5 per second of video, 10 above 30 fps); refunded if it fails */
130
+ credits: number;
131
+ /** Requested output format */
132
+ format: VideoFormat;
133
+ /** Requested output channels */
134
+ channels: Channels;
135
+ /** URL of the job; GET it to poll for progress */
136
+ statusUrl: string;
137
+ /** Direct download URL of the result on the Poof CDN once completed, null before that. No API key needed */
138
+ resultUrl: string | null;
139
+ /** When the result is deleted, 24 hours after completion; null until completed */
140
+ expiresAt: string | null;
141
+ /** Set when status is failed, null otherwise */
142
+ error: JobError | null;
143
+ /** Processing statistics once completed (output_width, output_height, processing_seconds, ...), null before */
144
+ stats: Record<string, unknown> | null;
145
+ }
52
146
  /** Account information */
53
147
  interface AccountInfo {
54
148
  /** Your organization ID */
@@ -63,7 +157,7 @@ interface AccountInfo {
63
157
  autoRechargeThreshold: number | null;
64
158
  }
65
159
  /** Error codes returned by the API */
66
- type ErrorCode = 'authentication_error' | 'permission_denied' | 'payment_required' | 'rate_limit_exceeded' | 'validation_error' | 'missing_image' | 'image_too_large' | 'upstream_error' | 'internal_server_error';
160
+ type ErrorCode = 'authentication_error' | 'permission_denied' | 'payment_required' | 'rate_limit_exceeded' | 'validation_error' | 'missing_image' | 'image_too_large' | 'invalid_image' | 'video_too_large' | 'video_too_long' | 'invalid_video' | 'job_not_found' | 'job_failed' | 'upstream_error' | 'internal_server_error';
67
161
  /** API error response structure */
68
162
  interface ApiErrorResponse {
69
163
  code: ErrorCode;
@@ -71,8 +165,14 @@ interface ApiErrorResponse {
71
165
  details?: string;
72
166
  request_id: string;
73
167
  }
74
- /** Valid input types for image processing */
168
+ /** Valid input types for image and video processing: file contents, or a file path in Node.js */
75
169
  type ImageInput = File | Blob | ArrayBuffer | Buffer | Uint8Array | string;
170
+ /** A publicly reachable https URL that Poof downloads instead of an upload (images up to 20 MB, videos up to 500 MB) */
171
+ interface UrlInput {
172
+ url: string;
173
+ }
174
+ /** Anything removeBackground() accepts: file contents, a file path (Node.js) or `{ url }` */
175
+ type MediaInput = ImageInput | UrlInput;
76
176
 
77
177
  /**
78
178
  * Poof API client for background removal
@@ -91,34 +191,71 @@ declare class Poof {
91
191
  private readonly timeout;
92
192
  constructor(options: PoofOptions);
93
193
  /**
94
- * Remove background from an image
194
+ * Remove the background from an image or a video.
195
+ *
196
+ * Images are processed synchronously and come back as bytes. Videos are
197
+ * processed as a job: the call returns a queued {@link Job}; poll it with
198
+ * {@link getJob} / {@link waitForJob}, or pass `wait: true` to get the
199
+ * completed job (with `resultUrl`) directly. Use {@link isJob} to tell the
200
+ * two apart.
95
201
  *
96
- * @param input - Image input: File, Blob, Buffer, ArrayBuffer, Uint8Array, or file path (Node.js)
202
+ * @param input - File, Blob, Buffer, ArrayBuffer, Uint8Array, file path (Node.js), or `{ url }`
97
203
  * @param options - Processing options
98
- * @returns Processed image data and metadata
204
+ * @returns Processed image data and metadata, or a video Job
99
205
  *
100
206
  * @example
101
207
  * ```typescript
102
- * // Basic usage
208
+ * // Image
103
209
  * const result = await poof.removeBackground(file);
104
210
  * const imageBlob = new Blob([result.data], { type: result.metadata.contentType });
105
211
  *
106
212
  * // With options
107
- * const result = await poof.removeBackground(file, {
108
- * format: 'webp',
109
- * crop: true,
110
- * size: 'medium'
111
- * });
213
+ * const result = await poof.removeBackground(file, { format: 'webp', crop: true, size: 'medium' });
112
214
  *
113
- * // Node.js: from file path
114
- * const result = await poof.removeBackground('/path/to/image.png');
215
+ * // Exact 500x500 output, subject cropped and centred, never stretched
216
+ * const result = await poof.removeBackground(file, { crop: true, width: 500, height: 500 });
115
217
  *
116
- * // Node.js: save to file
117
- * const fs = require('fs');
118
- * fs.writeFileSync('output.png', Buffer.from(result.data));
218
+ * // Video: submit, then wait for the result
219
+ * const job = await poof.removeBackground('./clip.mp4', { format: 'webm' });
220
+ * const done = await poof.waitForJob(job);
221
+ * console.log(done.resultUrl);
222
+ *
223
+ * // Video from a public URL, waiting inline
224
+ * const done = await poof.removeBackground({ url: 'https://example.com/clip.mp4' }, { wait: true });
119
225
  * ```
120
226
  */
121
- removeBackground(input: ImageInput, options?: RemoveBackgroundOptions): Promise<RemoveBackgroundResult>;
227
+ removeBackground(input: MediaInput, options?: RemoveBackgroundOptions): Promise<RemoveBackgroundResult | Job>;
228
+ /**
229
+ * Get the current state of a video job. Polling is free and does not count
230
+ * against your rate limit.
231
+ *
232
+ * @param jobId - The job ID returned by removeBackground()
233
+ *
234
+ * @example
235
+ * ```typescript
236
+ * const job = await poof.getJob('job_8f3a1c2e9b7d4a10');
237
+ * console.log(job.status, job.progress);
238
+ * ```
239
+ */
240
+ getJob(jobId: string): Promise<Job>;
241
+ /**
242
+ * Poll a video job until it is completed.
243
+ *
244
+ * @param job - A Job or a job ID
245
+ * @param options - Poll interval, timeout and progress callback
246
+ * @returns The completed job; `resultUrl` is a direct download link valid for 24 hours
247
+ * @throws PoofError with code `job_failed` if the job fails (credits are refunded),
248
+ * or code `timeout` if `timeoutMs` elapses first
249
+ *
250
+ * @example
251
+ * ```typescript
252
+ * const done = await poof.waitForJob(job, {
253
+ * onProgress: (j) => console.log(`${Math.round(j.progress * 100)}%`),
254
+ * });
255
+ * const video = await fetch(done.resultUrl!);
256
+ * ```
257
+ */
258
+ waitForJob(job: Job | string, options?: WaitForJobOptions): Promise<Job>;
122
259
  /**
123
260
  * Get account information
124
261
  *
@@ -137,6 +274,20 @@ declare class Poof {
137
274
  /** Handle error response */
138
275
  private handleError;
139
276
  }
277
+ /**
278
+ * Type guard: did removeBackground() return a video Job rather than image bytes?
279
+ *
280
+ * @example
281
+ * ```typescript
282
+ * const result = await poof.removeBackground(input);
283
+ * if (isJob(result)) {
284
+ * const done = await poof.waitForJob(result);
285
+ * } else {
286
+ * fs.writeFileSync('output.png', Buffer.from(result.data));
287
+ * }
288
+ * ```
289
+ */
290
+ declare function isJob(value: RemoveBackgroundResult | Job): value is Job;
140
291
 
141
292
  /**
142
293
  * Base error class for all Poof SDK errors
@@ -219,4 +370,4 @@ declare class ServerError extends PoofError {
219
370
  });
220
371
  }
221
372
 
222
- export { type AccountInfo, type ApiErrorResponse, AuthenticationError, type Channels, type ErrorCode, type ImageFormat, type ImageInput, type ImageSize, PaymentRequiredError, PermissionError, Poof, PoofError, type PoofOptions, type ProcessingMetadata, RateLimitError, type RemoveBackgroundOptions, type RemoveBackgroundResult, ServerError, ValidationError };
373
+ export { type AccountInfo, type ApiErrorResponse, AuthenticationError, type Channels, type ErrorCode, type FitMode, type ImageFormat, type ImageInput, type ImageSize, type Job, type JobError, type JobStatus, type MediaInput, PaymentRequiredError, PermissionError, Poof, PoofError, type PoofOptions, type ProcessingMetadata, RateLimitError, type RemoveBackgroundOptions, type RemoveBackgroundResult, ServerError, type UrlInput, ValidationError, type VideoFormat, type WaitForJobOptions, isJob };
package/dist/index.d.ts CHANGED
@@ -12,22 +12,53 @@ interface PoofOptions {
12
12
  }
13
13
  /** Output image format */
14
14
  type ImageFormat = 'png' | 'jpg' | 'webp';
15
+ /** Output video format: VP9 WebM (alpha or opaque), ProRes MOV (alpha or opaque) or H.264 MP4 (opaque) */
16
+ type VideoFormat = 'webm' | 'mov' | 'mp4';
15
17
  /** Output color channels */
16
- type Channels = 'rgba' | 'rgb';
18
+ type Channels = 'rgba' | 'rgb' | 'alpha';
17
19
  /** Output image size preset */
18
- type ImageSize = 'full' | 'preview' | 'small' | 'medium' | 'large';
20
+ type ImageSize = 'full' | 'preview' | 'medium' | 'hd';
21
+ /**
22
+ * How the image is fitted into a fixed width/height (never stretched):
23
+ * 'contain' scales to fit inside and pads the rest, 'cover' scales to fill and
24
+ * crops the overflow around the subject, 'scale-down' is contain without ever
25
+ * enlarging a smaller image.
26
+ */
27
+ type FitMode = 'contain' | 'cover' | 'scale-down';
28
+ /** Options for waiting on a video job */
29
+ interface WaitForJobOptions {
30
+ /** Delay between status polls in milliseconds (default: 3000) */
31
+ pollIntervalMs?: number;
32
+ /** Give up after this many milliseconds (default: 600000, i.e. 10 minutes) */
33
+ timeoutMs?: number;
34
+ /** Called after every poll with the latest job state */
35
+ onProgress?: (job: Job) => void;
36
+ }
19
37
  /** Options for background removal */
20
38
  interface RemoveBackgroundOptions {
21
- /** Output format (default: png) */
22
- format?: ImageFormat;
23
- /** Color channels - rgba for transparency, rgb for opaque (default: rgba) */
39
+ /** Output format: png, jpg or webp for images (default: png); webm, mov or mp4 for videos (default: webm) */
40
+ format?: ImageFormat | VideoFormat;
41
+ /** Color channels - rgba for transparency, rgb for opaque, alpha for the grayscale mask only (default: rgba) */
24
42
  channels?: Channels;
25
- /** Background color (hex, rgb, or color name). Only applies when channels is 'rgb' */
43
+ /** Background color (hex, rgb, or color name). Applies when channels is 'rgb' or 'rgba' */
26
44
  bgColor?: string;
27
45
  /** Output size preset (default: full) */
28
46
  size?: ImageSize;
29
- /** Crop to subject bounds (default: false) */
30
- crop?: boolean;
47
+ /** Crop to subject bounds: true/false or an aspect ratio like '1:1', '4:3', '16:9' (default: false) */
48
+ crop?: boolean | string;
49
+ /** Padding around the subject when crop is enabled, as a fraction ('0.1') or percentage ('10%') */
50
+ padding?: string;
51
+ /** Output width in pixels (1-6000). On its own, the height follows the aspect ratio. Overrides size */
52
+ width?: number;
53
+ /** Output height in pixels (1-6000). On its own, the width follows the aspect ratio. Overrides size */
54
+ height?: number;
55
+ /** How to fit into width x height without stretching (default: contain) */
56
+ fit?: FitMode;
57
+ /**
58
+ * Videos only: wait for the job to finish and return the completed Job
59
+ * instead of the queued one. Pass an object to tune polling.
60
+ */
61
+ wait?: boolean | WaitForJobOptions;
31
62
  }
32
63
  /** Metadata returned with processed images */
33
64
  interface ProcessingMetadata {
@@ -41,6 +72,16 @@ interface ProcessingMetadata {
41
72
  height: number;
42
73
  /** Content type of the result */
43
74
  contentType: string;
75
+ /**
76
+ * Confidence in the alpha matte, 0-1. 1 means a fully decisive mask; lower
77
+ * values mean the model hedged. Heuristic, not a calibrated probability.
78
+ */
79
+ matteConfidence?: number;
80
+ /**
81
+ * Fraction of pixels with alpha between 0.1 and 0.9, 0-1. High values
82
+ * indicate large uncertain regions - useful for flagging results for review.
83
+ */
84
+ matteAmbiguousRatio?: number;
44
85
  }
45
86
  /** Result of background removal including image data and metadata */
46
87
  interface RemoveBackgroundResult {
@@ -49,6 +90,59 @@ interface RemoveBackgroundResult {
49
90
  /** Processing metadata */
50
91
  metadata: ProcessingMetadata;
51
92
  }
93
+ /** State of a video job */
94
+ type JobStatus = 'queued' | 'processing' | 'completed' | 'failed';
95
+ /** Why a video job failed */
96
+ interface JobError {
97
+ /** Machine-readable error code, e.g. processing_failed */
98
+ code: string;
99
+ /** Human-readable description */
100
+ message: string;
101
+ }
102
+ /**
103
+ * A video background removal job. Returned with status 'queued' when a video
104
+ * is submitted; poll with getJob() or waitForJob() until it is 'completed'.
105
+ */
106
+ interface Job {
107
+ /** Job ID, prefixed with job_ */
108
+ id: string;
109
+ /** queued and processing are transient; completed and failed are terminal */
110
+ status: JobStatus;
111
+ /** Fraction of the video processed so far, 0 to 1 */
112
+ progress: number;
113
+ /** When the job was accepted (ISO 8601) */
114
+ createdAt: string;
115
+ /** When processing began; null while queued */
116
+ startedAt: string | null;
117
+ /** When the job reached completed or failed; null until then */
118
+ completedAt: string | null;
119
+ /** Source video duration in seconds */
120
+ durationSeconds: number;
121
+ /** Source frame rate */
122
+ fps: number;
123
+ /** Source video width in pixels */
124
+ width: number;
125
+ /** Source video height in pixels */
126
+ height: number;
127
+ /** Number of frames in the source video */
128
+ frames: number;
129
+ /** Credits charged for this job (5 per second of video, 10 above 30 fps); refunded if it fails */
130
+ credits: number;
131
+ /** Requested output format */
132
+ format: VideoFormat;
133
+ /** Requested output channels */
134
+ channels: Channels;
135
+ /** URL of the job; GET it to poll for progress */
136
+ statusUrl: string;
137
+ /** Direct download URL of the result on the Poof CDN once completed, null before that. No API key needed */
138
+ resultUrl: string | null;
139
+ /** When the result is deleted, 24 hours after completion; null until completed */
140
+ expiresAt: string | null;
141
+ /** Set when status is failed, null otherwise */
142
+ error: JobError | null;
143
+ /** Processing statistics once completed (output_width, output_height, processing_seconds, ...), null before */
144
+ stats: Record<string, unknown> | null;
145
+ }
52
146
  /** Account information */
53
147
  interface AccountInfo {
54
148
  /** Your organization ID */
@@ -63,7 +157,7 @@ interface AccountInfo {
63
157
  autoRechargeThreshold: number | null;
64
158
  }
65
159
  /** Error codes returned by the API */
66
- type ErrorCode = 'authentication_error' | 'permission_denied' | 'payment_required' | 'rate_limit_exceeded' | 'validation_error' | 'missing_image' | 'image_too_large' | 'upstream_error' | 'internal_server_error';
160
+ type ErrorCode = 'authentication_error' | 'permission_denied' | 'payment_required' | 'rate_limit_exceeded' | 'validation_error' | 'missing_image' | 'image_too_large' | 'invalid_image' | 'video_too_large' | 'video_too_long' | 'invalid_video' | 'job_not_found' | 'job_failed' | 'upstream_error' | 'internal_server_error';
67
161
  /** API error response structure */
68
162
  interface ApiErrorResponse {
69
163
  code: ErrorCode;
@@ -71,8 +165,14 @@ interface ApiErrorResponse {
71
165
  details?: string;
72
166
  request_id: string;
73
167
  }
74
- /** Valid input types for image processing */
168
+ /** Valid input types for image and video processing: file contents, or a file path in Node.js */
75
169
  type ImageInput = File | Blob | ArrayBuffer | Buffer | Uint8Array | string;
170
+ /** A publicly reachable https URL that Poof downloads instead of an upload (images up to 20 MB, videos up to 500 MB) */
171
+ interface UrlInput {
172
+ url: string;
173
+ }
174
+ /** Anything removeBackground() accepts: file contents, a file path (Node.js) or `{ url }` */
175
+ type MediaInput = ImageInput | UrlInput;
76
176
 
77
177
  /**
78
178
  * Poof API client for background removal
@@ -91,34 +191,71 @@ declare class Poof {
91
191
  private readonly timeout;
92
192
  constructor(options: PoofOptions);
93
193
  /**
94
- * Remove background from an image
194
+ * Remove the background from an image or a video.
195
+ *
196
+ * Images are processed synchronously and come back as bytes. Videos are
197
+ * processed as a job: the call returns a queued {@link Job}; poll it with
198
+ * {@link getJob} / {@link waitForJob}, or pass `wait: true` to get the
199
+ * completed job (with `resultUrl`) directly. Use {@link isJob} to tell the
200
+ * two apart.
95
201
  *
96
- * @param input - Image input: File, Blob, Buffer, ArrayBuffer, Uint8Array, or file path (Node.js)
202
+ * @param input - File, Blob, Buffer, ArrayBuffer, Uint8Array, file path (Node.js), or `{ url }`
97
203
  * @param options - Processing options
98
- * @returns Processed image data and metadata
204
+ * @returns Processed image data and metadata, or a video Job
99
205
  *
100
206
  * @example
101
207
  * ```typescript
102
- * // Basic usage
208
+ * // Image
103
209
  * const result = await poof.removeBackground(file);
104
210
  * const imageBlob = new Blob([result.data], { type: result.metadata.contentType });
105
211
  *
106
212
  * // With options
107
- * const result = await poof.removeBackground(file, {
108
- * format: 'webp',
109
- * crop: true,
110
- * size: 'medium'
111
- * });
213
+ * const result = await poof.removeBackground(file, { format: 'webp', crop: true, size: 'medium' });
112
214
  *
113
- * // Node.js: from file path
114
- * const result = await poof.removeBackground('/path/to/image.png');
215
+ * // Exact 500x500 output, subject cropped and centred, never stretched
216
+ * const result = await poof.removeBackground(file, { crop: true, width: 500, height: 500 });
115
217
  *
116
- * // Node.js: save to file
117
- * const fs = require('fs');
118
- * fs.writeFileSync('output.png', Buffer.from(result.data));
218
+ * // Video: submit, then wait for the result
219
+ * const job = await poof.removeBackground('./clip.mp4', { format: 'webm' });
220
+ * const done = await poof.waitForJob(job);
221
+ * console.log(done.resultUrl);
222
+ *
223
+ * // Video from a public URL, waiting inline
224
+ * const done = await poof.removeBackground({ url: 'https://example.com/clip.mp4' }, { wait: true });
119
225
  * ```
120
226
  */
121
- removeBackground(input: ImageInput, options?: RemoveBackgroundOptions): Promise<RemoveBackgroundResult>;
227
+ removeBackground(input: MediaInput, options?: RemoveBackgroundOptions): Promise<RemoveBackgroundResult | Job>;
228
+ /**
229
+ * Get the current state of a video job. Polling is free and does not count
230
+ * against your rate limit.
231
+ *
232
+ * @param jobId - The job ID returned by removeBackground()
233
+ *
234
+ * @example
235
+ * ```typescript
236
+ * const job = await poof.getJob('job_8f3a1c2e9b7d4a10');
237
+ * console.log(job.status, job.progress);
238
+ * ```
239
+ */
240
+ getJob(jobId: string): Promise<Job>;
241
+ /**
242
+ * Poll a video job until it is completed.
243
+ *
244
+ * @param job - A Job or a job ID
245
+ * @param options - Poll interval, timeout and progress callback
246
+ * @returns The completed job; `resultUrl` is a direct download link valid for 24 hours
247
+ * @throws PoofError with code `job_failed` if the job fails (credits are refunded),
248
+ * or code `timeout` if `timeoutMs` elapses first
249
+ *
250
+ * @example
251
+ * ```typescript
252
+ * const done = await poof.waitForJob(job, {
253
+ * onProgress: (j) => console.log(`${Math.round(j.progress * 100)}%`),
254
+ * });
255
+ * const video = await fetch(done.resultUrl!);
256
+ * ```
257
+ */
258
+ waitForJob(job: Job | string, options?: WaitForJobOptions): Promise<Job>;
122
259
  /**
123
260
  * Get account information
124
261
  *
@@ -137,6 +274,20 @@ declare class Poof {
137
274
  /** Handle error response */
138
275
  private handleError;
139
276
  }
277
+ /**
278
+ * Type guard: did removeBackground() return a video Job rather than image bytes?
279
+ *
280
+ * @example
281
+ * ```typescript
282
+ * const result = await poof.removeBackground(input);
283
+ * if (isJob(result)) {
284
+ * const done = await poof.waitForJob(result);
285
+ * } else {
286
+ * fs.writeFileSync('output.png', Buffer.from(result.data));
287
+ * }
288
+ * ```
289
+ */
290
+ declare function isJob(value: RemoveBackgroundResult | Job): value is Job;
140
291
 
141
292
  /**
142
293
  * Base error class for all Poof SDK errors
@@ -219,4 +370,4 @@ declare class ServerError extends PoofError {
219
370
  });
220
371
  }
221
372
 
222
- export { type AccountInfo, type ApiErrorResponse, AuthenticationError, type Channels, type ErrorCode, type ImageFormat, type ImageInput, type ImageSize, PaymentRequiredError, PermissionError, Poof, PoofError, type PoofOptions, type ProcessingMetadata, RateLimitError, type RemoveBackgroundOptions, type RemoveBackgroundResult, ServerError, ValidationError };
373
+ export { type AccountInfo, type ApiErrorResponse, AuthenticationError, type Channels, type ErrorCode, type FitMode, type ImageFormat, type ImageInput, type ImageSize, type Job, type JobError, type JobStatus, type MediaInput, PaymentRequiredError, PermissionError, Poof, PoofError, type PoofOptions, type ProcessingMetadata, RateLimitError, type RemoveBackgroundOptions, type RemoveBackgroundResult, ServerError, type UrlInput, ValidationError, type VideoFormat, type WaitForJobOptions, isJob };