Getting started overview

This guide provides a structured approach to initiating development with the ElevenLabs API, covering the essential steps from account setup to a successful first API request. The process is designed to enable developers to quickly generate synthesized speech. It includes instructions for registering an ElevenLabs account, locating and generating an API key, and constructing a basic text-to-speech API call.

ElevenLabs offers a free tier that permits up to 5,000 characters of text-to-speech generation per month, suitable for initial testing and proof-of-concept development. Paid plans, such as the Creator plan, begin at $22 per month when billed annually, offering an increased character limit of 100,000 characters.

Before proceeding, ensure you have access to a web browser for account creation and a development environment capable of making HTTP requests, such as curl, Postman, or a programming language with HTTP client libraries like Python or Node.js. ElevenLabs provides official SDKs for Python and Node.js to simplify API interactions.

ElevenLabs Integration Quick Reference

Step What to Do Where
1. Account Creation Sign up for a new ElevenLabs account. ElevenLabs Sign Up Page
2. API Key Retrieval Generate and copy your unique API key. ElevenLabs Account History (Profile / Billing)
3. Endpoint Identification Locate the Text-to-Speech endpoint. ElevenLabs Text-to-Speech API Reference
4. Request Construction Formulate an HTTP POST request with required headers and body. Your chosen development environment (e.g., terminal, IDE)
5. Execution & Testing Send the request and verify audio output. Your chosen development environment

Create an account and get keys

To begin using the ElevenLabs API, you must first create an account and obtain an API key. This key is essential for authenticating your requests and accessing the various ElevenLabs services.

  1. Register for an ElevenLabs Account: Navigate to the ElevenLabs sign-up page. Provide the required information, such as your email address and a password, to create your account. You may need to verify your email address as part of the registration process.
  2. Access Your Profile: Once logged in, locate and click on your profile icon or username, typically found in the top right corner of the ElevenLabs dashboard. This action will usually open a dropdown menu or navigate you to your account settings.
  3. Navigate to API Key Section: Within your account settings or profile page, look for a section labeled "Profile", "Billing", or "API Key". The API key is often found under the "Profile" or "Account History" section on the ElevenLabs website. The direct link to your API key is available on your ElevenLabs Account History page.
  4. Generate or Retrieve Your API Key: If you haven't generated a key before, there will be an option to generate a new API key. If a key already exists, it will be displayed, often partially masked for security. Click the "Reveal" or "Copy" button to view and copy your complete API key. It is critical to treat this key as sensitive information, similar to a password, and store it securely. Avoid embedding it directly in client-side code or public repositories.

The API key is a unique token that identifies your application and authorizes its access to the ElevenLabs API. It should be included in the xi-api-key header of every API request you make. For security best practices regarding API key management, consult general guidelines on Google Developers API key best practices.

Your first request

After acquiring your API key, you can make your first text-to-speech request. This example uses curl, a command-line tool, for simplicity, but the principles apply to any HTTP client library or SDK.

Prerequisites:

  • Your ElevenLabs API key.
  • A terminal or command prompt with curl installed.
  • An internet connection.

API Endpoint:

The primary endpoint for text-to-speech is /v1/text-to-speech/{voice_id}. You need to specify a voice_id to indicate which voice to use for synthesis. A list of available voices and their IDs can be found in the ElevenLabs Text-to-Speech API reference.

For this example, we'll use a common voice ID. The full URL will look like https://api.elevenlabs.io/v1/text-to-speech/21m00Tzpb8AVc8QgCXl7, where 21m00Tzpb8AVc8QgCXl7 is a placeholder for a specific voice ID (e.g., 'Rachel'). This specific ID corresponds to a female voice often used in examples.

Request Structure (curl example):

The request will be a POST request with a JSON body containing the text to be converted to speech. The xi-api-key header will carry your API key.

curl -X POST "https://api.elevenlabs.io/v1/text-to-speech/21m00Tzpb8AVc8QgCXl7" \
  -H "Accept: audio/mpeg" \
  -H "xi-api-key: YOUR_ELEVENLABS_API_KEY" \
  -H "Content-Type: application/json" \
  --data-binary '{"text": "Hello, this is a test from ElevenLabs.", "model_id": "eleven_monolingual_v1", "voice_settings": {"stability": 0.5, "similarity_boost": 0.75}}' \
  --output "output.mp3"

