@puppetry.com/sdk 0.1.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.
@@ -0,0 +1,947 @@
1
+ /**
2
+ * Puppetry SDK Types
3
+ * Generated from OpenAPI spec (docs/api/openapi.yaml)
4
+ */
5
+ type VideoStatus = "queued" | "processing" | "completed" | "failed";
6
+ type VideoJobSource = "text" | "audio";
7
+ interface IdempotencyKeyOptions {
8
+ /**
9
+ * Optional retry key sent as the Idempotency-Key header.
10
+ *
11
+ * Use this when retrying create requests so Puppetry can replay the accepted
12
+ * job or upload reservation without charging or reserving quota twice.
13
+ */
14
+ idempotencyKey?: string;
15
+ /**
16
+ * Optional snake_case retry key alias for agent tool inputs.
17
+ *
18
+ * This is normalized to the Idempotency-Key header just like
19
+ * idempotencyKey.
20
+ */
21
+ idempotency_key?: string;
22
+ }
23
+ interface ApiAudioUploadFallbackDiagnostics {
24
+ source: "api-audio-upload-s3-fallback";
25
+ key: string;
26
+ recoveredFromS3: boolean;
27
+ reason?: string;
28
+ s3FallbackRetryCount?: number;
29
+ s3FallbackLastRetryReason?: string;
30
+ expectedETag?: string;
31
+ expectedMimeType?: "audio/wav" | "audio/mpeg" | "audio/mp4";
32
+ expectedSizeBytes?: number;
33
+ readUrlExpiresAt?: string;
34
+ readUrlExpiredAtFallback?: boolean;
35
+ }
36
+ interface LivePortraitRecoveryDiagnostics {
37
+ source: "liveportrait";
38
+ squareDrivingCropBypassAttempted: true;
39
+ squareDrivingCropBypassStage: string;
40
+ }
41
+ interface VideoJobDiagnostics {
42
+ apiAudioUpload?: ApiAudioUploadFallbackDiagnostics;
43
+ livePortrait?: LivePortraitRecoveryDiagnostics;
44
+ }
45
+ interface VideoJobResult {
46
+ diagnostics?: VideoJobDiagnostics;
47
+ [key: string]: unknown;
48
+ }
49
+ type ImageUrlAliases = {
50
+ /** Hosted portrait image URL. */
51
+ image_url?: string;
52
+ /** @deprecated Prefer image_url for raw API parity. Kept for idiomatic SDK callers. */
53
+ imageUrl?: string;
54
+ /** Alias for agent callers that label the portrait input as an image. */
55
+ image?: string;
56
+ /** @deprecated Use image_url. Kept as an SDK alias for older callers. */
57
+ portrait?: string;
58
+ /** Hosted portrait image URL snake_case alias for agent callers. */
59
+ portrait_url?: string;
60
+ /** Hosted portrait image URL alias for agent callers. */
61
+ portraitUrl?: string;
62
+ /** Hosted avatar image URL alias for agent callers. */
63
+ avatar?: string;
64
+ /** Hosted avatar image URL alias for agent callers. */
65
+ avatarUrl?: string;
66
+ /** Hosted avatar image URL snake_case alias for agent callers. */
67
+ avatar_url?: string;
68
+ /** Hosted photo image URL alias for agent callers. */
69
+ photo?: string;
70
+ /** Hosted photo image URL alias for agent callers. */
71
+ photoUrl?: string;
72
+ /** Hosted photo image URL snake_case alias for agent callers. */
73
+ photo_url?: string;
74
+ };
75
+ type ImageUrlInput = ImageUrlAliases & ({
76
+ image_url: string;
77
+ } | {
78
+ imageUrl: string;
79
+ } | {
80
+ image: string;
81
+ } | {
82
+ portrait: string;
83
+ } | {
84
+ portrait_url: string;
85
+ } | {
86
+ portraitUrl: string;
87
+ } | {
88
+ avatar: string;
89
+ } | {
90
+ avatarUrl: string;
91
+ } | {
92
+ avatar_url: string;
93
+ } | {
94
+ photo: string;
95
+ } | {
96
+ photoUrl: string;
97
+ } | {
98
+ photo_url: string;
99
+ });
100
+ type AudioUrlInput = {
101
+ /** Hosted audio URL. */
102
+ audio_url: string;
103
+ audioUrl?: string;
104
+ /** Hosted audio URL alias for agent callers. */
105
+ audio?: string;
106
+ } | {
107
+ audio_url?: string;
108
+ /** @deprecated Use audio_url. Kept as an SDK alias for older callers. */
109
+ audioUrl: string;
110
+ /** Hosted audio URL alias for agent callers. */
111
+ audio?: string;
112
+ } | {
113
+ audio_url?: string;
114
+ /** @deprecated Use audio_url. Kept as an SDK alias for older callers. */
115
+ audioUrl?: string;
116
+ /** Hosted audio URL alias for agent callers. */
117
+ audio: string;
118
+ };
119
+ type MimeTypeInput = {
120
+ /** Audio MIME type. */
121
+ mime_type: string;
122
+ mimeType?: string;
123
+ contentType?: string;
124
+ } | {
125
+ mime_type?: string;
126
+ /** Audio MIME type. */
127
+ mimeType: string;
128
+ contentType?: string;
129
+ } | {
130
+ mime_type?: string;
131
+ mimeType?: string;
132
+ /** Audio MIME type alias commonly used for signed uploads. */
133
+ contentType: string;
134
+ };
135
+ type ContentLengthInput = {
136
+ /** Exact byte length of the audio file to upload */
137
+ content_length: number;
138
+ contentLength?: number;
139
+ sizeBytes?: number;
140
+ file_size?: number;
141
+ fileSize?: number;
142
+ } | {
143
+ content_length?: number;
144
+ /** Exact byte length of the audio file to upload */
145
+ contentLength: number;
146
+ sizeBytes?: number;
147
+ file_size?: number;
148
+ fileSize?: number;
149
+ } | {
150
+ content_length?: number;
151
+ contentLength?: number;
152
+ /** Exact byte length alias for agent/runtime callers. */
153
+ sizeBytes: number;
154
+ file_size?: number;
155
+ fileSize?: number;
156
+ } | {
157
+ content_length?: number;
158
+ contentLength?: number;
159
+ sizeBytes?: number;
160
+ /** Exact byte length alias for upload/file metadata callers. */
161
+ file_size: number;
162
+ fileSize?: number;
163
+ } | {
164
+ content_length?: number;
165
+ contentLength?: number;
166
+ sizeBytes?: number;
167
+ file_size?: number;
168
+ /** Exact byte length alias for upload/file metadata callers. */
169
+ fileSize: number;
170
+ };
171
+ type TextScriptInput = {
172
+ /** Text script for TTS */
173
+ text: string;
174
+ /** Alias for text, useful for MCP/agent callers that use script terminology. */
175
+ script?: string;
176
+ /** Alias for text, useful for prompt-oriented agents. */
177
+ prompt?: string;
178
+ } | {
179
+ /** Text script for TTS */
180
+ text?: string;
181
+ /** Alias for text, useful for MCP/agent callers that use script terminology. */
182
+ script: string;
183
+ /** Alias for text, useful for prompt-oriented agents. */
184
+ prompt?: string;
185
+ } | {
186
+ /** Text script for TTS */
187
+ text?: string;
188
+ /** Alias for text, useful for MCP/agent callers that use script terminology. */
189
+ script?: string;
190
+ /** Alias for text, useful for prompt-oriented agents. */
191
+ prompt: string;
192
+ };
193
+ interface VideoJob {
194
+ object?: "video_job";
195
+ id: string;
196
+ job_id?: string;
197
+ jobId?: string;
198
+ operation_id?: string;
199
+ operationId?: string;
200
+ request_id?: string;
201
+ requestId?: string;
202
+ task_id?: string;
203
+ taskId?: string;
204
+ source?: VideoJobSource;
205
+ request_source?: VideoJobSource;
206
+ requestSource?: VideoJobSource;
207
+ status: VideoStatus;
208
+ state?: VideoStatus;
209
+ task_status?: VideoStatus;
210
+ taskStatus?: VideoStatus;
211
+ progress?: number | null;
212
+ percent?: number | null;
213
+ percentage?: number | null;
214
+ progress_percent?: number | null;
215
+ progressPercent?: number | null;
216
+ created_at?: string;
217
+ createdAt?: string;
218
+ expires_at?: string;
219
+ expiresAt?: string;
220
+ completed_at?: string | null;
221
+ completedAt?: string | null;
222
+ url?: string | null;
223
+ video_url?: string | null;
224
+ videoUrl?: string | null;
225
+ result_url?: string | null;
226
+ resultUrl?: string | null;
227
+ download_url?: string | null;
228
+ downloadUrl?: string | null;
229
+ output_url?: string | null;
230
+ outputUrl?: string | null;
231
+ thumbnail_url?: string | null;
232
+ thumbnailUrl?: string | null;
233
+ duration?: number | null;
234
+ duration_seconds?: number | null;
235
+ durationSeconds?: number | null;
236
+ error?: string | null;
237
+ retryable?: boolean;
238
+ retry_blocked_reason?: string;
239
+ retryBlockedReason?: string;
240
+ retry_block_code?: string;
241
+ retryBlockCode?: string;
242
+ diagnostics?: VideoJobDiagnostics;
243
+ result?: VideoJobResult | null;
244
+ credits?: {
245
+ charged: number;
246
+ remaining: number | null;
247
+ };
248
+ creation_credits?: {
249
+ charged: number;
250
+ remaining_after_debit: number | null;
251
+ remainingAfterDebit?: number | null;
252
+ };
253
+ creationCredits?: {
254
+ charged: number;
255
+ remaining_after_debit?: number | null;
256
+ remainingAfterDebit: number | null;
257
+ };
258
+ status_url?: string;
259
+ statusUrl?: string;
260
+ content_location?: string;
261
+ contentLocation?: string;
262
+ retry_after_seconds?: number;
263
+ retryAfter?: number;
264
+ retryAfterSeconds?: number;
265
+ next_poll_at?: string;
266
+ nextPollAt?: string;
267
+ idempotent_replay?: true;
268
+ idempotentReplay?: true;
269
+ }
270
+ interface VideoJobHelpers {
271
+ /**
272
+ * Poll this job until it reaches completed or failed.
273
+ *
274
+ * SDK-returned jobs expose this helper as a non-enumerable property, so the
275
+ * object still serializes like the raw API response.
276
+ */
277
+ waitForCompletion(options?: WaitForCompletionOptions): Promise<PuppetryVideoJob>;
278
+ }
279
+ type PuppetryVideoJob = VideoJob & VideoJobHelpers;
280
+ type CreateTextVideoParams = IdempotencyKeyOptions & ImageUrlInput & TextScriptInput & {
281
+ /** Puppetry voice ID (from voices.listPuppetry()) */
282
+ voice_id?: string;
283
+ /** @deprecated Use voice_id. Kept as an SDK alias for older callers. */
284
+ voiceId?: string;
285
+ /** Voice ID alias that matches the quickstart-style SDK examples. */
286
+ voice?: string;
287
+ /** Language code (default: "en") */
288
+ language?: string;
289
+ /** Animation expressiveness from 0 to 2 (default: 1) */
290
+ expressiveness?: number;
291
+ };
292
+ type CreateAudioVideoParams = IdempotencyKeyOptions & ImageUrlInput & AudioUrlInput & {
293
+ /** Animation expressiveness from 0 to 2 (default: 1) */
294
+ expressiveness?: number;
295
+ };
296
+ interface WaitForCompletionOptions {
297
+ /** Polling interval in milliseconds, default 2000 */
298
+ intervalMs?: number;
299
+ /** Max wait time in milliseconds, default 300000 */
300
+ timeoutMs?: number;
301
+ /**
302
+ * Optional delay before the first status request.
303
+ *
304
+ * Jobs returned by create helpers use the API's Retry-After hint by default
305
+ * so the first poll is paced like the raw Developer API contract.
306
+ */
307
+ initialDelayMs?: number;
308
+ /**
309
+ * Called after each status poll, including the terminal completed/failed job.
310
+ *
311
+ * Use this for agent progress logs or UI updates without starting a separate
312
+ * stream.
313
+ */
314
+ onPoll?: (job: PuppetryVideoJob) => void | Promise<void>;
315
+ /**
316
+ * Called when status polling receives a retryable API error and the SDK will
317
+ * wait/back off before polling again.
318
+ */
319
+ onRetrying?: (event: VideoEvent) => void | Promise<void>;
320
+ }
321
+ interface Voice {
322
+ id: string;
323
+ name: string;
324
+ language: string;
325
+ gender?: "male" | "female" | "neutral";
326
+ provider: string;
327
+ previewUrl?: string;
328
+ isCloned?: boolean;
329
+ }
330
+ interface PuppetryVoice {
331
+ id: string;
332
+ object: "voice";
333
+ name: string;
334
+ provider: "puppetry";
335
+ language: string;
336
+ language_code: string;
337
+ gender: string;
338
+ description: string;
339
+ styles: string[];
340
+ preview_text: string;
341
+ preview_url: string;
342
+ }
343
+ interface PuppetryVoiceList {
344
+ object: "list";
345
+ data: PuppetryVoice[];
346
+ default_voice_id: string;
347
+ }
348
+ interface ListVoicesParams {
349
+ language?: string;
350
+ gender?: "male" | "female" | "neutral";
351
+ cursor?: string;
352
+ limit?: number;
353
+ }
354
+ interface CreatePuppetryTtsParams {
355
+ /** Voice ID from voices.listPuppetry() */
356
+ voice_id: string;
357
+ /** Text to synthesize, up to 5,000 characters */
358
+ text: string;
359
+ /** Speech speed multiplier, from 0.5 to 2.0 */
360
+ speed?: number;
361
+ }
362
+ interface PuppetryTtsResponse {
363
+ object: "audio";
364
+ id: string;
365
+ voice_id: string;
366
+ audio_url: string;
367
+ format: "wav" | string;
368
+ usage?: {
369
+ voice_characters: {
370
+ used: number;
371
+ limit: number;
372
+ remaining: number;
373
+ };
374
+ };
375
+ }
376
+ interface AudioUploadVideoReadinessOptions {
377
+ /**
378
+ * Require current video-generation credit/slot readiness before reserving a
379
+ * hosted audio upload URL for an audio-to-video workflow.
380
+ */
381
+ require_video_readiness?: boolean;
382
+ /** CamelCase alias for require_video_readiness. */
383
+ requireVideoReadiness?: boolean;
384
+ }
385
+ type CreateAudioUploadUrlParams = IdempotencyKeyOptions & MimeTypeInput & ContentLengthInput & AudioUploadVideoReadinessOptions;
386
+ type AudioUploadBody = NonNullable<NonNullable<Parameters<typeof globalThis.fetch>[1]>["body"]>;
387
+ type UploadAudioParams = CreateAudioUploadUrlParams & {
388
+ /** Raw audio bytes to PUT to the signed upload URL */
389
+ body: AudioUploadBody;
390
+ };
391
+ interface ApiUploadLimits {
392
+ max_file_bytes: number;
393
+ maxFileBytes?: number;
394
+ monthly_uploads: number;
395
+ monthlyUploads?: number;
396
+ storage_bytes: number;
397
+ storageBytes?: number;
398
+ remaining_monthly_uploads: number;
399
+ remainingMonthlyUploads?: number;
400
+ remaining_storage_bytes: number;
401
+ remainingStorageBytes?: number;
402
+ }
403
+ interface AudioUploadUrlResponse {
404
+ object: "upload_url";
405
+ id: string;
406
+ upload_url: string;
407
+ uploadUrl?: string;
408
+ method: "PUT";
409
+ headers: {
410
+ "Content-Type": string;
411
+ "Content-Length": string;
412
+ };
413
+ key: string;
414
+ read_url: string;
415
+ readUrl?: string;
416
+ read_url_expires_in: number;
417
+ readUrlExpiresIn?: number;
418
+ read_url_expires_at: string;
419
+ readUrlExpiresAt?: string;
420
+ upload_url_expires_in: number;
421
+ uploadUrlExpiresIn?: number;
422
+ idempotent_replay?: true;
423
+ idempotentReplay?: true;
424
+ limits: ApiUploadLimits;
425
+ }
426
+ interface Puppet {
427
+ id: string;
428
+ name: string;
429
+ imageUrl: string;
430
+ createdAt: string;
431
+ }
432
+ interface CreatePuppetParams {
433
+ /** Portrait image URL */
434
+ imageUrl: string;
435
+ /** Display name for the puppet */
436
+ name?: string;
437
+ }
438
+ interface ListPuppetsParams {
439
+ cursor?: string;
440
+ limit?: number;
441
+ }
442
+ interface UsageApiKeyVideoCredits {
443
+ id?: string;
444
+ key_id?: string;
445
+ keyId?: string;
446
+ name?: string;
447
+ key_prefix?: string;
448
+ keyPrefix?: string;
449
+ type?: "developer_api" | "mcp";
450
+ used: number;
451
+ refunded: number;
452
+ net_used: number;
453
+ netUsed?: number;
454
+ transactions: number;
455
+ }
456
+ interface UsageVideoCredits {
457
+ balance: number;
458
+ month: string;
459
+ reset_at: string;
460
+ resetAt?: string;
461
+ used: number;
462
+ refunded: number;
463
+ net_used: number;
464
+ netUsed?: number;
465
+ transactions: number;
466
+ current_api_key: UsageApiKeyVideoCredits;
467
+ currentApiKey?: UsageApiKeyVideoCredits;
468
+ }
469
+ type UsageVideoGenerationReadinessReason = "available" | "insufficient_video_credits" | "concurrent_job_limit_reached";
470
+ interface UsageVideoGenerationCreditBlocker {
471
+ code: "insufficient_video_credits";
472
+ reason: "insufficient_video_credits";
473
+ retryable: false;
474
+ required_credits: number;
475
+ requiredCredits?: number;
476
+ credits_remaining: number;
477
+ creditsRemaining?: number;
478
+ retry_block_code?: string;
479
+ retryBlockCode?: string;
480
+ }
481
+ interface UsageVideoGenerationConcurrentBlocker {
482
+ code: "concurrent_job_limit_reached";
483
+ reason: "concurrent_job_limit_reached";
484
+ retryable: true;
485
+ concurrent_jobs?: number;
486
+ concurrentJobs?: number;
487
+ active_jobs?: number;
488
+ activeJobs?: number;
489
+ available_slots?: number;
490
+ availableSlots?: number;
491
+ active_job_expires_in_seconds?: number;
492
+ activeJobExpiresInSeconds?: number;
493
+ retry_after_seconds?: number;
494
+ retryAfter?: number;
495
+ retryAfterSeconds?: number;
496
+ next_poll_at?: string;
497
+ nextPollAt?: string;
498
+ }
499
+ type UsageVideoGenerationBlocker = UsageVideoGenerationCreditBlocker | UsageVideoGenerationConcurrentBlocker;
500
+ interface UsageVideoGenerationReadiness {
501
+ can_create: boolean;
502
+ canCreate?: boolean;
503
+ required_credits: number;
504
+ requiredCredits?: number;
505
+ credits_remaining: number;
506
+ creditsRemaining?: number;
507
+ concurrent_jobs?: number;
508
+ concurrentJobs?: number;
509
+ active_jobs?: number;
510
+ activeJobs?: number;
511
+ available_slots?: number;
512
+ availableSlots?: number;
513
+ active_job_expires_in_seconds?: number;
514
+ activeJobExpiresInSeconds?: number;
515
+ retry_after_seconds?: number;
516
+ retryAfter?: number;
517
+ retryAfterSeconds?: number;
518
+ next_poll_at?: string;
519
+ nextPollAt?: string;
520
+ reason: UsageVideoGenerationReadinessReason;
521
+ blockers?: UsageVideoGenerationBlocker[];
522
+ }
523
+ interface Usage {
524
+ object?: "usage";
525
+ video_credits?: UsageVideoCredits;
526
+ videoCredits?: UsageVideoCredits;
527
+ video_generation?: UsageVideoGenerationReadiness;
528
+ videoGeneration?: UsageVideoGenerationReadiness;
529
+ /** @deprecated Use video_credits.balance or videoCredits.balance. */
530
+ plan: string;
531
+ /** @deprecated Use video_credits.balance plus video_credits.net_used when needed. */
532
+ creditsTotal: number;
533
+ /** @deprecated Use video_credits.net_used or videoCredits.netUsed. */
534
+ creditsUsed: number;
535
+ /** @deprecated Use video_credits.balance or videoCredits.balance. */
536
+ creditsRemaining: number;
537
+ /** @deprecated Use video_credits.month. */
538
+ periodStart: string;
539
+ /** @deprecated Use video_credits.reset_at or videoCredits.resetAt. */
540
+ periodEnd: string;
541
+ }
542
+ interface PaginatedResponse<T> {
543
+ data: T[];
544
+ nextCursor?: string | null;
545
+ hasMore: boolean;
546
+ }
547
+ type VideoEventType = "queued" | "processing" | "progress" | "retrying" | "completed" | "failed";
548
+ interface VideoEvent {
549
+ type: VideoEventType;
550
+ id?: string;
551
+ job_id?: string;
552
+ jobId: string;
553
+ task_id?: string;
554
+ taskId?: string;
555
+ operation_id?: string;
556
+ operationId?: string;
557
+ request_id?: string;
558
+ requestId?: string;
559
+ source?: VideoJobSource;
560
+ request_source?: VideoJobSource;
561
+ requestSource?: VideoJobSource;
562
+ status_url?: string;
563
+ statusUrl?: string;
564
+ content_location?: string;
565
+ contentLocation?: string;
566
+ progress?: number;
567
+ video_url?: string;
568
+ videoUrl?: string;
569
+ error?: string;
570
+ code?: string;
571
+ status?: number;
572
+ statusCode?: number;
573
+ retryable?: boolean;
574
+ credits?: {
575
+ charged: number;
576
+ remaining: number | null;
577
+ };
578
+ creation_credits?: {
579
+ charged: number;
580
+ remaining_after_debit: number | null;
581
+ remainingAfterDebit: number | null;
582
+ };
583
+ creationCredits?: {
584
+ charged: number;
585
+ remaining_after_debit: number | null;
586
+ remainingAfterDebit: number | null;
587
+ };
588
+ retry_blocked_reason?: string;
589
+ retryBlockedReason?: string;
590
+ retry_block_code?: string;
591
+ retryBlockCode?: string;
592
+ retry_after_seconds?: number;
593
+ retryAfter?: number;
594
+ retryAfterSeconds?: number;
595
+ next_poll_at?: string;
596
+ nextPollAt?: string;
597
+ created_at?: string;
598
+ createdAt?: string;
599
+ expires_at?: string;
600
+ expiresAt?: string;
601
+ completed_at?: string | null;
602
+ completedAt?: string | null;
603
+ timestamp: string;
604
+ }
605
+ interface PuppetryRequestRetryEvent {
606
+ /** HTTP method being retried. */
607
+ method: string;
608
+ /** SDK API path being retried, relative to the configured base URL. */
609
+ path: string;
610
+ /** Full request URL being retried. */
611
+ url: string;
612
+ /** Normalized Idempotency-Key header value for retry-safe writes. */
613
+ idempotency_key?: string;
614
+ /** CamelCase alias for idempotency_key. */
615
+ idempotencyKey?: string;
616
+ /** One-based failed attempt count. */
617
+ attempt: number;
618
+ /** Configured retry budget. */
619
+ maxRetries: number;
620
+ /** Delay the SDK will wait before the next attempt. */
621
+ delayMs: number;
622
+ status?: number;
623
+ statusCode?: number;
624
+ code?: string;
625
+ message?: string;
626
+ details?: Record<string, unknown>;
627
+ retryable?: boolean;
628
+ credits?: {
629
+ charged: number;
630
+ remaining: number | null;
631
+ };
632
+ creation_credits?: {
633
+ charged: number;
634
+ remaining_after_debit: number | null;
635
+ remainingAfterDebit: number | null;
636
+ };
637
+ creationCredits?: {
638
+ charged: number;
639
+ remaining_after_debit: number | null;
640
+ remainingAfterDebit: number | null;
641
+ };
642
+ retry_blocked_reason?: string;
643
+ retryBlockedReason?: string;
644
+ retry_block_code?: string;
645
+ retryBlockCode?: string;
646
+ retry_after_seconds?: number;
647
+ retryAfter?: number;
648
+ retryAfterSeconds?: number;
649
+ id?: string;
650
+ job_id?: string;
651
+ jobId?: string;
652
+ operation_id?: string;
653
+ operationId?: string;
654
+ request_id?: string;
655
+ requestId?: string;
656
+ task_id?: string;
657
+ taskId?: string;
658
+ source?: string;
659
+ request_source?: string;
660
+ requestSource?: string;
661
+ status_url?: string;
662
+ statusUrl?: string;
663
+ content_location?: string;
664
+ contentLocation?: string;
665
+ next_poll_at?: string;
666
+ nextPollAt?: string;
667
+ }
668
+ interface PuppetryConfig {
669
+ /** Your Puppetry API key */
670
+ apiKey: string;
671
+ /** Base URL (default: https://www.puppetry.com/api/v1) */
672
+ baseUrl?: string;
673
+ /** Request timeout in ms (default: 30000) */
674
+ timeout?: number;
675
+ /** Retries for safe 429/5xx reads and idempotency-protected 429/5xx writes (default: 2) */
676
+ maxRetries?: number;
677
+ /** Initial exponential backoff delay in ms (default: 500) */
678
+ retryDelayMs?: number;
679
+ /**
680
+ * Called before the SDK sleeps and retries a safe/idempotent request.
681
+ *
682
+ * Use this to surface Developer API 429/5xx backoff and job correlation
683
+ * metadata in agents or CLIs. Observer failures are ignored so retry logging
684
+ * cannot break an otherwise successful idempotent replay.
685
+ */
686
+ onRetry?: (event: PuppetryRequestRetryEvent) => void | Promise<void>;
687
+ /** Custom fetch implementation (for Node 16 or custom environments) */
688
+ fetch?: typeof globalThis.fetch;
689
+ }
690
+ interface ApiErrorResponse {
691
+ error: string;
692
+ message: string;
693
+ object?: unknown;
694
+ id?: unknown;
695
+ job_id?: unknown;
696
+ jobId?: unknown;
697
+ operation_id?: unknown;
698
+ operationId?: unknown;
699
+ task_id?: unknown;
700
+ taskId?: unknown;
701
+ source?: unknown;
702
+ request_source?: unknown;
703
+ requestSource?: unknown;
704
+ status_url?: unknown;
705
+ statusUrl?: unknown;
706
+ content_location?: unknown;
707
+ contentLocation?: unknown;
708
+ created_at?: unknown;
709
+ createdAt?: unknown;
710
+ expires_at?: unknown;
711
+ expiresAt?: unknown;
712
+ next_poll_at?: unknown;
713
+ nextPollAt?: unknown;
714
+ retryable?: unknown;
715
+ retry_blocked_reason?: unknown;
716
+ retryBlockedReason?: unknown;
717
+ retry_block_code?: unknown;
718
+ retryBlockCode?: unknown;
719
+ retry_after_seconds?: unknown;
720
+ retryAfter?: unknown;
721
+ retryAfterSeconds?: unknown;
722
+ details?: Record<string, unknown>;
723
+ }
724
+
725
+ declare class Puppetry {
726
+ private readonly apiKey;
727
+ private readonly baseUrl;
728
+ private readonly timeout;
729
+ private readonly maxRetries;
730
+ private readonly retryDelayMs;
731
+ private readonly onRetry?;
732
+ private readonly fetchFn;
733
+ constructor(config: PuppetryConfig);
734
+ private requestWithResponse;
735
+ private requestRetryEvent;
736
+ private notifyRetry;
737
+ private request;
738
+ private get;
739
+ private getWithResponse;
740
+ private post;
741
+ private delete;
742
+ private shouldRetry;
743
+ private isRetryableVideoStatusError;
744
+ private isVideoStatusRequest;
745
+ private shouldRetryTransport;
746
+ private isRetrySafeRequest;
747
+ private isAbortError;
748
+ private isNetworkError;
749
+ private transportErrorMessage;
750
+ private parseRetryAfter;
751
+ private responseRetryAfter;
752
+ private retryAfterFromErrorBody;
753
+ private retryAfterFromDetails;
754
+ private normalizeRetryAfterSeconds;
755
+ private retryDelay;
756
+ private sleep;
757
+ private responseHeaders;
758
+ private readHeader;
759
+ private readResponseHeader;
760
+ private compactBody;
761
+ private normalizeIdempotencyKey;
762
+ private idempotencyKeyFromParams;
763
+ private resolveAlias;
764
+ private resolveRequiredStringAliases;
765
+ private resolveOptionalStringAliases;
766
+ private resolveUploadStringAliases;
767
+ private resolveNumberAliases;
768
+ private firstDefinedNullable;
769
+ private textVideoBody;
770
+ private audioVideoBody;
771
+ private videoJobPath;
772
+ private normalizeVideoJob;
773
+ private videoJobStatusUrlHeader;
774
+ private videoJobPollLocationAliases;
775
+ private videoLocationHeader;
776
+ private videoContentLocationHeader;
777
+ private videoOperationIdHeader;
778
+ private videoRequestIdHeader;
779
+ private videoNextPollAtHeader;
780
+ private videoStatusErrorOptions;
781
+ private videoCreditErrorOptions;
782
+ private videoCreditHeaderNumber;
783
+ private videoJobIdFromStatusUrl;
784
+ private retryableStatusErrorJobId;
785
+ private videoJobResultDiagnostics;
786
+ private videoStatusCredits;
787
+ private videoCreationCredits;
788
+ private videoCreationCreditsFromHeaders;
789
+ private videoProgress;
790
+ private attachVideoJobHelpers;
791
+ private waitOptionsWithInitialDelay;
792
+ private retryAfterDelayMs;
793
+ private optionDelayMs;
794
+ private nextPollDelayMs;
795
+ private sleepWithinDeadline;
796
+ private pollingDelayMs;
797
+ private retryableStatusErrorDelayMs;
798
+ private normalizeUsage;
799
+ private normalizeVideoGenerationReadiness;
800
+ private normalizeVideoGenerationBlockers;
801
+ private normalizeVideoGenerationBlocker;
802
+ private derivedVideoGenerationBlockers;
803
+ private activeJobReadinessAliases;
804
+ private videoGenerationReadinessReason;
805
+ private readinessNumber;
806
+ private readinessString;
807
+ private getVideoGenerationReadiness;
808
+ private ensureVideoGenerationReady;
809
+ private videoGenerationReadinessErrorOptions;
810
+ private normalizeAudioUploadLimits;
811
+ private normalizeAudioUpload;
812
+ /**
813
+ * Create a video from text (text-to-speech + lip sync).
814
+ *
815
+ * @example
816
+ * ```ts
817
+ * const job = await puppetry.videos.createFromText({
818
+ * text: "Hello, world!",
819
+ * image_url: "https://example.com/photo.jpg",
820
+ * voice_id: "puppetry-af_heart",
821
+ * });
822
+ * ```
823
+ */
824
+ readonly videos: {
825
+ createFromText: (params: CreateTextVideoParams) => Promise<PuppetryVideoJob>;
826
+ createFromAudio: (params: CreateAudioVideoParams) => Promise<PuppetryVideoJob>;
827
+ get: (jobId: string) => Promise<PuppetryVideoJob>;
828
+ /**
829
+ * Return the current Developer API video readiness contract.
830
+ *
831
+ * Use this before reserving uploads or queueing a video when an agent needs
832
+ * to fail fast on credits or active slot limits.
833
+ */
834
+ getReadiness: () => Promise<NonNullable<Usage["video_generation"]>>;
835
+ /**
836
+ * Assert that this API key can create a video right now.
837
+ *
838
+ * Throws PuppetryRateLimitError with retryAfter for active-slot blockers,
839
+ * and PuppetryError(402) for credit blockers.
840
+ */
841
+ ensureReady: () => Promise<NonNullable<Usage["video_generation"]>>;
842
+ /**
843
+ * Wait for a video job to complete, polling at the given interval.
844
+ *
845
+ * @param jobId - The job ID to watch
846
+ * @param options.intervalMs - Polling interval (default: 2000)
847
+ * @param options.timeoutMs - Max wait time (default: 300000 = 5 min)
848
+ * @returns The completed VideoJob
849
+ * @throws PuppetryTimeoutError if the job doesn't complete in time
850
+ */
851
+ waitForCompletion: (jobId: string, options?: WaitForCompletionOptions) => Promise<PuppetryVideoJob>;
852
+ /**
853
+ * Stream progress-like events by polling the live v1 job status endpoint.
854
+ *
855
+ * @param jobId - The job ID to stream
856
+ * @param options.intervalMs - Polling interval (default: 2000)
857
+ * @param options.timeoutMs - Max stream time (default: 300000 = 5 min)
858
+ * @returns AsyncGenerator yielding VideoEvent objects
859
+ *
860
+ * @example
861
+ * ```ts
862
+ * for await (const event of puppetry.videos.stream("job-123")) {
863
+ * console.log(`${event.type}: ${event.progress}%`);
864
+ * if (event.type === "completed") break;
865
+ * }
866
+ * ```
867
+ */
868
+ stream: (jobId: string, options?: WaitForCompletionOptions) => AsyncGenerator<VideoEvent>;
869
+ };
870
+ readonly jobs: {
871
+ /**
872
+ * Fetch a generated video job by ID.
873
+ *
874
+ * This is an alias for `videos.get()` because Puppetry's public v1 API
875
+ * exposes generated video job state under `/videos/{jobId}`.
876
+ */
877
+ get: (jobId: string) => Promise<PuppetryVideoJob>;
878
+ /**
879
+ * Wait for a generated video job to complete, polling at the given interval.
880
+ */
881
+ waitForCompletion: (jobId: string, options?: WaitForCompletionOptions) => Promise<PuppetryVideoJob>;
882
+ };
883
+ readonly voices: {
884
+ list: (params?: ListVoicesParams) => Promise<PaginatedResponse<Voice>>;
885
+ listPuppetry: () => Promise<PuppetryVoiceList>;
886
+ };
887
+ readonly tts: {
888
+ createPuppetry: (params: CreatePuppetryTtsParams) => Promise<PuppetryTtsResponse>;
889
+ };
890
+ readonly uploads: {
891
+ /**
892
+ * Create a signed PUT URL for hosting audio that can be used by Puppetry API
893
+ * workflows.
894
+ */
895
+ createAudioUrl: (params: CreateAudioUploadUrlParams) => Promise<AudioUploadUrlResponse>;
896
+ /**
897
+ * Create a signed audio upload URL and PUT the provided bytes to it.
898
+ *
899
+ * The returned `read_url` can be passed to `videos.createFromAudio()`.
900
+ */
901
+ uploadAudio: (params: UploadAudioParams) => Promise<AudioUploadUrlResponse>;
902
+ };
903
+ readonly puppets: {
904
+ list: (params?: ListPuppetsParams) => Promise<PaginatedResponse<Puppet>>;
905
+ create: (params: CreatePuppetParams) => Promise<Puppet>;
906
+ delete: (puppetId: string) => Promise<void>;
907
+ };
908
+ readonly usage: {
909
+ get: () => Promise<Usage>;
910
+ };
911
+ readonly quota: {
912
+ get: () => Promise<Usage>;
913
+ };
914
+ private videoJobEvent;
915
+ private videoRetryingEvent;
916
+ private streamPolledVideoEvents;
917
+ }
918
+
919
+ type JsonRpcId = string | number | null;
920
+ interface JsonRpcRequest {
921
+ jsonrpc: "2.0";
922
+ id?: JsonRpcId;
923
+ method: string;
924
+ params?: unknown;
925
+ }
926
+ interface JsonRpcSuccessResponse {
927
+ jsonrpc: "2.0";
928
+ id: JsonRpcId;
929
+ result: unknown;
930
+ }
931
+ interface JsonRpcErrorResponse {
932
+ jsonrpc: "2.0";
933
+ id: JsonRpcId;
934
+ error: {
935
+ code: number;
936
+ message: string;
937
+ data?: unknown;
938
+ };
939
+ }
940
+ type JsonRpcResponse = JsonRpcSuccessResponse | JsonRpcErrorResponse;
941
+ interface PuppetryMcpServerInfo {
942
+ name: "puppetry";
943
+ version: string;
944
+ }
945
+ declare function handlePuppetryMcpRequest(client: Puppetry, request: JsonRpcRequest): Promise<JsonRpcResponse | null>;
946
+
947
+ export { type ApiErrorResponse as A, type VideoJobSource as B, type CreateTextVideoParams as C, type VideoStatus as D, type Voice as E, handlePuppetryMcpRequest as F, type JsonRpcErrorResponse as J, type ListPuppetsParams as L, type PuppetryVideoJob as P, type UsageVideoGenerationReadiness as U, type VideoEvent as V, type WaitForCompletionOptions as W, type AudioUploadUrlResponse as a, type PuppetryVoiceList as b, type Usage as c, type CreateAudioVideoParams as d, type CreateAudioUploadUrlParams as e, Puppetry as f, type ApiUploadLimits as g, type AudioUploadBody as h, type CreatePuppetParams as i, type CreatePuppetryTtsParams as j, type JsonRpcId as k, type JsonRpcRequest as l, type JsonRpcResponse as m, type JsonRpcSuccessResponse as n, type ListVoicesParams as o, type PaginatedResponse as p, type Puppet as q, type PuppetryConfig as r, type PuppetryMcpServerInfo as s, type PuppetryRequestRetryEvent as t, type PuppetryTtsResponse as u, type PuppetryVoice as v, type UploadAudioParams as w, type VideoEventType as x, type VideoJob as y, type VideoJobHelpers as z };