Skip to main content

Overview

The AsyncElevenLabs 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

Access to the async History API for retrieving and managing generated audio history. Type: AsyncHistoryClient

text_to_speech

Access to the async Text-to-Speech API for converting text to speech audio. Type: AsyncTextToSpeechClient

text_to_sound_effects

Access to the async Text-to-Sound Effects API for generating sound effects from text descriptions. Type: AsyncTextToSoundEffectsClient

text_to_dialogue

Access to the async Text-to-Dialogue API for creating multi-voice dialogues. Type: AsyncTextToDialogueClient

speech_to_speech

Access to the async Speech-to-Speech API for voice conversion. Type: AsyncSpeechToSpeechClient

speech_to_text

Access to the async Speech-to-Text API for transcribing audio to text. Type: AsyncSpeechToTextClient

text_to_voice

Access to the async Text-to-Voice API for creating custom voices. Type: AsyncTextToVoiceClient

voices

Access to the async Voices API for managing and retrieving voice models. Type: AsyncVoicesClient

models

Access to the async Models API for retrieving available AI models. Type: AsyncModelsClient

user

Access to the async User API for managing user account information. Type: AsyncUserClient

usage

Access to the async Usage API for tracking API usage and quotas. Type: AsyncUsageClient

samples

Access to the async Samples API for managing voice samples. Type: AsyncSamplesClient

audio_isolation

Access to the async Audio Isolation API for separating audio sources. Type: AsyncAudioIsolationClient

audio_native

Access to the async Audio Native API for creating audio-native projects. Type: AsyncAudioNativeClient

dubbing

Access to the async Dubbing API for video and audio dubbing. Type: AsyncDubbingClient

studio

Access to the async Studio API for managing studio projects. Type: AsyncStudioClient

pronunciation_dictionaries

Access to the async Pronunciation Dictionaries API for managing custom pronunciations. Type: AsyncPronunciationDictionariesClient

service_accounts

Access to the async Service Accounts API for managing service accounts. Type: AsyncServiceAccountsClient

webhooks

Access to the async Webhooks API for managing webhook subscriptions. Type: AsyncWebhooksClient

forced_alignment

Access to the async Forced Alignment API for audio-text alignment. Type: AsyncForcedAlignmentClient

conversational_ai

Access to the async Conversational AI API for building conversational agents. Type: AsyncConversationalAiClient

music

Access to the async Music API for generating AI music. Type: AsyncMusicClient

tokens

Access to the async Tokens API for managing authentication tokens. Type: AsyncTokensClient

workspace

Access to the async Workspace API for managing workspace settings. Type: AsyncWorkspaceClient

with_raw_response

Retrieves a raw implementation of this client that returns raw HTTP responses instead of parsed data. Type: 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
Compared to the synchronous client, the async client can significantly reduce total execution time when handling multiple requests by running them concurrently rather than sequentially.