Breaking down the curl command:

  • -X POST: Specifies the HTTP method as POST.
  • "https://api.elevenlabs.io/v1/text-to-speech/21m00Tzpb8AVc8QgCXl7": The target API endpoint, using a specific voice ID.
  • -H "Accept: audio/mpeg": Tells the server to return the audio in MPEG format (MP3).
  • -H "xi-api-key: YOUR_ELEVENLABS_API_KEY": Your unique API key for authentication. Replace YOUR_ELEVENLABS_API_KEY with your actual key.
  • -H "Content-Type: application/json": Informs the server that the request body is in JSON format.
  • --data-binary '{"text": "Hello, this is a test from ElevenLabs.", "model_id": "eleven_monolingual_v1", "voice_settings": {"stability": 0.5, "similarity_boost": 0.75}}': The JSON payload.
    • "text": The actual text to convert to speech.
    • "model_id": Specifies the text-to-speech model to use. eleven_monolingual_v1 is a common default.
    • "voice_settings": An optional object to fine-tune voice characteristics. stability controls consistency, and similarity_boost affects how closely the generated voice matches the original. Refer to ElevenLabs voice settings documentation for more details.
  • --output "output.mp3": Saves the received audio stream directly to a file named output.mp3.

Running the Request:

Open your terminal or command prompt, paste the modified curl command (with your API key), and press Enter. If successful, an output.mp3 file will be created in your current directory containing the synthesized speech. Play this file to confirm the audio generation.

Common next steps

After successfully making your first text-to-speech request, consider these common next steps to expand your integration:

  1. Explore SDKs: For more complex applications, using the official Python or Node.js SDKs can simplify API interactions, handling authentication, request formatting, and response parsing. The SDKs provide idiomatic ways to interact with the ElevenLabs API, reducing boilerplate code.
  2. Voice Customization: Experiment with different voice_id values and voice_settings parameters (stability, similarity boost) to achieve desired vocal styles and emotional tones. The ElevenLabs API reference for voice settings provides comprehensive details on available parameters.
  3. Voice Cloning: Investigate the voice cloning capabilities to generate speech in a voice that highly resembles a provided audio sample. This feature requires uploading a high-quality audio recording of a target voice. Information on ElevenLabs voice cloning API outlines the process and requirements.
  4. Speech to Speech: Explore the Speech to Speech API for transforming spoken audio while maintaining prosody and emotion, or converting it into a different voice.
  5. Error Handling: Implement robust error handling in your application to manage API rate limits, invalid requests, or authentication failures. The ElevenLabs API typically returns standard HTTP status codes and JSON error messages. Proper error handling ensures your application remains resilient.
  6. Monitor Usage: Keep track of your character usage against your ElevenLabs plan limits to avoid unexpected interruptions. Your ElevenLabs account dashboard provides usage statistics.
  7. Security Best Practices: Review and implement best practices for securing your API keys and managing sensitive data, especially in production environments. Consider using environment variables or a secrets management service to store API keys, rather than hardcoding them.

Troubleshooting the first call

If your first API call does not produce the expected audio output or returns an error, consider the following troubleshooting steps:

  1. Verify API Key: Double-check that your xi-api-key header contains the correct and complete API key. A common error is a truncated or incorrect key. Ensure there are no leading or trailing spaces.
  2. Check Voice ID: Confirm that the voice_id in your URL is valid and correctly formatted. An incorrect voice ID will result in a 404 Not Found or similar error. Refer to the ElevenLabs voices documentation for valid IDs.
  3. Review JSON Payload: Ensure your JSON request body is syntactically correct and includes all required fields (text, model_id). Mismatched curly braces, missing commas, or incorrect data types can cause parsing errors. Use a JSON validator if necessary.
  4. Confirm Headers: Verify that all required headers (Accept: audio/mpeg, Content-Type: application/json, and xi-api-key) are present and correctly formatted.
  5. Examine API Response: If you're not saving the output to a file, the API will return a response. For curl, you might remove --output "output.mp3" to see the raw response, which could contain an error message. ElevenLabs typically returns JSON error objects with descriptive messages and status codes (e.g., 400 Bad Request, 401 Unauthorized, 429 Too Many Requests).
  6. Check Character Limit: If you are on the free tier or a limited paid plan, you might have exceeded your monthly character allocation. Check your ElevenLabs account dashboard for current usage statistics. An exceeded limit usually results in a 429 error.
  7. Network Connectivity: Ensure your development environment has stable internet connectivity and no firewalls or proxies are blocking access to api.elevenlabs.io.
  8. SDK Specific Issues: If using an SDK, ensure it's correctly installed and configured. Check the specific SDK documentation for common pitfalls related to initialization or method calls.
  9. Consult ElevenLabs Documentation: The official ElevenLabs documentation provides comprehensive guides, API references, and troubleshooting sections that can offer more specific solutions.

By systematically checking these points, you can identify and resolve most issues encountered during your initial ElevenLabs API integration.