import os
from openai import OpenAI
client = OpenAI(base_url="https://api.naga.ac/v1", api_key=os.environ["NAGAAI_API_KEY"])
with client.audio.speech.with_streaming_response.create(
model="gpt-4o-mini-tts",
voice="alloy",
input="NagaAI serves models from many providers behind one API.",
) as response:
response.stream_to_file("speech.mp3")
import fs from "node:fs";
import OpenAI from "openai";
const client = new OpenAI({ baseURL: "https://api.naga.ac/v1", apiKey: process.env.NAGAAI_API_KEY });
const response = await client.audio.speech.create({
model: "gpt-4o-mini-tts",
voice: "alloy",
input: "NagaAI serves models from many providers behind one API.",
});
fs.writeFileSync("speech.mp3", Buffer.from(await response.arrayBuffer()));
curl https://api.naga.ac/v1/audio/speech \
-H "Authorization: Bearer $NAGAAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model": "gpt-4o-mini-tts", "voice": "alloy", "input": "NagaAI serves models from many providers behind one API."}' \
--output speech.mp3
| Field | Notes |
|---|---|
input | Up to 32,768 characters |
voice | Depends on the model. OpenAI voice names such as alloy and nova also work on ElevenLabs models, where NagaAI maps them to similar voices |
response_format | mp3 (default), opus, aac, flac, wav or pcm. A format the model cannot produce fails with 400: ElevenLabs models, for example, have no aac or flac |
speed | Greater than 0 |
instructions | Style directions, on models that support them |