Authentication overview

ElevenLabs employs API keys as its primary authentication mechanism to control access to its suite of voice AI services, including text-to-speech, speech-to-speech, and voice cloning. This method requires developers to obtain a unique API key from their ElevenLabs account and include it in the headers of their HTTP requests. The API key serves as a bearer token, verifying the identity of the client application and authorizing its interactions with the ElevenLabs API endpoints. This approach is commonly used in RESTful APIs for its simplicity and effectiveness in securing communication over HTTPS.

API keys are a fundamental component of many web service architectures, providing a straightforward way for services to identify and authenticate calling clients without requiring complex login flows for each request. For ElevenLabs, this means that every API call must carry a valid and active API key to be processed successfully. This system facilitates secure integration of ElevenLabs's voice generation capabilities into various applications, from web platforms to mobile apps and backend services, by ensuring that only authorized users can access and utilize the computational resources.

Supported authentication methods

ElevenLabs exclusively supports API key authentication for programmatic access to its services. This approach simplifies the integration process while maintaining a necessary level of security for transactions. The API key acts as a secret token that must be protected like a password.

Method When to Use Security Level
API Key (Bearer Token) All programmatic access to ElevenLabs APIs for direct integration from servers or secure client-side environments. Moderate to High (when properly managed and transmitted over HTTPS).

The API key is transmitted in the xi-api-key header for all ElevenLabs API requests. This method is consistent across all endpoints, providing a unified authentication experience for developers. While other authentication methods like OAuth 2.0 offer more granular permission control and are common for user-facing applications, the API key system is well-suited for server-to-server or trusted client integrations where a single key can manage access for a specific application or service instance.

For more detailed information on API key usage, refer to the ElevenLabs API reference documentation.

Getting your credentials

To obtain your ElevenLabs API key, you must have an active ElevenLabs account. The process involves navigating to your account settings within the ElevenLabs web interface:

  1. Create an ElevenLabs Account: If you don't already have one, sign up for an account on the ElevenLabs homepage.
  2. Access Your Profile Settings: Log in to your ElevenLabs account. Typically, you can find your profile or account settings by clicking on your user icon or name in the top right corner of the dashboard.
  3. Locate the API Key Section: Within your profile or account settings, look for a section labeled 'API Key' or 'Developer Settings'. The exact navigation path may vary slightly but is usually intuitive.
  4. Generate or Reveal Your API Key: Your API key will either be displayed (often partially masked for security) or you'll have an option to generate a new one. Click the 'Reveal' or 'Generate New Key' button as appropriate. If generating a new key, be aware that existing keys might be invalidated, so update any applications using the old key.
  5. Copy Your API Key: Once revealed, carefully copy the entire API key. This key is a long alphanumeric string and is critical for authenticating your API requests.

It is crucial to treat your API key as a sensitive credential, similar to a password. Do not hardcode it directly into client-side code, commit it to public repositories, or share it unnecessarily. Best practices for securing API keys are discussed in the Security Best Practices section.

ElevenLabs provides a free tier for users to experiment with their services, which includes access to API key generation for initial development and testing, allowing developers to integrate and test before committing to a paid plan. The ElevenLabs pricing page provides details on character limits and features across different plans.

Authenticated request example

When making API requests to ElevenLabs, your API key must be included in the HTTP header. The specific header name is xi-api-key. Below are examples demonstrating how to include your API key in requests using common programming languages and tools.

Using cURL

This cURL example demonstrates a basic request to the Text-to-Speech endpoint, authenticating with an API key:

curl -X POST \
  'https://api.elevenlabs.io/v1/text-to-speech/{voice_id}' \
  --header 'Content-Type: application/json' \
  --header 'xi-api-key: YOUR_ELEVENLABS_API_KEY' \
  --data-raw '{
    "text": "Hello, this is an authenticated request to ElevenLabs.",
    "model_id": "eleven_monolingual_v1",
    "voice_settings": {
      "stability": 0.75,
      "similarity_boost": 0.75
    }
  }'

Replace YOUR_ELEVENLABS_API_KEY with your actual API key and {voice_id} with the ID of the desired voice.

Using Python SDK

