# Cartesia (/en/ai/models/tts/cartesia)

> For AI agents: see the complete documentation index at [llms.txt](/llms.txt).

Cartesia provides ultra-fast, low-latency text-to-speech with real-time streaming capabilities, optimized for interactive conversational AI applications.

<CalloutContainer type="info">
  <CalloutTitle>
    Info
  </CalloutTitle>

  <CalloutDescription>
    This integration is fully supported for use with Conversational AI Engine. While it has completed functional validation, it is newer to the platform, and additional provider-specific edge cases may be identified as usage scales across a broader range of applications and workloads.
  </CalloutDescription>
</CalloutContainer>

### Sample configuration [#sample-configuration]

The following examples show how to configure Cartesia TTS when starting a conversational AI agent.

<Tabs defaultValue="python" groupId="ai-sdk-language">
  <TabsList>
    <TabsTrigger value="python">
      Python SDK
    </TabsTrigger>

    <TabsTrigger value="typescript">
      TypeScript SDK
    </TabsTrigger>

    <TabsTrigger value="go">
      Go SDK
    </TabsTrigger>

    <TabsTrigger value="rest-api">
      REST API
    </TabsTrigger>
  </TabsList>

  <TabsContent value="python">
    ```python
    from agora_agent import Agent
    from agora_agent.agentkit.vendors import CartesiaTTS

    # client is your configured Agora client
    agent = (
        Agent(client)
        .with_stt(...)  # configure your STT vendor
        .with_llm(...)  # configure your LLM vendor
        .with_tts(CartesiaTTS(
            api_key='your-cartesia-key',
            model_id='sonic-2',
            voice_id='<voice_id>',
        ))
    )
    ```
  </TabsContent>

  <TabsContent value="typescript">
    ```typescript
    import { Agent, CartesiaTTS } from 'agora-agents';

    // client is your configured Agora client
    const agent = new Agent({ client })
      .withStt(/* configure your STT vendor */)
      .withLlm(/* configure your LLM vendor */)
      .withTts(new CartesiaTTS({
        apiKey: 'your-cartesia-key',
        modelId: 'sonic-2',
        voiceId: '<voice_id>',
      }));
    ```
  </TabsContent>

  <TabsContent value="go">
    ```go
    import "github.com/AgoraIO/agora-agents-go/v2/agentkit/vendors"

    // client is your configured Agora client
    agent := agentkit.NewAgent(client).WithStt(/* configure your STT vendor */).
      WithLlm(/* configure your LLM vendor */).
      WithTts(
        vendors.NewCartesiaTTS(vendors.CartesiaTTSOptions{
            APIKey:  "your-cartesia-key",
            ModelID: "sonic-2",
            VoiceID: "<voice_id>",
        }),
    )
    ```
  </TabsContent>

  <TabsContent value="rest-api">
    Use the following `tts` configuration in your request:

    ```json
    "tts": {
      "vendor": "cartesia",
      "params": {
        "api_key": "<your_cartesia_key>",
        "model_id": "sonic-2",
        "base_url": "wss://api.cartesia.ai",
        "voice": {
            "mode": "id",
            "id": "<voice_id>"
        },
        "output_format": {
            "container": "raw",
            "sample_rate": 16000
        },
        "language": "en"
      }
    }
    ```
  </TabsContent>
</Tabs>

<CalloutContainer type="warning">
  <CalloutTitle>
    Caution
  </CalloutTitle>

  <CalloutDescription>
    The parameters listed on this page are validated for use with Conversational AI Engine. Required parameters must be provided as documented. Any additional parameters are passed through directly to the underlying vendor without validation. For a full list of supported options, refer to the [Cartesia TTS documentation](https://docs.cartesia.ai/).
  </CalloutDescription>
</CalloutContainer>

### Key parameters [#key-parameters]

<ParameterList title="params" required="true">
  <Parameter name="api_key" type="string" required="true">
    The Cartesia API key used to authenticate requests. Get your API key from the [Cartesia Console](https://play.cartesia.ai/sign-up).
  </Parameter>

  <Parameter name="model_id" type="string" required="true">
    The identifier of the TTS model to use. For example, `sonic-2`.
  </Parameter>

  <Parameter name="base_url" type="string" required="false">
    The WebSocket URL for the Cartesia streaming API. For example, `wss://api.cartesia.ai`.
  </Parameter>

  <Parameter name="voice" type="object" required="true">
    Voice configuration object.

    <Parameter name="mode" type="string" required="true">
      Voice selection mode. Use `id` to select by voice identifier.
    </Parameter>

    <Parameter name="id" type="string" required="true">
      The identifier of the selected voice for speech synthesis.
    </Parameter>
  </Parameter>

  <Parameter name="output_format" type="object" required="false">
    Audio output format configuration

    <Parameter name="container" type="string" required="false">
      Audio container format for the output stream.
    </Parameter>

    <Parameter name="sample_rate" type="number" defaultValue="16000" possibleValues="8000, 16000, 22050, 24000, 44100, 48000" required="false">
      Audio sampling rate in Hz
    </Parameter>
  </Parameter>

  <Parameter name="language" type="string" required="false">
    Target language for speech synthesis.
  </Parameter>
</ParameterList>
