Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Elevenlabs Elevenlabs python ElevenLabs Init

From Leeroopedia
Knowledge Sources
Domains SDK_Architecture, API_Integration
Last Updated 2026-02-15 00:00 GMT

Overview

Concrete tool for initializing an authenticated ElevenLabs API client provided by the elevenlabs-python SDK.

Description

The ElevenLabs class is the main entry point for the SDK. It extends BaseElevenLabs to add custom sub-clients for realtime TTS, webhooks, music, and speech-to-text. On instantiation, it creates shared HTTP transport via httpx and wires up both auto-generated Fern sub-clients (lazy-loaded via properties) and custom sub-clients (eager-loaded in __init__).

Usage

Import and instantiate this class as the first step in any ElevenLabs workflow. The client instance provides access to all API domains through dot notation (e.g., client.text_to_speech, client.voices, client.speech_to_text).

Code Reference

Source Location

Signature

class ElevenLabs(BaseElevenLabs):
    def __init__(
        self,
        *,
        base_url: typing.Optional[str] = None,
        environment: ElevenLabsEnvironment = ElevenLabsEnvironment.PRODUCTION,
        api_key: typing.Optional[str] = os.getenv("ELEVENLABS_API_KEY"),
        timeout: typing.Optional[float] = 240,
        httpx_client: typing.Optional[httpx.Client] = None,
    ):
        """
        Args:
            base_url: Custom base URL override for all requests.
            environment: API region (PRODUCTION, PRODUCTION_US, PRODUCTION_EU, PRODUCTION_INDIA).
            api_key: ElevenLabs API key. Defaults to ELEVENLABS_API_KEY env var.
            timeout: Request timeout in seconds (default 240).
            httpx_client: Custom httpx.Client for advanced HTTP configuration.
        """

Import

from elevenlabs import ElevenLabs

I/O Contract

Inputs

Name Type Required Description
base_url Optional[str] No Custom base URL; overrides environment setting
environment ElevenLabsEnvironment No API region enum (default: PRODUCTION at api.elevenlabs.io)
api_key Optional[str] No API key; defaults to ELEVENLABS_API_KEY env var
timeout Optional[float] No Request timeout in seconds (default 240)
httpx_client Optional[httpx.Client] No Pre-configured httpx client

Outputs

Name Type Description
(instance) ElevenLabs Client with lazy-loaded sub-clients: text_to_speech, voices, speech_to_text, conversational_ai, music, webhooks, etc.

Usage Examples

Basic Initialization

from elevenlabs import ElevenLabs

# API key from environment variable
client = ElevenLabs()

# Or provide API key directly
client = ElevenLabs(api_key="your-api-key")

Multi-Region Configuration

from elevenlabs import ElevenLabs
from elevenlabs.environment import ElevenLabsEnvironment

# Use EU data residency region
client = ElevenLabs(
    api_key="your-api-key",
    environment=ElevenLabsEnvironment.PRODUCTION_EU,
)

Custom Timeout and HTTP Client

import httpx
from elevenlabs import ElevenLabs

custom_client = httpx.Client(verify=False, proxies="http://proxy:8080")
client = ElevenLabs(
    api_key="your-api-key",
    timeout=60,
    httpx_client=custom_client,
)

Related Pages

Implements Principle

Requires Environment

Uses Heuristic

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment