---
title: "Generate speech from text"
description: "Generate audio from text.\n\nDrop-in replacement for OpenAI /v1/audio/speech. Routes to Gemini when the\nmodel is a Gemini TTS variant (e.g. ``google/gemini-2.5-flash-tts``); any\nother model goes through the OpenAI proxy.\n\nAccepts tri-mode auth (user token / service+on-behalf-of / service-only) —\nthe service-key path is required for backend callers like BlinkLife that\nproxy TTS previews to TIE on a user's behalf."
---

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

Path: AI Gateway API › Chat

`POST /v1/audio/speech`

Generate audio from text.

Drop-in replacement for OpenAI /v1/audio/speech. Routes to Gemini when the
model is a Gemini TTS variant (e.g. ``google/gemini-2.5-flash-tts``); any
other model goes through the OpenAI proxy.

Accepts tri-mode auth (user token / service+on-behalf-of / service-only) —
the service-key path is required for backend callers like BlinkLife that
proxy TTS previews to TIE on a user's behalf.

## Authentication

- `HTTPBearer`, http, header `Authorization`

## Header parameters

- `X-On-Behalf-Of` (`create_speech.header.X-On-Behalf-Of`; any of, optional)
  - any of: `string`, `null`
- `X-External-User-Id` (`create_speech.header.X-External-User-Id`; any of, optional)
  - any of: `string`, `null`
- `X-App-Id` (`create_speech.header.X-App-Id`; any of, optional)
  - any of: `string`, `null`

## Request body

_Required._

- `input` (`create_speech.input`; string, required) — Text to convert to speech
  - minLength 1; maxLength 4000
- `model` (`create_speech.model`; string, optional) — TTS model to use
  - minLength 1; maxLength 100; default `"gpt-4o-mini-tts"`
- `voice` (`create_speech.voice`; string, optional) — Voice to use
  - minLength 1; maxLength 100; default `"alloy"`
- `response_format` (`create_speech.response_format`; string, optional)
  - one of `"mp3"`, `"opus"`, `"aac"`, `"flac"`, `"wav"`, `"pcm"`; default `"mp3"`
- `speed` (`create_speech.speed`; number, optional)
  - min 0.25; max 4; default `1`
- `language` (`create_speech.language`; any of, optional) — Language code (Gemini only, e.g. 'en', 'ms', 'en-US')
  - any of: `string`, `null`

## Example request

```json
{
  "model": "gpt-4o-mini-tts",
  "input": "string",
  "voice": "alloy",
  "response_format": "mp3",
  "speed": 1,
  "language": "string"
}
```

## Code samples

### cURL

```bash
curl --request POST \
  --url https://truememory-api.mvstg.com/v1/audio/speech \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "model": "gpt-4o-mini-tts",
  "input": "string",
  "voice": "alloy",
  "response_format": "mp3",
  "speed": 1,
  "language": "string"
}
'
```

### TypeScript

```typescript
const url = 'https://truememory-api.mvstg.com/v1/audio/speech';
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json', Authorization: 'Bearer <token>'},
  body: JSON.stringify({
    model: 'gpt-4o-mini-tts',
    input: 'string',
    voice: 'alloy',
    response_format: 'mp3',
    speed: 1,
    language: 'string'
  })
};

fetch(url, options)
  .then(res => res.json())
  .then(json => console.log(json))
  .catch(err => console.error(err));
```

### Python

```python
import requests

url = "https://truememory-api.mvstg.com/v1/audio/speech"

payload = {
    "model": "gpt-4o-mini-tts",
    "input": "string",
    "voice": "alloy",
    "response_format": "mp3",
    "speed": 1,
    "language": "string"
}
headers = {
    "Content-Type": "application/json",
    "Authorization": "Bearer <token>"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
```

## Responses

### 200

The generated audio as raw bytes — this response is a binary audio stream, not JSON. The `Content-Type` reflects the format the provider returned.

### 422

Validation Error

#### Example

```json
{
  "detail": [
    {
      "loc": [
        "string"
      ],
      "msg": "string",
      "type": "string",
      "input": null,
      "ctx": {}
    }
  ]
}
```

- `detail` (`create_speech.response.422.detail`; array<object>, optional)
  - `loc` (`create_speech.response.422.detail.loc`; array<any of>, required)
    - any of: `string`, `integer`
  - `msg` (`create_speech.response.422.detail.msg`; string, required)
  - `type` (`create_speech.response.422.detail.type`; string, required)
  - `input` (`create_speech.response.422.detail.input`; unknown, optional)
  - `ctx` (`create_speech.response.422.detail.ctx`; object, optional)


Source: https://truememory-docs.mvstg.com/api/audio/speech/index.md
