Skip to main content
POST
/
v1
/
audio
/
speech
Text to speech (TTS)
curl --request POST \
  --url https://openp.ai/v1/audio/speech
import requests

url = "https://openp.ai/v1/audio/speech"

response = requests.post(url)

print(response.text)
const options = {method: 'POST'};

fetch('https://openp.ai/v1/audio/speech', options)
  .then(res => res.json())
  .then(res => console.log(res))
  .catch(err => console.error(err));
<?php

$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => "https://openp.ai/v1/audio/speech",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
package main

import (
	"fmt"
	"net/http"
	"io"
)

func main() {

	url := "https://openp.ai/v1/audio/speech"

	req, _ := http.NewRequest("POST", url, nil)

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(string(body))

}
HttpResponse<String> response = Unirest.post("https://openp.ai/v1/audio/speech")
  .asString();
require 'uri'
require 'net/http'

url = URI("https://openp.ai/v1/audio/speech")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)

response = http.request(request)
puts response.read_body
Synthesize text into natural-sounding speech.

Request

curl https://openp.ai/v1/audio/speech \
  -H "Authorization: Bearer $OPENPAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "tts-1",
    "input": "Hello from OpenPAI",
    "voice": "alloy",
    "response_format": "mp3"
  }' --output speech.mp3

Parameters

FieldTypeRequiredDescription
modelstringtts-1 / tts-1-hd / gpt-4o-mini-tts
inputstringThe text to synthesize (up to 4096 characters)
voicestringVoice: alloy / echo / fable / onyx / nova / shimmer / coral / verse, etc.
response_formatstringmp3 (default) / opus / aac / flac / wav / pcm
speednumber0.25 - 4.0 (default 1.0)
instructionsstringgpt-4o-mini-tts only; describe tone / style

Response

Returns a binary audio stream directly, with Content-Type matching the chosen response_format:
response_formatContent-Type
mp3audio/mpeg
opusaudio/ogg
aacaudio/aac
flacaudio/flac
wavaudio/wav
pcmaudio/pcm

Python example

from openai import OpenAI
client = OpenAI(api_key="sk-...", base_url="https://openp.ai/v1")

with client.audio.speech.with_streaming_response.create(
    model="tts-1-hd",
    voice="nova",
    input="OpenPAI makes integrating LLMs simpler.",
) as resp:
    resp.stream_to_file("output.mp3")

gpt-4o-mini-tts advanced

The next-gen TTS supports controlling tone via instructions:
{
  "model": "gpt-4o-mini-tts",
  "voice": "coral",
  "input": "Today's meeting results were excellent.",
  "instructions": "Read in an excited, upbeat tone, slightly faster."
}

Streaming playback

Synthesis may take ≥ 1 second; in a browser or client you can receive it as a stream:
with client.audio.speech.with_streaming_response.create(
    model="tts-1",
    voice="alloy",
    input="...",
    response_format="opus",
) as resp:
    for chunk in resp.iter_bytes():
        # play as you receive
        play(chunk)

Billing

Charged by input character count, regardless of the chosen model and format.