The Elevenlabs8 API provides a simple interface to state-of-the-art audio models and features. Follow this guide to learn how to create lifelike speech with our Text to Speech API using direct HTTP requests.

Using the Text to Speech API

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 in the X-API-KEY header with your requests.
.env
ELEVENLABS8_API_KEY=<your_api_key_here>
2

Make your first request

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

Run the code

You should see “Audio generated successfully!” with the History ID and Audio URL, then find an output.mp3 file in your directory.

Request Format

All API requests to TTSLab should include the X-API-KEY header with your API key:
X-API-KEY: your_api_key_here

Model Versions

TTSLab supports different model versions with different request formats:

v3 Models

Use the simplified inputs format with model_id:
{
  "inputs": [
      {
        "text": "The first move is what sets everything in motion.",
        "voice_id": "JBFqnCBsd6RMkjVDRZzb"
      },
      {
        "text": "The second move is what sets everything in motion.",
        "voice_id": "2EiwWnXFnvU5JabPnv8n"
      },
  ],
  "model_id": "eleven_v3"
}

v1/v2 Models

Use the traditional format with additional parameters and config:
{
  "text": "Your text here",
  "voice_id": "voice_id_here",
  "model_id": "eleven_flash_v2_5",
  "config": {
    "stability": 0.5,
    "similarity_boost": 0.75,
    "style": 0.0,
    "use_speaker_boost": true
  }
}
Config Parameters:
  • stability (0.0 - 1.0): Controls voice consistency
  • similarity_boost (0.0 - 1.0): Controls voice similarity to original
  • style (0.0 - 1.0): Controls speaking style
  • use_speaker_boost (boolean): Enhances speaker clarity

Response Handling

The API returns a JSON object with the following structure:
{
  "id": "history_id_here",
  "user": {
    "fullname": "User Full Name",
    "avatar": "https://api.elevenlabs8.com/media/avatars/user.jpg"
  },
  "history_id": "unique_history_id",
  "prompt": "The first move is what sets everything in motion.",
  "model": "ttslab_multilingual_v3",
  "voice": "voice_name_here",
  "config": {
    "stability": 0.5,
    "similarity_boost": 0.75,
    "style": 0.0,
    "use_speaker_boost": true
  },
  "credits_used": 1,
  "status": "completed",
  "shared_url": "https://app.elevenlabs8.com/share/audio_id",
  "created_at": "2024-01-01T12:00:00Z",
  "audio_url": "https://api.elevenlabs8.com/media/audio/output.mp3"
}

Response Fields:

  • id: Unique identifier for the history record
  • user: User information (fullname, avatar)
  • history_id: History tracking ID
  • prompt: The text that was converted to speech
  • model: Model used for generation
  • voice: Voice used for generation
  • config: Configuration parameters used
  • credits_used: Number of credits consumed
  • status: Status of the generation (completed, processing, failed)
  • shared_url: Public shareable URL for the audio
  • created_at: Timestamp of creation
  • audio_url: Direct URL to download the generated audio file

Downloading the Audio:

To get the actual audio file, make a GET request to the audio_url:
# Download the audio file
audio_response = requests.get(response.json()["audio_url"])
with open("output.mp3", "wb") as f:
    f.write(audio_response.content)

Next Steps