talksign 0.2.0__py3-none-any.whl

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.
talksign/_resources.py ADDED
@@ -0,0 +1,775 @@
1
+ """API resources. Each sync class has an async twin with the same methods (``async def``)."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import asyncio
6
+ import time
7
+ from collections.abc import Mapping, Sequence
8
+ from typing import TYPE_CHECKING, Any, cast
9
+
10
+ from . import _requests as r
11
+ from ._base import FileInput
12
+ from ._errors import TalksignError
13
+ from .types import (
14
+ AvatarQualityResult,
15
+ AvatarResponse,
16
+ AvatarsResponse,
17
+ Balance,
18
+ BrowserToken,
19
+ DeleteResponse,
20
+ GlossResponse,
21
+ Job,
22
+ JobList,
23
+ Meeting,
24
+ ModelsResponse,
25
+ RealtimeResponse,
26
+ SpeechToSpeechResponse,
27
+ StudioResponse,
28
+ Upload,
29
+ UsageList,
30
+ VoiceJsonResponse,
31
+ VoiceList,
32
+ Warmup,
33
+ )
34
+
35
+ if TYPE_CHECKING:
36
+ from ._base import AsyncHTTP, SyncHTTP
37
+
38
+
39
+ class JobWaitTimeout(TalksignError):
40
+ """``jobs.wait`` gave up before the job finished (the job keeps running)."""
41
+
42
+
43
+ # ======================================================================
44
+ # Sync
45
+ # ======================================================================
46
+ class _Sync:
47
+ def __init__(self, client: SyncHTTP) -> None:
48
+ self._client = client
49
+
50
+
51
+ class SpeechToSign(_Sync):
52
+ """Echo 2.0: text or speech to sign language video."""
53
+
54
+ def realtime(
55
+ self,
56
+ text: str | None = None,
57
+ *,
58
+ audio: FileInput | None = None,
59
+ language: str | None = None,
60
+ avatar: str | None = None,
61
+ model: str | None = None,
62
+ duration_seconds: float | None = None,
63
+ spoken_language: str | None = None,
64
+ config: Mapping[str, Any] | None = None,
65
+ idempotency_key: str | None = None,
66
+ timeout: float | None = None,
67
+ ) -> RealtimeResponse:
68
+ """Playlist of short signed clip URLs for ``text`` (or transcribed ``audio``)."""
69
+ return cast(
70
+ RealtimeResponse,
71
+ self._client.request(
72
+ r.realtime(
73
+ text,
74
+ audio=audio,
75
+ language=language,
76
+ avatar=avatar,
77
+ model=model,
78
+ duration_seconds=duration_seconds,
79
+ spoken_language=spoken_language,
80
+ config=config,
81
+ idempotency_key=idempotency_key,
82
+ timeout=timeout,
83
+ )
84
+ ),
85
+ )
86
+
87
+ def create(
88
+ self,
89
+ text: str,
90
+ *,
91
+ mode: str | None = None,
92
+ language: str | None = None,
93
+ avatar: str | None = None,
94
+ model: str | None = None,
95
+ duration_seconds: float | None = None,
96
+ config: Mapping[str, Any] | None = None,
97
+ idempotency_key: str | None = None,
98
+ timeout: float | None = None,
99
+ ) -> dict[str, Any]:
100
+ """``POST /speech-to-sign``: realtime playlist by default, a studio video with ``mode="studio"``."""
101
+ return cast(
102
+ dict[str, Any],
103
+ self._client.request(
104
+ r.create(
105
+ text,
106
+ mode=mode,
107
+ language=language,
108
+ avatar=avatar,
109
+ model=model,
110
+ duration_seconds=duration_seconds,
111
+ config=config,
112
+ idempotency_key=idempotency_key,
113
+ timeout=timeout,
114
+ )
115
+ ),
116
+ )
117
+
118
+ def studio(
119
+ self,
120
+ text: str,
121
+ *,
122
+ language: str | None = None,
123
+ avatar: str | None = None,
124
+ model: str | None = None,
125
+ duration_seconds: float | None = None,
126
+ config: Mapping[str, Any] | None = None,
127
+ async_: bool = False,
128
+ idempotency_key: str | None = None,
129
+ timeout: float | None = None,
130
+ ) -> StudioResponse | Job:
131
+ """One rendered MP4. With ``async_=True`` a :class:`Job` is returned; use ``jobs.wait``."""
132
+ return cast(
133
+ "StudioResponse | Job",
134
+ self._client.request(
135
+ r.studio(
136
+ text,
137
+ language=language,
138
+ avatar=avatar,
139
+ model=model,
140
+ duration_seconds=duration_seconds,
141
+ config=config,
142
+ async_=async_,
143
+ idempotency_key=idempotency_key,
144
+ timeout=timeout,
145
+ )
146
+ ),
147
+ )
148
+
149
+ def gloss(
150
+ self,
151
+ text: str,
152
+ *,
153
+ language: str | None = None,
154
+ idempotency_key: str | None = None,
155
+ timeout: float | None = None,
156
+ ) -> GlossResponse:
157
+ """Sign language gloss tokens for ``text``."""
158
+ return cast(
159
+ GlossResponse,
160
+ self._client.request(r.gloss(text, language=language, idempotency_key=idempotency_key, timeout=timeout)),
161
+ )
162
+
163
+ def video(self, request_id: str, *, timeout: float | None = None) -> bytes:
164
+ """MP4 bytes of a studio render (kept 7 days)."""
165
+ return cast(bytes, self._client.request(r.video(request_id, timeout=timeout)))
166
+
167
+
168
+ class Avatars(_Sync):
169
+ def list(self, *, language: str | None = None) -> AvatarsResponse:
170
+ """Every avatar you can use, each with ``idle`` (signed idle-loop URL or ``None``). Free."""
171
+ return cast(AvatarsResponse, self._client.request(r.avatars_list(language)))
172
+
173
+ def get(self, avatar_id: str, *, language: str | None = None) -> AvatarResponse:
174
+ """One avatar (preset id like ``arthur`` or your custom id), with ``idle``. Free."""
175
+ return cast(AvatarResponse, self._client.request(r.avatars_get(avatar_id, language)))
176
+
177
+ def create(
178
+ self,
179
+ file: FileInput,
180
+ *,
181
+ name: str | None = None,
182
+ strict: bool | None = None,
183
+ idempotency_key: str | None = None,
184
+ timeout: float | None = None,
185
+ ) -> AvatarResponse:
186
+ """Upload a custom avatar photo/video. Adds a paid avatar slot when no free slot is owned."""
187
+ return cast(
188
+ AvatarResponse,
189
+ self._client.request(
190
+ r.avatars_create(file, name=name, strict=strict, idempotency_key=idempotency_key, timeout=timeout)
191
+ ),
192
+ )
193
+
194
+ def delete(self, avatar_id: str) -> DeleteResponse:
195
+ return cast(DeleteResponse, self._client.request(r.avatars_delete(avatar_id)))
196
+
197
+ def validate(self, file: FileInput, *, timeout: float | None = None) -> AvatarQualityResult:
198
+ """Free quality pre-check of an avatar photo/video (nothing stored)."""
199
+ return cast(AvatarQualityResult, self._client.request(r.avatars_validate(file, timeout=timeout)))
200
+
201
+
202
+ class SignToSpeech(_Sync):
203
+ """Palm (sign to speech). Not available in the API yet: the server answers 501 ``not_available``."""
204
+
205
+ def create(self, video: FileInput | None = None, **fields: Any) -> dict[str, Any]:
206
+ return cast(dict[str, Any], self._client.request(r.sign_to_speech(video, fields)))
207
+
208
+
209
+ class SpeechToSpeech(_Sync):
210
+ def create(
211
+ self,
212
+ text: str,
213
+ *,
214
+ to_lang: str,
215
+ from_lang: str | None = None,
216
+ model: str | None = None,
217
+ duration_seconds: float | None = None,
218
+ idempotency_key: str | None = None,
219
+ timeout: float | None = None,
220
+ ) -> SpeechToSpeechResponse:
221
+ """Translate text between spoken languages."""
222
+ return cast(
223
+ SpeechToSpeechResponse,
224
+ self._client.request(
225
+ r.speech_to_speech(
226
+ text,
227
+ to_lang=to_lang,
228
+ from_lang=from_lang,
229
+ model=model,
230
+ duration_seconds=duration_seconds,
231
+ idempotency_key=idempotency_key,
232
+ timeout=timeout,
233
+ )
234
+ ),
235
+ )
236
+
237
+
238
+ class VoiceResource(_Sync):
239
+ def create(
240
+ self,
241
+ text: str,
242
+ *,
243
+ voice: str | None = None,
244
+ idempotency_key: str | None = None,
245
+ timeout: float | None = None,
246
+ ) -> bytes:
247
+ """MP3 audio bytes for ``text``."""
248
+ return cast(
249
+ bytes,
250
+ self._client.request(
251
+ r.voice_create(
252
+ text, voice=voice, response_format=None, idempotency_key=idempotency_key, timeout=timeout
253
+ )
254
+ ),
255
+ )
256
+
257
+ def create_json(
258
+ self,
259
+ text: str,
260
+ *,
261
+ voice: str | None = None,
262
+ idempotency_key: str | None = None,
263
+ timeout: float | None = None,
264
+ ) -> VoiceJsonResponse:
265
+ """Speech as JSON (base64 audio + usage)."""
266
+ return cast(
267
+ VoiceJsonResponse,
268
+ self._client.request(
269
+ r.voice_create(
270
+ text, voice=voice, response_format="json", idempotency_key=idempotency_key, timeout=timeout
271
+ )
272
+ ),
273
+ )
274
+
275
+ def voices(self) -> VoiceList:
276
+ return cast(VoiceList, self._client.request(r.voice_voices()))
277
+
278
+
279
+ class Jobs(_Sync):
280
+ def create(
281
+ self,
282
+ type: str, # noqa: A002
283
+ *,
284
+ audio: FileInput | None = None,
285
+ video: FileInput | None = None,
286
+ photo: FileInput | None = None,
287
+ idempotency_key: str | None = None,
288
+ timeout: float | None = None,
289
+ **fields: Any,
290
+ ) -> Job:
291
+ """Queue an async job (``sign_video``, ``captions`` or ``sign_morph``). Other fields go in the body."""
292
+ return cast(
293
+ Job,
294
+ self._client.request(
295
+ r.jobs_create(
296
+ type,
297
+ files={"audio": audio, "video": video, "photo": photo},
298
+ fields=fields,
299
+ idempotency_key=idempotency_key,
300
+ timeout=timeout,
301
+ )
302
+ ),
303
+ )
304
+
305
+ def get(self, job_id: str) -> Job:
306
+ return cast(Job, self._client.request(r.jobs_get(job_id)))
307
+
308
+ def list(self, *, limit: int | None = None, starting_after: str | None = None) -> JobList:
309
+ return cast(JobList, self._client.request(r.jobs_list(limit, starting_after)))
310
+
311
+ def cancel(self, job_id: str) -> Job:
312
+ return cast(Job, self._client.request(r.jobs_cancel(job_id)))
313
+
314
+ def wait(self, job_id: str, *, poll_interval: float = 2.0, timeout: float = 900.0) -> Job:
315
+ """Poll until the job is ``succeeded``, ``failed`` or ``canceled`` and return it."""
316
+ deadline = time.monotonic() + timeout
317
+ while True:
318
+ job = self.get(job_id)
319
+ if job.get("status") in r.TERMINAL_JOB_STATUSES:
320
+ return job
321
+ if time.monotonic() + poll_interval > deadline:
322
+ raise JobWaitTimeout(
323
+ f"Job {job_id} still {job.get('status')} after {timeout:.0f}s.", code="wait_timeout"
324
+ )
325
+ time.sleep(poll_interval)
326
+
327
+
328
+ class Uploads(_Sync):
329
+ def create(self, *, content_type: str, size_bytes: int) -> Upload:
330
+ """Signed PUT link for a large source video (pass its ``id`` as ``video_upload_id``)."""
331
+ return cast(Upload, self._client.request(r.uploads_create(content_type, size_bytes)))
332
+
333
+
334
+ class Meetings(_Sync):
335
+ def create(
336
+ self,
337
+ meeting_url: str,
338
+ *,
339
+ disclosure_accepted: bool,
340
+ avatar: str | None = None,
341
+ background: str | None = None,
342
+ idempotency_key: str | None = None,
343
+ ) -> Meeting:
344
+ return cast(
345
+ Meeting,
346
+ self._client.request(
347
+ r.meetings_create(
348
+ meeting_url,
349
+ disclosure_accepted=disclosure_accepted,
350
+ avatar=avatar,
351
+ background=background,
352
+ idempotency_key=idempotency_key,
353
+ )
354
+ ),
355
+ )
356
+
357
+ def get(self, meeting_id: str) -> Meeting:
358
+ return cast(Meeting, self._client.request(r.meetings_get(meeting_id)))
359
+
360
+ def stop(self, meeting_id: str) -> Meeting:
361
+ return cast(Meeting, self._client.request(r.meetings_stop(meeting_id)))
362
+
363
+
364
+ class Models(_Sync):
365
+ def list(self) -> ModelsResponse:
366
+ return cast(ModelsResponse, self._client.request(r.models_list()))
367
+
368
+ def warmup(self) -> Warmup:
369
+ """Wakes the signing engine (free). Call it when your user opens the interpreter view."""
370
+ return cast(Warmup, self._client.request(r.warmup()))
371
+
372
+ def __call__(self, **kwargs: Any) -> Any:
373
+ """Shortcut for ``list()``."""
374
+ return self.list(**kwargs)
375
+
376
+
377
+ class UsageResource(_Sync):
378
+ def list(
379
+ self,
380
+ *,
381
+ from_: str | int | None = None,
382
+ to: str | int | None = None,
383
+ limit: int | None = None,
384
+ starting_after: str | None = None,
385
+ ) -> UsageList:
386
+ return cast(UsageList, self._client.request(r.usage_list(from_, to, limit, starting_after)))
387
+
388
+ def __call__(self, **kwargs: Any) -> Any:
389
+ """Shortcut for ``list()``."""
390
+ return self.list(**kwargs)
391
+
392
+
393
+ class BalanceResource(_Sync):
394
+ def retrieve(self) -> Balance:
395
+ return cast(Balance, self._client.request(r.balance()))
396
+
397
+ def __call__(self, **kwargs: Any) -> Any:
398
+ """Shortcut for ``retrieve()``."""
399
+ return self.retrieve(**kwargs)
400
+
401
+
402
+ class Tokens(_Sync):
403
+ """Short-lived browser tokens (``tst_…``): mint on your server, hand to a web page."""
404
+
405
+ def create(
406
+ self,
407
+ *,
408
+ expires_in: int | None = None,
409
+ allowed_origins: Sequence[str] | None = None,
410
+ scopes: Sequence[str] | None = None,
411
+ ) -> BrowserToken:
412
+ """Mints a token (60–3600 s, default 600). Set ``allowed_origins`` in production. Free."""
413
+ return cast(BrowserToken, self._client.request(r.tokens_create(expires_in, allowed_origins, scopes)))
414
+
415
+
416
+ # ======================================================================
417
+ # Async
418
+ # ======================================================================
419
+ class _Async:
420
+ def __init__(self, client: AsyncHTTP) -> None:
421
+ self._client = client
422
+
423
+
424
+ class AsyncSpeechToSign(_Async):
425
+ """Echo 2.0: text or speech to sign language video."""
426
+
427
+ async def realtime(
428
+ self,
429
+ text: str | None = None,
430
+ *,
431
+ audio: FileInput | None = None,
432
+ language: str | None = None,
433
+ avatar: str | None = None,
434
+ model: str | None = None,
435
+ duration_seconds: float | None = None,
436
+ spoken_language: str | None = None,
437
+ config: Mapping[str, Any] | None = None,
438
+ idempotency_key: str | None = None,
439
+ timeout: float | None = None,
440
+ ) -> RealtimeResponse:
441
+ return cast(
442
+ RealtimeResponse,
443
+ await self._client.request(
444
+ r.realtime(
445
+ text,
446
+ audio=audio,
447
+ language=language,
448
+ avatar=avatar,
449
+ model=model,
450
+ duration_seconds=duration_seconds,
451
+ spoken_language=spoken_language,
452
+ config=config,
453
+ idempotency_key=idempotency_key,
454
+ timeout=timeout,
455
+ )
456
+ ),
457
+ )
458
+
459
+ async def create(
460
+ self,
461
+ text: str,
462
+ *,
463
+ mode: str | None = None,
464
+ language: str | None = None,
465
+ avatar: str | None = None,
466
+ model: str | None = None,
467
+ duration_seconds: float | None = None,
468
+ config: Mapping[str, Any] | None = None,
469
+ idempotency_key: str | None = None,
470
+ timeout: float | None = None,
471
+ ) -> dict[str, Any]:
472
+ return cast(
473
+ dict[str, Any],
474
+ await self._client.request(
475
+ r.create(
476
+ text,
477
+ mode=mode,
478
+ language=language,
479
+ avatar=avatar,
480
+ model=model,
481
+ duration_seconds=duration_seconds,
482
+ config=config,
483
+ idempotency_key=idempotency_key,
484
+ timeout=timeout,
485
+ )
486
+ ),
487
+ )
488
+
489
+ async def studio(
490
+ self,
491
+ text: str,
492
+ *,
493
+ language: str | None = None,
494
+ avatar: str | None = None,
495
+ model: str | None = None,
496
+ duration_seconds: float | None = None,
497
+ config: Mapping[str, Any] | None = None,
498
+ async_: bool = False,
499
+ idempotency_key: str | None = None,
500
+ timeout: float | None = None,
501
+ ) -> StudioResponse | Job:
502
+ return cast(
503
+ "StudioResponse | Job",
504
+ await self._client.request(
505
+ r.studio(
506
+ text,
507
+ language=language,
508
+ avatar=avatar,
509
+ model=model,
510
+ duration_seconds=duration_seconds,
511
+ config=config,
512
+ async_=async_,
513
+ idempotency_key=idempotency_key,
514
+ timeout=timeout,
515
+ )
516
+ ),
517
+ )
518
+
519
+ async def gloss(
520
+ self,
521
+ text: str,
522
+ *,
523
+ language: str | None = None,
524
+ idempotency_key: str | None = None,
525
+ timeout: float | None = None,
526
+ ) -> GlossResponse:
527
+ return cast(
528
+ GlossResponse,
529
+ await self._client.request(
530
+ r.gloss(text, language=language, idempotency_key=idempotency_key, timeout=timeout)
531
+ ),
532
+ )
533
+
534
+ async def video(self, request_id: str, *, timeout: float | None = None) -> bytes:
535
+ return cast(bytes, await self._client.request(r.video(request_id, timeout=timeout)))
536
+
537
+
538
+ class AsyncAvatars(_Async):
539
+ async def list(self, *, language: str | None = None) -> AvatarsResponse:
540
+ """Every avatar you can use, each with ``idle`` (signed idle-loop URL or ``None``). Free."""
541
+ return cast(AvatarsResponse, await self._client.request(r.avatars_list(language)))
542
+
543
+ async def get(self, avatar_id: str, *, language: str | None = None) -> AvatarResponse:
544
+ """One avatar (preset id like ``arthur`` or your custom id), with ``idle``. Free."""
545
+ return cast(AvatarResponse, await self._client.request(r.avatars_get(avatar_id, language)))
546
+
547
+ async def create(
548
+ self,
549
+ file: FileInput,
550
+ *,
551
+ name: str | None = None,
552
+ strict: bool | None = None,
553
+ idempotency_key: str | None = None,
554
+ timeout: float | None = None,
555
+ ) -> AvatarResponse:
556
+ return cast(
557
+ AvatarResponse,
558
+ await self._client.request(
559
+ r.avatars_create(file, name=name, strict=strict, idempotency_key=idempotency_key, timeout=timeout)
560
+ ),
561
+ )
562
+
563
+ async def delete(self, avatar_id: str) -> DeleteResponse:
564
+ return cast(DeleteResponse, await self._client.request(r.avatars_delete(avatar_id)))
565
+
566
+ async def validate(self, file: FileInput, *, timeout: float | None = None) -> AvatarQualityResult:
567
+ return cast(AvatarQualityResult, await self._client.request(r.avatars_validate(file, timeout=timeout)))
568
+
569
+
570
+ class AsyncSignToSpeech(_Async):
571
+ async def create(self, video: FileInput | None = None, **fields: Any) -> dict[str, Any]:
572
+ return cast(dict[str, Any], await self._client.request(r.sign_to_speech(video, fields)))
573
+
574
+
575
+ class AsyncSpeechToSpeech(_Async):
576
+ async def create(
577
+ self,
578
+ text: str,
579
+ *,
580
+ to_lang: str,
581
+ from_lang: str | None = None,
582
+ model: str | None = None,
583
+ duration_seconds: float | None = None,
584
+ idempotency_key: str | None = None,
585
+ timeout: float | None = None,
586
+ ) -> SpeechToSpeechResponse:
587
+ return cast(
588
+ SpeechToSpeechResponse,
589
+ await self._client.request(
590
+ r.speech_to_speech(
591
+ text,
592
+ to_lang=to_lang,
593
+ from_lang=from_lang,
594
+ model=model,
595
+ duration_seconds=duration_seconds,
596
+ idempotency_key=idempotency_key,
597
+ timeout=timeout,
598
+ )
599
+ ),
600
+ )
601
+
602
+
603
+ class AsyncVoiceResource(_Async):
604
+ async def create(
605
+ self,
606
+ text: str,
607
+ *,
608
+ voice: str | None = None,
609
+ idempotency_key: str | None = None,
610
+ timeout: float | None = None,
611
+ ) -> bytes:
612
+ """MP3 audio bytes for ``text``."""
613
+ return cast(
614
+ bytes,
615
+ await self._client.request(
616
+ r.voice_create(
617
+ text, voice=voice, response_format=None, idempotency_key=idempotency_key, timeout=timeout
618
+ )
619
+ ),
620
+ )
621
+
622
+ async def create_json(
623
+ self,
624
+ text: str,
625
+ *,
626
+ voice: str | None = None,
627
+ idempotency_key: str | None = None,
628
+ timeout: float | None = None,
629
+ ) -> VoiceJsonResponse:
630
+ """Speech as JSON (base64 audio + usage)."""
631
+ return cast(
632
+ VoiceJsonResponse,
633
+ await self._client.request(
634
+ r.voice_create(
635
+ text, voice=voice, response_format="json", idempotency_key=idempotency_key, timeout=timeout
636
+ )
637
+ ),
638
+ )
639
+
640
+ async def voices(self) -> VoiceList:
641
+ return cast(VoiceList, await self._client.request(r.voice_voices()))
642
+
643
+
644
+ class AsyncJobs(_Async):
645
+ async def create(
646
+ self,
647
+ type: str, # noqa: A002
648
+ *,
649
+ audio: FileInput | None = None,
650
+ video: FileInput | None = None,
651
+ photo: FileInput | None = None,
652
+ idempotency_key: str | None = None,
653
+ timeout: float | None = None,
654
+ **fields: Any,
655
+ ) -> Job:
656
+ return cast(
657
+ Job,
658
+ await self._client.request(
659
+ r.jobs_create(
660
+ type,
661
+ files={"audio": audio, "video": video, "photo": photo},
662
+ fields=fields,
663
+ idempotency_key=idempotency_key,
664
+ timeout=timeout,
665
+ )
666
+ ),
667
+ )
668
+
669
+ async def get(self, job_id: str) -> Job:
670
+ return cast(Job, await self._client.request(r.jobs_get(job_id)))
671
+
672
+ async def list(self, *, limit: int | None = None, starting_after: str | None = None) -> JobList:
673
+ return cast(JobList, await self._client.request(r.jobs_list(limit, starting_after)))
674
+
675
+ async def cancel(self, job_id: str) -> Job:
676
+ return cast(Job, await self._client.request(r.jobs_cancel(job_id)))
677
+
678
+ async def wait(self, job_id: str, *, poll_interval: float = 2.0, timeout: float = 900.0) -> Job:
679
+ loop = asyncio.get_running_loop()
680
+ deadline = loop.time() + timeout
681
+ while True:
682
+ job = await self.get(job_id)
683
+ if job.get("status") in r.TERMINAL_JOB_STATUSES:
684
+ return job
685
+ if loop.time() + poll_interval > deadline:
686
+ raise JobWaitTimeout(
687
+ f"Job {job_id} still {job.get('status')} after {timeout:.0f}s.", code="wait_timeout"
688
+ )
689
+ await asyncio.sleep(poll_interval)
690
+
691
+
692
+ class AsyncUploads(_Async):
693
+ async def create(self, *, content_type: str, size_bytes: int) -> Upload:
694
+ return cast(Upload, await self._client.request(r.uploads_create(content_type, size_bytes)))
695
+
696
+
697
+ class AsyncMeetings(_Async):
698
+ async def create(
699
+ self,
700
+ meeting_url: str,
701
+ *,
702
+ disclosure_accepted: bool,
703
+ avatar: str | None = None,
704
+ background: str | None = None,
705
+ idempotency_key: str | None = None,
706
+ ) -> Meeting:
707
+ return cast(
708
+ Meeting,
709
+ await self._client.request(
710
+ r.meetings_create(
711
+ meeting_url,
712
+ disclosure_accepted=disclosure_accepted,
713
+ avatar=avatar,
714
+ background=background,
715
+ idempotency_key=idempotency_key,
716
+ )
717
+ ),
718
+ )
719
+
720
+ async def get(self, meeting_id: str) -> Meeting:
721
+ return cast(Meeting, await self._client.request(r.meetings_get(meeting_id)))
722
+
723
+ async def stop(self, meeting_id: str) -> Meeting:
724
+ return cast(Meeting, await self._client.request(r.meetings_stop(meeting_id)))
725
+
726
+
727
+ class AsyncModels(_Async):
728
+ async def list(self) -> ModelsResponse:
729
+ return cast(ModelsResponse, await self._client.request(r.models_list()))
730
+
731
+ async def warmup(self) -> Warmup:
732
+ return cast(Warmup, await self._client.request(r.warmup()))
733
+
734
+ async def __call__(self, **kwargs: Any) -> Any:
735
+ """Shortcut for ``list()``."""
736
+ return await self.list(**kwargs)
737
+
738
+
739
+ class AsyncUsageResource(_Async):
740
+ async def list(
741
+ self,
742
+ *,
743
+ from_: str | int | None = None,
744
+ to: str | int | None = None,
745
+ limit: int | None = None,
746
+ starting_after: str | None = None,
747
+ ) -> UsageList:
748
+ return cast(UsageList, await self._client.request(r.usage_list(from_, to, limit, starting_after)))
749
+
750
+ async def __call__(self, **kwargs: Any) -> Any:
751
+ """Shortcut for ``list()``."""
752
+ return await self.list(**kwargs)
753
+
754
+
755
+ class AsyncBalanceResource(_Async):
756
+ async def retrieve(self) -> Balance:
757
+ return cast(Balance, await self._client.request(r.balance()))
758
+
759
+ async def __call__(self, **kwargs: Any) -> Any:
760
+ """Shortcut for ``retrieve()``."""
761
+ return await self.retrieve(**kwargs)
762
+
763
+
764
+ class AsyncTokens(_Async):
765
+ """Short-lived browser tokens (``tst_…``): mint on your server, hand to a web page."""
766
+
767
+ async def create(
768
+ self,
769
+ *,
770
+ expires_in: int | None = None,
771
+ allowed_origins: Sequence[str] | None = None,
772
+ scopes: Sequence[str] | None = None,
773
+ ) -> BrowserToken:
774
+ """Mints a token (60–3600 s, default 600). Set ``allowed_origins`` in production. Free."""
775
+ return cast(BrowserToken, await self._client.request(r.tokens_create(expires_in, allowed_origins, scopes)))