Skip to navigation

ElevenAPI quickstart

Learn how to make your first ElevenLabs API request.

By the end of this guide you will have ElevenLabs set up in your project and can make your first text to speech request. There are two ways to get there: let your coding agent do the setup, or do it by hand.

For guides covering other capabilities — streaming, voice cloning, speech-to-text — see the Tutorials section.

Set up with your coding agent

You do not need an account or an API key before you start. Paste this into your coding agent:

Add ElevenLabs to my project: run `npx -y @elevenlabs/cli@latest onboard init` and follow what it prints.

The ElevenLabs CLI takes it from there and tells your agent each step. Your browser opens once so you can sign in or create an account and click Authorize. The key is saved in your project’s env file (.env.local, or .env in a Python project) and kept out of git; it is never shown in the chat. The agent then asks what you’d like to build, installs the SDK, adds the code to your app, and asks whether to send a test request.

If your agent runs somewhere your browser cannot reach, such as a remote machine over SSH or a cloud sandbox, the CLI asks you to create a key yourself and paste it into the env file, then continues. The command needs Node.js for npx. Without it, install the ElevenLabs CLI with Homebrew (macOS and Linux) or Scoop (Windows), or update it if you already have it (brew upgrade elevenlabs, scoop update elevenlabs), and ask your agent to run elevenlabs onboard init instead.

Set up by hand

1

Create an API key

Create an API key in the dashboard here, which you’ll use to securely access the API.

Store the key as a managed secret and pass it to the SDKs either as an environment variable via an .env file, or directly in your app’s configuration depending on your preference.

.env
ELEVENLABS_API_KEY=<your_api_key_here>
2

Install the SDK

We’ll also use the dotenv library to load our API key from an environment variable.

pip install elevenlabs
pip install python-dotenv

To play the audio through your speakers, you may be prompted to install MPV and/or ffmpeg.

3

Make your first request

Create a new file named example.py or example.mts, depending on your language of choice and add the following code:

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", # "George" - browse voices at elevenlabs.io/app/voice-library
model_id="eleven_v4",
output_format="mp3_44100_128",
)
play(audio)

Then run it:

python example.py

You should hear the audio play through your speakers.

Next steps