> ## Documentation Index
> Fetch the complete documentation index at: https://inference-docs.cerebras.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Get Started with ElevenLabs

> Learn how to integrate Cerebras Inference with ElevenLabs for ultra-fast text-to-speech generation and voice AI applications.

ElevenLabs is a leading voice AI platform that provides realistic text-to-speech, voice cloning, and dubbing capabilities. By combining Cerebras Inference's lightning-fast LLM responses with ElevenLabs' natural-sounding voice synthesis, you can build responsive voice agents and conversational AI applications.

This guide will walk you through integrating Cerebras models with ElevenLabs to create a complete voice AI pipeline.

## Prerequisites

Before you begin, ensure you have:

* **Cerebras API Key** - Get a free API key [here](https://cloud.cerebras.ai/?utm_source=3pi_elevenlabs\&utm_campaign=integrations).
* **ElevenLabs API Key** - Visit [ElevenLabs](https://elevenlabs.io/?utm_source=cerebras\&utm_campaign=elevenlabs) and create an account. Navigate to your profile settings to generate an API key.
* **Python 3.10 or higher** - Required for running the integration code.

## Configure ElevenLabs Integration

<Steps>
  <Step title="Install required dependencies">
    Install the necessary Python packages for both Cerebras Inference and ElevenLabs:

    ```bash theme={null}
    pip install openai elevenlabs
    ```

    The `openai` package provides the client for Cerebras Inference (OpenAI-compatible), and `elevenlabs` is the official ElevenLabs SDK for voice synthesis.

    <Note>
      **Audio playback requirement:** To play audio files, you may need to install FFmpeg:

      * **macOS**: `brew install ffmpeg`
      * **Windows**: Download from [ffmpeg.org](https://ffmpeg.org/download.html?utm_source=cerebras\&utm_campaign=elevenlabs) or use `choco install ffmpeg`
      * **Linux**: `sudo apt install ffmpeg` (Ubuntu/Debian) or `sudo yum install ffmpeg` (CentOS/RHEL)
    </Note>
  </Step>

  <Step title="Configure environment variables">
    Create a `.env` file in your project directory to securely store your API keys:

    ```bash theme={null}
    CEREBRAS_API_KEY=your-cerebras-api-key-here
    ELEVENLABS_API_KEY=your-elevenlabs-api-key-here
    ```

    Alternatively, you can set these as environment variables in your shell:

    ```bash theme={null}
    export CEREBRAS_API_KEY="your-cerebras-api-key-here"
    export ELEVENLABS_API_KEY="your-elevenlabs-api-key-here"
    ```
  </Step>

  <Step title="Initialize the Cerebras client">
    Set up the Cerebras client using the OpenAI-compatible interface. The integration header helps us track and optimize this integration:

    <CodeGroup>
      ```python Python theme={null}
      import os
      from openai import OpenAI

      client = OpenAI(
          api_key=os.getenv("CEREBRAS_API_KEY"),
          base_url="https://api.cerebras.ai/v1",
          default_headers={"X-Cerebras-3rd-Party-Integration": "elevenlabs"}
      )
      ```
    </CodeGroup>
  </Step>

  <Step title="Create a basic text-to-speech pipeline">
    Now let's create a complete pipeline that generates text with Cerebras and converts it to speech with ElevenLabs. This example demonstrates the power of combining Cerebras's fast inference with ElevenLabs's natural voice synthesis:

    <CodeGroup>
      ```python Python theme={null}
      import os
      from openai import OpenAI
      from elevenlabs.client import ElevenLabs
      from elevenlabs.play import play

      # Initialize Cerebras client
      cerebras_client = OpenAI(
          api_key=os.getenv("CEREBRAS_API_KEY"),
          base_url="https://api.cerebras.ai/v1",
          default_headers={"X-Cerebras-3rd-Party-Integration": "elevenlabs"}
      )

      # Initialize ElevenLabs client
      elevenlabs_client = ElevenLabs(
          api_key=os.getenv("ELEVENLABS_API_KEY")
      )

      def generate_and_speak(prompt, voice_id="21m00Tcm4TlvDq8ikWAM"):
          """
          Generate text response using Cerebras and convert to speech with ElevenLabs.
          
          Args:
              prompt: User input text
              voice_id: ElevenLabs voice ID (default is Rachel)
          """
          # Generate text response with Cerebras
          response = cerebras_client.chat.completions.create(
              model="gpt-oss-120b",
              messages=[
                  {"role": "system", "content": "You are a helpful assistant. Keep responses concise and natural for voice output."},
                  {"role": "user", "content": prompt}
              ],
              max_completion_tokens=150,
              temperature=0.7,
              extra_headers={
                  "X-Cerebras-3rd-Party-Integration": "elevenlabs"
              }
          )
          
          text_response = response.choices[0].message.content
          print(f"Generated text: {text_response}")
          
          # Convert to speech with ElevenLabs
          audio = elevenlabs_client.text_to_speech.convert(
              text=text_response,
              voice_id=voice_id,
              model_id="eleven_multilingual_v2",
              output_format="mp3_44100_128"
          )
          
          # Play the audio
          play(audio)
          
          # And save to a file
          with open("output.mp3", "wb") as f:
              for chunk in audio:
                  f.write(chunk)
          
          return text_response

      # Example usage
      if __name__ == "__main__":
          generate_and_speak("Tell me an interesting fact about space exploration.")
      ```
    </CodeGroup>
  </Step>

  <Step title="Build a conversational voice agent">
    For a more advanced use case, here's how to build a multi-turn conversational agent that maintains context across multiple interactions:

    ```python theme={null}
    import os
    from openai import OpenAI
    from elevenlabs.client import ElevenLabs
    from elevenlabs.play import play

    # Initialize Cerebras client
    cerebras_client = OpenAI(
        api_key=os.getenv("CEREBRAS_API_KEY"),
        base_url="https://api.cerebras.ai/v1",
        default_headers={"X-Cerebras-3rd-Party-Integration": "elevenlabs"}
    )

    # Initialize ElevenLabs client
    elevenlabs_client = ElevenLabs(
        api_key=os.getenv("ELEVENLABS_API_KEY")
    )

    class VoiceAgent:
        def __init__(self, system_prompt, voice_id="21m00Tcm4TlvDq8ikWAM"):
            self.conversation_history = [
                {"role": "system", "content": system_prompt}
            ]
            self.voice_id = voice_id
        
        def chat(self, user_input):
            """Process user input and generate voice response."""
            # Add user message to history
            self.conversation_history.append({
                "role": "user",
                "content": user_input
            })
            
            # Generate response with Cerebras
            response = cerebras_client.chat.completions.create(
                model="gpt-oss-120b",
                messages=self.conversation_history,
                max_completion_tokens=200,
                temperature=0.8,
                extra_headers={
                    "X-Cerebras-3rd-Party-Integration": "elevenlabs"
                }
            )
            
            assistant_message = response.choices[0].message.content
            
            # Add assistant response to history
            self.conversation_history.append({
                "role": "assistant",
                "content": assistant_message
            })
            
            print(f"Assistant: {assistant_message}")
            
            # Convert to speech using updated ElevenLabs API method
            audio = elevenlabs_client.text_to_speech.convert(
                text=assistant_message,
                voice_id=self.voice_id,
                model_id="eleven_multilingual_v2",  # Use current supported free tier model
                output_format="mp3_44100_128"
            )
            
            # Play audio
            play(audio)
            
            return assistant_message

    # Example: Customer service agent
    agent = VoiceAgent(
        system_prompt="You are a friendly customer service representative. Be helpful, concise, and professional.",
        voice_id="21m00Tcm4TlvDq8ikWAM"  # Rachel voice
    )

    # Simulate conversation
    agent.chat("Hi, I need help with my order.")
    agent.chat("My order number is 12345.")
    agent.chat("When will it arrive?")
    ```

    This voice agent maintains conversation context and provides natural, spoken responses using Cerebras's fast inference and ElevenLabs's voice synthesis.
  </Step>

  <Step title="Stream responses for lower latency">
    For even faster response times, you can stream the Cerebras output and generate speech in chunks. Streaming provides the lowest possible latency by starting audio playback as soon as content is ready:

    ```python theme={null}
    import os
    from openai import OpenAI
    from elevenlabs.client import ElevenLabs
    from elevenlabs.play import play  # Use play for audio playback

    cerebras_client = OpenAI(
        api_key=os.getenv("CEREBRAS_API_KEY"),
        base_url="https://api.cerebras.ai/v1",
        default_headers={"X-Cerebras-3rd-Party-Integration": "elevenlabs"}
    )

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

    def streaming_voice_response(prompt):
        """Generate and speak response with streaming for minimal latency."""
        # Stream text from Cerebras
        response_stream = cerebras_client.chat.completions.create(
            model="gpt-oss-120b",
            messages=[
                {"role": "system", "content": "You are a helpful assistant."},
                {"role": "user", "content": prompt}
            ],
            stream=True,
            max_completion_tokens=200,
            extra_headers={
                "X-Cerebras-3rd-Party-Integration": "elevenlabs"
            }
        )
        
        full_response = ""
        for chunk in response_stream:
            if chunk.choices[0].delta.content:
                content = chunk.choices[0].delta.content
                full_response += content
                print(content, end="", flush=True)
        print()  # Newline after text stream
        
        # Generate audio from ElevenLabs
        audio = elevenlabs_client.text_to_speech.convert(
            text=full_response,
            voice_id="21m00Tcm4TlvDq8ikWAM",
            model_id="eleven_multilingual_v2",
            output_format="mp3_44100_128"
        )
        
        # Play audio
        play(audio)
        
        return full_response

    # Example usage
    streaming_voice_response("Explain quantum computing in simple terms.")
    ```
  </Step>
</Steps>

## Voice Selection

ElevenLabs offers a variety of pre-made voices. Here are some popular options:

* **Rachel** (21m00Tcm4TlvDq8ikWAM) - Calm, professional female voice
* **Adam** (pNInz6obpgDQGcFmaJgB) - Deep, authoritative male voice
* **Bella** (EXAVITQu4vr4xnSDxMaL) - Soft, friendly female voice
* **Antoni** (ErXwobaYiN019PkySvjV) - Well-rounded male voice

You can also create custom voices or clone voices using the ElevenLabs platform. Visit the [ElevenLabs Voice Library](https://elevenlabs.io/voice-library?utm_source=cerebras\&utm_campaign=elevenlabs) to explore more options.

## Use Cases

The Cerebras + ElevenLabs integration is perfect for:

* **Voice Assistants** - Build responsive AI assistants with natural conversation flow
* **Content Creation** - Generate and narrate articles, stories, or educational content
* **Customer Service** - Create automated voice support systems with human-like responses
* **Accessibility Tools** - Convert text content to speech for visually impaired users
* **Interactive Experiences** - Build voice-enabled games, tours, or educational apps
* **Podcast Generation** - Automatically create podcast episodes from text content

## FAQ

<Accordion title="Audio playback not working">
  If you're having trouble playing audio:

  1. Ensure you have audio output devices properly configured
  2. Try saving the audio to a file instead of playing directly:

  ```python theme={null}
  # Assuming you have audio from elevenlabs_client.text_to_speech.convert()
  # audio = elevenlabs_client.text_to_speech.convert(...)

  # Save to file instead of playing
  # with open("output.mp3", "wb") as f:
  #     for chunk in audio:
  #         f.write(chunk)
  ```

  3. Install additional audio libraries if needed: `pip install sounddevice soundfile`
</Accordion>

<Accordion title="High latency in responses">
  To reduce latency:

  1. Use streaming for both text generation and audio synthesis (see Step 6)
  2. Keep responses concise by setting lower `max_completion_tokens` values
  3. Use faster Cerebras models like `gpt-oss-120b` for simpler tasks
  4. Consider caching common responses
</Accordion>

## Available Models

Cerebras offers several models optimized for voice AI applications:

| Model            | Parameters | Best For                                                         |
| ---------------- | ---------- | ---------------------------------------------------------------- |
| **gpt-oss-120b** | 120B       | Largest model for the most demanding tasks                       |
| **zai-glm-4.7**  | 357B       | Advanced 357B parameter model with strong reasoning capabilities |

Simply change the `model` parameter in your Cerebras API calls to switch between models.

## Next Steps

* Explore the [ElevenLabs API documentation](https://elevenlabs.io/docs?utm_source=cerebras\&utm_campaign=elevenlabs) for advanced features like voice cloning and dubbing
* Try different Cerebras models like `gpt-oss-120b` for specialized tasks
* Experiment with [streaming responses](/capabilities/streaming) for even lower latency
* Learn about [structured outputs](/capabilities/structured-outputs) to format responses for voice synthesis
* Check out the [ElevenLabs Voice Library](https://elevenlabs.io/voice-library?utm_source=cerebras\&utm_campaign=elevenlabs) for more voice options
* **Migrate to GLM4.7**: Ready to upgrade? Follow our [migration guide](https://inference-docs.cerebras.ai/resources/glm-47-migration) to start using our latest model

## Additional Resources

* [ElevenLabs Python SDK Documentation](https://github.com/elevenlabs/elevenlabs-python?utm_source=cerebras\&utm_campaign=elevenlabs)
* [Cerebras Streaming Guide](/capabilities/streaming)
* [Voice AI Best Practices](https://elevenlabs.io/blog?utm_source=cerebras\&utm_campaign=elevenlabs)
* [ElevenLabs Community Discord](https://discord.gg/elevenlabs?utm_source=cerebras\&utm_campaign=elevenlabs)
