Overview
TheAsyncElevenLabs client class provides asynchronous access to the ElevenLabs API. It’s designed for use with Python’s async/await syntax, making it ideal for applications that need to handle multiple concurrent API requests efficiently.
Initialization
Parameters
str
Your ElevenLabs API key. If not provided, the client will attempt to read from the
ELEVENLABS_API_KEY environment variable.str
The base URL to use for requests from the client. Use this to override the default API endpoint.
ElevenLabsEnvironment
default:"ElevenLabsEnvironment.PRODUCTION"
The environment to use for requests from the client. Import with:
Dict[str, str]
Additional headers to send with every request.
float
default:"240"
The timeout to be used, in seconds, for requests. By default the timeout is 240 seconds, unless a custom httpx client is used, in which case this default is not enforced.
bool
default:"true"
Whether the default httpx client follows redirects or not. This is irrelevant if a custom httpx client is passed in.
httpx.AsyncClient
The httpx async client to use for making requests. A preconfigured async client is used by default, however this is useful should you want to pass in any custom httpx configuration.
Properties
The async client provides access to various API endpoints through properties. All methods on these clients are asynchronous and must be awaited:history
AsyncHistoryClient
text_to_speech
AsyncTextToSpeechClient
text_to_sound_effects
AsyncTextToSoundEffectsClient
text_to_dialogue
AsyncTextToDialogueClient
speech_to_speech
AsyncSpeechToSpeechClient
speech_to_text
AsyncSpeechToTextClient
text_to_voice
AsyncTextToVoiceClient
voices
AsyncVoicesClient
models
AsyncModelsClient
user
AsyncUserClient
usage
AsyncUsageClient
samples
AsyncSamplesClient
audio_isolation
AsyncAudioIsolationClient
audio_native
AsyncAudioNativeClient
dubbing
AsyncDubbingClient
studio
AsyncStudioClient
pronunciation_dictionaries
AsyncPronunciationDictionariesClient
service_accounts
AsyncServiceAccountsClient
webhooks
AsyncWebhooksClient
forced_alignment
AsyncForcedAlignmentClient
conversational_ai
AsyncConversationalAiClient
music
AsyncMusicClient
tokens
AsyncTokensClient
workspace
AsyncWorkspaceClient
with_raw_response
AsyncRawBaseElevenLabs
Example Usage
Basic Async Client Usage
Concurrent API Requests
Async Text-to-Speech Generation
Using Environment Variables
Custom HTTP Client Configuration
Batch Processing with Async
Context Manager Usage
Performance Benefits
The async client is particularly beneficial when:- Making multiple API requests that can run concurrently
- Building web applications with async frameworks (FastAPI, Sanic, etc.)
- Processing large batches of text-to-speech conversions
- Integrating with other async libraries and services