Changelog
Changelog
SDK

SDK

Clients

ClientAliasUse it for
TeenageWorksTWSynchronous applications
AsyncTeenageWorksAsyncTWAsync 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")

Resources

ResourcePurpose
audio.speechCreate 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

Response modes

  • Normal methods return parsed results.
  • 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.

Errors and retries

All SDK errors inherit from TeenageWorksError, also available as TWError.

ConditionError
Invalid keyAuthenticationError
Insufficient creditBillingError
Invalid requestUnprocessableEntityError
Rate or concurrency limitRateLimitError
Connection failureAPIConnectionError
TimeoutAPITimeoutError

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.