# OpenAI (/en/ai/models/tts/openai)

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

> Documentation: Conversational AI.
> Documentation version: Main.
> This document describes only this version. [Version index](/llms/doc-versions-convoai-guides-v1.txt).


OpenAI provides natural-sounding text-to-speech with customizable voice instructions and multiple voice options.

### Sample configuration

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

**Python SDK**

```python
from agora_agent import Agent
from agora_agent.agentkit.vendors import OpenAITTS

# client is your configured Agora client
agent = (
    Agent(client)
    .with_stt(...)  # configure your STT vendor
    .with_llm(...)  # configure your LLM vendor
    .with_tts(OpenAITTS(
        api_key='your-openai-key',  # to use Agora-managed mode, omit api_key and base_url and set model to 'tts-1'
        base_url='https://api.openai.com/v1',
        model='gpt-4o-mini-tts',
        voice='coral',
        instructions='Please use standard American English, natural tone, moderate pace, and steady intonation',
        speed=1,
    ))
)
```

**TypeScript SDK**

```typescript
import { Agent, OpenAITTS } 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 OpenAITTS({
    apiKey: 'your-openai-key',  // to use Agora-managed mode, omit apiKey and baseUrl and set model to 'tts-1'
    baseUrl: 'https://api.openai.com/v1',
    model: 'gpt-4o-mini-tts',
    voice: 'coral',
    instructions: 'Please use standard American English, natural tone, moderate pace, and steady intonation',
    speed: 1,
  }));
```

**Go SDK**

```go
import (
    Agora "github.com/AgoraIO/agora-agents-go/v2"
    "github.com/AgoraIO/agora-agents-go/v2/agentkit"
    "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.NewOpenAITTS(vendors.OpenAITTSOptions{
        APIKey:       "your-openai-key", // to use Agora-managed mode, omit APIKey and BaseURL and set Model to "tts-1"
        BaseURL:      "https://api.openai.com/v1",
        Model:        "gpt-4o-mini-tts",
        Voice:        "coral",
        Instructions: "Please use standard American English, natural tone, moderate pace, and steady intonation",
        Speed:        Agora.Float64(1),
    }),
)
```

**REST API**

- **Managed mode**

  To use OpenAI TTS with Agora-managed credentials, set `credential_mode` to `"managed"` in the `tts` block. When using managed mode, `params.api_key` is not required. You can still use the `tts` field to configure additional settings such as `voice` and `instructions`. For more information, see [Use managed mode](/en/ai/build/managed-mode).

  ```json
  "tts": {
    "credential_mode": "managed",
    "vendor": "openai",
    "params": {
      "url": "https://api.openai.com/v1/audio/speech",
      "model": "tts-1",
      "voice": "coral",
      "instructions": "Please use standard American English, natural tone, moderate pace, and steady intonation",
      "speed": 1
    }
  }
  ```


- **BYOK**

  ```json
  "tts": {
    "vendor": "openai",
    "params": {
      "url": "https://api.openai.com/v1/audio/speech",
      "api_key": "<your_openai_key>",
      "model": "gpt-4o-mini-tts",
      "voice": "coral",
      "instructions": "Please use standard American English, natural tone, moderate pace, and steady intonation",
      "speed": 1
    }
  }
  ```

### Key parameters

The following parameters are required when using your own API key (BYOK). When using managed mode, `api_key` is not required. For more information, see [Use managed mode](/en/ai/build/managed-mode).

**params**

**`url` (string) required**

The full endpoint URL for the OpenAI speech API, for example `https://api.openai.com/v1/audio/speech`. See [How to use data residency](https://platform.openai.com/docs/guides/your-data#how-to-use-data-residency).

**`api_key` (string) optional**

The API key used for authentication. Required when using your own API key (BYOK). Get your API key from the [OpenAI Console](https://platform.openai.com/api-keys).

**`model` (string) required**

Identifier of the model to be used. For managed mode, use `tts-1`.

**`voice` (string) required**

The voice identifier for speech synthesis.

**`instructions` (string) optional**

Custom instructions for voice style, accent, pace, and tone. Helps fine-tune the speech characteristics.

**`speed` (number) optional**

Default value: `1.0`

Speaking rate multiplier. Values between `0.25` and `4.0`, where `1.0` is normal speed.

> **Info**
>
> OpenAI TTS models do not support changing the sample rate. The audio output is fixed at 24,000 Hz.

> **Caution**
>
> 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 [OpenAI TTS documentation](https://platform.openai.com/docs/guides/text-to-speech).

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.
