Get Started with ElevenLabs API

elevenlabs logo
In this guide:

Convert text to natural-sounding speech with a few lines of Python code.

Prerequisites

  • Python 3.7+
  • An ElevenLabs account (free or paid)
  • A text editor

Step 1: Create an API Key

Go to the ElevenLabs API Keys dashboard and create a new key.

Store it in a .env file in your project folder:

ELEVENLABS_API_KEY=your_api_key_here

Step 2: Install the SDK

pip install elevenlabs python-dotenv

To hear audio play automatically, you may need to install MPV and ffmpeg (the package will prompt you if needed).

Step 3: Create Your Script

Create example.py:

from dotenv import load_dotenv
from elevenlabs.client import ElevenLabs
from elevenlabs.play import play
import os

load_dotenv()

elevenlabs = ElevenLabs(api_key=os.getenv("ELEVENLABS_API_KEY"))

audio = elevenlabs.text_to_speech.convert(
    text="The first move is what sets everything in motion.",
    voice_id="JBFqnCBsd6RMkjVDRZzb",
    model_id="eleven_multilingual_v2",
    output_format="mp3_44100_128",
)

play(audio)


Parameters:

  • text: What to convert to speech
  • voice_id: Which voice to use (find in your dashboard)
  • model_id: The AI model (use eleven_multilingual_v2)
  • output_format: Audio quality (mp3_44100_128 is standard)

Step 4: Run It

python example.py

You should hear the audio play through your speakers.

Troubleshooting

Problem Solution
ModuleNotFoundError Run pip install elevenlabs python-dotenv
ELEVENLABS_API_KEY not found Make sure .env is in the same folder as your script
Invalid API key Create a new key in the dashboard and update .env
Audio doesn’t play Save to a file: with open("output.mp3", "wb") as f: f.write(audio)

Quick FAQ 

Marco-profile-pic

Written by

Marco Sansalone

Founder of AI Tool Curator. UX/UI Designer & strategist with 20+ years in the design field.
Elevenlabs

Want to know more?

View Elevenlabs

Also in ElevenLabs Guide

Something Not Working? Tell Us What’s Wrong.

Popular requests move to the top of our queue.
You'll be notified when the tutorial goes live and join our newsletter on AI tools and tutorials.

Find Your Perfect AI Tool