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

# OpenAI

> Use the OpenAI text-to-speech plugin in a Zero Runtime pipeline. Setup, options, and usage.

OpenAI is a **text-to-speech** plugin. It synthesizes the LLM's reply into the agent's voice
using OpenAI's TTS models. It occupies the pipeline's `tts` slot.

## Setup

Set your OpenAI API key in the worker environment. Generate a key from the [OpenAI dashboard](https://platform.openai.com/api-keys):

```bash theme={null}
export OPENAI_API_KEY=<key>
```

## Usage

Import the plugin and pass it to the pipeline's `tts` slot.

<CodeGroup>
  ```python Python theme={null}
  from zeroruntime.plugins import OpenAITTS

  tts = OpenAITTS(
      model="gpt-4o-mini-tts",
      voice="ash",
  )

  # Pipeline(tts=tts, ...)
  ```

  ```typescript Node JS theme={null}
  import { OpenAITTS } from '@zeroruntime/js-sdk/plugins';

  const tts = OpenAITTS({
    model: 'gpt-4o-mini-tts',
    voice: 'ash',
  });

  // Pipeline({ tts, ... })
  ```
</CodeGroup>

## Speed control

Use `speed` to adjust the speaking rate. The value is a multiplier in the range
`0.25` - `4.0`; leaving it unset uses the provider default of `1.0`:

<CodeGroup>
  ```python Python theme={null}
  from zeroruntime.plugins import OpenAITTS

  tts = OpenAITTS(
      model="gpt-4o-mini-tts",
      voice="marin",
      speed=1.1,
  )
  ```

  ```typescript Node JS theme={null}
  import { OpenAITTS } from '@zeroruntime/js-sdk/plugins';

  const tts = OpenAITTS({
    model: 'gpt-4o-mini-tts',
    voice: 'marin',
    speed: 1.1,
  });
  ```
</CodeGroup>

## Parameters

*Constructor parameters for `OpenAITTS`. The Python and Node JS SDKs share these field names.*

| Parameter     | Type    | Default             | Description                                                                                                         |
| ------------- | ------- | ------------------- | ------------------------------------------------------------------------------------------------------------------- |
| `api_key`     | `str`   | `None`              | OpenAI API key. Falls back to the `OPENAI_API_KEY` environment variable when unset.                                 |
| `voice`       | `str`   | `"ash"`             | Built-in voice name (e.g. `"marin"`, `"cedar"`, `"ash"`, `"coral"`).                                                |
| `model`       | `str`   | `"gpt-4o-mini-tts"` | TTS model: `"gpt-4o-mini-tts"` (newest, most capable), `"tts-1"` (lower latency), or `"tts-1-hd"` (higher quality). |
| `sample_rate` | `int`   | `24000`             | Output audio sample rate in Hz.                                                                                     |
| `speed`       | `float` | `None`              | Speaking speed multiplier (0.25 - 4.0). `None` uses the provider default of 1.0.                                    |
| `stream`      | `bool`  | `True`              | When `True`, audio is returned as a streaming response; `False` requests the full audio before playback.            |

## Import paths

| SDK     | Import                                                    | Constructor          |
| ------- | --------------------------------------------------------- | -------------------- |
| Python  | `from zeroruntime.plugins import OpenAITTS`               | `OpenAITTS(...)`     |
| Node JS | `import { OpenAITTS } from '@zeroruntime/js-sdk/plugins'` | `OpenAITTS({ ... })` |

The synthesized audio is streamed back to the caller as the final stage of the
[pipeline](/concepts/pipeline).
