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

# Audio

> POST /v1/audio/speech for text to speech and music, POST /v1/audio/transcriptions for speech to text.

Both endpoints take the OpenAI-compatible speech and transcription request bodies and return the matching responses. Speech and transcription models appear in the main [catalog](/ai-gateway/api/models); pick an id whose row lists the audio modality.

## Text to speech

`POST /v1/audio/speech` takes the standard speech body and returns audio bytes. Speech models are `openai/gpt-audio-mini` (fast) and `openai/gpt-audio` (higher quality); voices are `alloy`, `ash`, `ballad`, `coral`, `echo`, `sage`, `shimmer` and `verse`. The response is `audio/wav` (24 kHz mono); pass `response_format: "pcm16"` for the raw samples. `instructions` sets the delivery (default: read the text verbatim, warmly).

<CodeGroup>
  ```bash curl theme={null}
  curl --fail-with-body https://api.pre.dev/v1/audio/speech \
    -H "Authorization: Bearer $PREDEV_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{"model": "openai/gpt-audio-mini", "input": "Your build is ready.", "voice": "alloy"}' \
    -o ready.wav
  ```

  ```typescript Node.js theme={null}
  import fs from 'node:fs/promises';
  import OpenAI from 'openai';

  const client = new OpenAI({ baseURL: 'https://api.pre.dev/v1', apiKey: process.env.PREDEV_API_KEY! });

  const speech = await client.audio.speech.create({
    model: 'openai/gpt-audio-mini',
    input: 'Your build is ready.',
    voice: 'alloy',
  });
  await fs.writeFile('ready.wav', Buffer.from(await speech.arrayBuffer()));
  ```

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

  client = OpenAI(base_url="https://api.pre.dev/v1", api_key=os.environ["PREDEV_API_KEY"])

  with client.audio.speech.with_streaming_response.create(
      model="openai/gpt-audio-mini",
      input="Your build is ready.",
      voice="alloy",
  ) as speech:
      speech.stream_to_file("ready.wav")
  ```
</CodeGroup>

In a web app, serve the bytes from your own route and point an `<audio>` element at it; the `Content-Type` header names the format. A model id that does not produce audio returns `400` with the list of ids that do.

## Music

The same endpoint composes music: send `model: "google/lyria-3-clip-preview"` (or `google/lyria-3-pro-preview`) with `input` set to the mood or style you want, for example `"upbeat lo-fi for a launch video"`. Music models answer with an MP3 (`audio/mpeg`); `voice` is ignored. The header `x-predev-audio-format` carries the format on every speech response.

## Transcription

`POST /v1/audio/transcriptions` is `multipart/form-data` with a `file` part and a `model` field.

<CodeGroup>
  ```bash curl theme={null}
  curl --fail-with-body https://api.pre.dev/v1/audio/transcriptions \
    -H "Authorization: Bearer $PREDEV_API_KEY" \
    -F "model=$TRANSCRIBE_MODEL" \
    -F "file=@meeting.m4a"
  ```

  ```typescript Node.js theme={null}
  import fs from 'node:fs';
  import OpenAI from 'openai';

  const client = new OpenAI({ baseURL: 'https://api.pre.dev/v1', apiKey: process.env.PREDEV_API_KEY! });

  const transcript = await client.audio.transcriptions.create({
    model: process.env.TRANSCRIBE_MODEL!,
    file: fs.createReadStream('meeting.m4a'),
  });
  console.log(transcript.text);
  ```

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

  client = OpenAI(base_url="https://api.pre.dev/v1", api_key=os.environ["PREDEV_API_KEY"])

  with open("meeting.m4a", "rb") as audio:
      transcript = client.audio.transcriptions.create(model=os.environ["TRANSCRIBE_MODEL"], file=audio)
  print(transcript.text)
  ```
</CodeGroup>

Set `TRANSCRIBE_MODEL` to a transcription id from the catalog (`openai/whisper-large-v3` today). All three calls return the usual `x-predev-*` headers and are billed from `usage.cost`.
