Skip to main content

Overview

The AsyncElevenLabs client allows you to make API calls asynchronously using Python’s asyncio framework. This is particularly useful when you need to make multiple API calls concurrently or integrate with async web frameworks.

Installation

The async client is included in the standard ElevenLabs package:

Basic Usage

Here’s how to use the async client to list available models:

Configuration

The AsyncElevenLabs client accepts the same configuration parameters as the synchronous client:
str
required
Your ElevenLabs API key. Defaults to the ELEVENLABS_API_KEY environment variable.
str
The base URL for API requests. Override this for testing or custom endpoints.
ElevenLabsEnvironment
default:"PRODUCTION"
The environment to use for requests from the client.
float
default:240
The timeout in seconds for requests. Default is 240 seconds (4 minutes).
httpx.AsyncClient
A custom async httpx client for advanced configuration.

Common Async Operations

Text-to-Speech Generation

Listing Voices

Working with Pronunciation Dictionaries

Concurrent Operations

One of the main benefits of the async client is the ability to run multiple operations concurrently:

Integration with Web Frameworks

The async client integrates seamlessly with async web frameworks like FastAPI:

Best Practices

When working with the async client, ensure proper cleanup of resources:
Always wrap async operations in try-except blocks to handle potential errors:
When you need to perform multiple operations, use asyncio.gather to run them concurrently:
The async client provides the same functionality as the synchronous client. All methods that perform I/O operations are awaitable.

Next Steps

Error Handling

Learn how to handle errors in async operations

Pronunciation Dictionaries

Create custom pronunciation rules