
| Client | Alias | Use it for |
|---|---|---|
TeenageWorks | TW | Synchronous applications |
AsyncTeenageWorks | AsyncTW | Async applications |
Create one client per process or worker and reuse it. This keeps one connection pool available across requests.
Python
from teenageworks import AsyncTeenageWorks
async with AsyncTeenageWorks() as client:
speech = await client.audio.speech.create(
model="teen-v1",
voice="default",
input="Generate asynchronously.",
response_format="mp3",
)
await speech.write_to_file("speech.mp3")| Resource | Purpose |
|---|---|
audio.speech | Create or stream speech |
voices.list() | List public voices |
models.list() | List available models |
capabilities.retrieve() | Inspect formats and supported features |
account.usage.retrieve() | Read project usage and balance |
with_raw_response also exposes status, headers, and request ID.with_streaming_response keeps audio incremental and must be closed or used as a context manager.Use close() when you do not use a context manager.
All SDK errors inherit from TeenageWorksError, also available as TWError.
| Condition | Error |
|---|---|
| Invalid key | AuthenticationError |
| Insufficient credit | BillingError |
| Invalid request | UnprocessableEntityError |
| Rate or concurrency limit | RateLimitError |
| Connection failure | APIConnectionError |
| Timeout | APITimeoutError |
Connection failures, rate limits, and selected server failures may retry. Authentication, billing, validation, and unsupported-feature errors do not. A stream is never restarted automatically after audio bytes have been delivered.
On this page