ElevenLabs provides a Python SDK that simplifies API interactions, including authentication. You can set the API key as an environment variable or pass it directly. Setting it as an environment variable (ELEVENLABS_API_KEY) is generally recommended for security.

import os
from elevenlabs import generate, play

# Set your API key as an environment variable or replace 'os.getenv' directly
elevenlabs_api_key = os.getenv("ELEVENLABS_API_KEY")

if not elevenlabs_api_key:
    raise ValueError("ELEVENLABS_API_KEY environment variable not set.")

# Example using the generate function
audio = generate(
    text="This is a test message generated with the ElevenLabs Python SDK.",
    voice="Rachel", # Or a specific voice_id
    api_key=elevenlabs_api_key
)

play(audio)

Ensure you have installed the ElevenLabs Python SDK: pip install elevenlabs. For more Python examples, consult the ElevenLabs Python SDK documentation.

Using Node.js SDK

The Node.js SDK also streamlines API interactions. Similar to Python, it's best to manage your API key via environment variables.

const { ElevenLabsClient } = require("@elevenlabs/api");

const elevenlabs = new ElevenLabsClient({
  apiKey: process.env.ELEVENLABS_API_KEY, // Defaults to ELEVENLABS_API_KEY
});

async function main() {
  const audio = await elevenlabs.textToSpeech.convert(
    "21m00Tcm4TlvDq8ikWAM", // Voice ID for Rachel
    {
      text: "Hello from the ElevenLabs Node.js SDK, authenticated and ready.",
    }
  );

  // Handle the audio stream, e.g., save to file or play
  const p = require("node:fs/promises");
  await p.writeFile("output.mp3", Buffer.from(await audio.arrayBuffer()));
  console.log("Audio saved to output.mp3");
}

main();

Install the Node.js SDK: npm install @elevenlabs/api. More Node.js examples are available in the ElevenLabs Node.js SDK documentation.

Security best practices

Securing your ElevenLabs API keys is paramount to prevent unauthorized access to your account and services. Adhering to these best practices minimizes risks:

  • Never Expose API Keys in Client-Side Code: API keys embedded directly in client-side code (e.g., frontend JavaScript, mobile app binaries) can be easily extracted by malicious actors. Always route API requests through a secure backend server that holds your API key.

  • Use Environment Variables: Store API keys as environment variables on your server or in your deployment configuration (e.g., Docker secrets, Kubernetes secrets, cloud provider secret managers). This keeps them out of your codebase and version control systems.

    export ELEVENLABS_API_KEY="your_secret_key_here"
  • Do Not Commit API Keys to Version Control: Never include API keys directly in source code repositories, even private ones. Use .gitignore files to exclude configuration files that contain API keys.

  • Implement Server-Side Validation and Rate Limiting: While ElevenLabs handles its own rate limiting, implementing additional server-side validation and rate limiting on your application's calls to ElevenLabs can help mitigate abuse if your key is compromised. This adds a layer of defense against excessive usage.

  • Restrict Access to API Keys: Limit who has access to your API keys within your organization. Only individuals who require access for development or deployment should be granted it. This principle of least privilege helps contain potential breaches.

  • Use HTTPS/TLS: All communication with the ElevenLabs API is secured via HTTPS. Ensure your application always uses HTTPS to prevent eavesdropping during the transmission of your API key and other data. This is a fundamental principle of secure web communication, as highlighted by resources like Mozilla's explanation of TLS.

  • Rotate API Keys Regularly: Periodically generate new API keys and replace the old ones in your applications. This practice, known as key rotation, reduces the window of opportunity for a compromised key to be exploited. ElevenLabs typically allows you to generate new keys from your account settings.

  • Monitor Usage: Regularly monitor your ElevenLabs account usage for any unusual activity. Spikes in API calls or unexpected resource consumption could indicate a compromised key. Set up alerts if available.

  • Secure Your Development Environment: Ensure that your local development environment and any CI/CD pipelines are secure. Malicious software or improper configurations can expose API keys during development or deployment stages.

By diligently following these security practices, developers can significantly enhance the protection of their ElevenLabs integrations and safeguard their account resources.