Text to Speech
API Overview
API Specification
curl https://audio.onerouter.pro/v1/audio/speech \
-H "Content-Type: application/json" \
-H "Authorization: <API_KEY>" \
-d '{
"model": "gpt-4o-mini-tts",
"input": "A cute baby sea otter",
"voice": "alloy"
}' \
--output speech.mp3import os
import json
import requests
API_URL = "https://audio.onerouter.pro/v1/audio/speech"
API_KEY = os.getenv("ONEROUTER_API_KEY")
if not API_KEY:
raise RuntimeError("Please set the ONEROUTER_API_KEY")
payload = {
"model": "gpt-4o-mini-tts",
"input": "A cute baby sea otter.",
"voice": "alloy",
"response_format": "mp3"
}
headers = {
"Authorization": API_KEY,
"Content-Type": "application/json"
}
response = requests.post(API_URL, headers=headers, data=json.dumps(payload))
response.raise_for_status()
out_path = os.path.join(os.path.dirname(__file__), "tts-output.mp3")
with open(out_path, "wb") as f:
f.write(response.content)
print(f"Saved to: {out_path}")Last updated