Capabilities
Audio
Synthesize speech and transcribe audio through OpenAI-compatible endpoints.
On this page
This page is for developers building speech synthesis or transcription into a server application.
Text to speech#
POST /v1/audio/speech accepts JSON and returns binary audio. voice is required and model-specific; there is no generic default voice. An invalid voice returns 400 and may include the model's supported voice list. Formats, speed ranges, and other limits also depend on the selected model. This endpoint does not define a gateway-specific SSE audio stream.
curl https://api.clssai.com/v1/audio/speech \
-H "Authorization: Bearer $CLSSAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"deepgram/flux-tts:free","input":"Welcome to CLSSAI.","voice":"flux-alexis-en","response_format":"mp3"}' \
--output speech.mp3import os
from openai import OpenAI
client = OpenAI(base_url="https://api.clssai.com/v1", api_key=os.environ["CLSSAI_API_KEY"])
with client.audio.speech.with_streaming_response.create(
model="deepgram/flux-tts:free",
input="Welcome to CLSSAI.",
voice="flux-alexis-en",
response_format="mp3",
) as response:
response.stream_to_file("speech.mp3")import { writeFile } from "node:fs/promises";
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.clssai.com/v1",
apiKey: process.env.CLSSAI_API_KEY,
});
const response = await client.audio.speech.create({
model: "deepgram/flux-tts:free",
input: "Welcome to CLSSAI.",
voice: "flux-alexis-en",
response_format: "mp3",
});
await writeFile("speech.mp3", Buffer.from(await response.arrayBuffer()));When a binary response has no usage, the billing log estimates work from request text and marks the cost breakdown as estimated.
Speech to text#
The documented JSON path sends raw base64 audio and its format. The returned transcription schema is defined by the upstream API.
AUDIO_BASE64="$(base64 < sample.wav | tr -d '\n')"
curl https://api.clssai.com/v1/audio/transcriptions \
-H "Authorization: Bearer $CLSSAI_API_KEY" \
-H "Content-Type: application/json" \
-d "{\"model\":\"openai/gpt-4o-mini-transcribe\",\"input_audio\":{\"data\":\"$AUDIO_BASE64\",\"format\":\"wav\"},\"language\":\"en\"}"import base64
import os
import requests
with open("sample.wav", "rb") as audio:
encoded = base64.b64encode(audio.read()).decode("ascii")
response = requests.post(
"https://api.clssai.com/v1/audio/transcriptions",
headers={"Authorization": f"Bearer {os.environ['CLSSAI_API_KEY']}", "Content-Type": "application/json"},
json={"model": "openai/gpt-4o-mini-transcribe", "input_audio": {"data": encoded, "format": "wav"}, "language": "en"},
timeout=120,
)
response.raise_for_status()
print(response.json())import { readFile } from "node:fs/promises";
const audio = await readFile("sample.wav");
const response = await fetch("https://api.clssai.com/v1/audio/transcriptions", {
method: "POST",
headers: { Authorization: `Bearer ${process.env.CLSSAI_API_KEY}`, "Content-Type": "application/json" },
body: JSON.stringify({ model: "openai/gpt-4o-mini-transcribe", input_audio: { data: audio.toString("base64"), format: "wav" }, language: "en" }),
});
if (!response.ok) throw new Error(await response.text());
console.log(await response.json());The gateway does not publish a universal duration or file-size limit for TTS or JSON transcription. Respect upstream errors and bound uploads in your own server.
Common mistakes#
- Do not treat a binary TTS response as JSON.
- Always pass a voice supported by the selected TTS model; there is no generic default voice.
- Do not assume every format works with every model.
- Include
/v1in OpenAI SDK base URLs and omit it from the Anthropic SDK base URL. - Keep audio and keys on the server; a browser call exposes the key to every visitor.
- Preserve complete
:freeand:batchIDs, check empty streamingchoices, and recordcf-ray.
Also available (pass-through, lightly tested)#
Multipart transcription is passed through unchanged. Its cost comes from upstream usage.cost, while the gateway log row records the model as unknown. Prefer the JSON base64 form above when you need consistent per-model accounting metadata.
curl https://api.clssai.com/v1/audio/transcriptions \
-H "Authorization: Bearer $CLSSAI_API_KEY" \
-F "model=openai/gpt-4o-mini-transcribe" \
-F "file=@sample.wav"Find answers to common questions or diagnose a failed request.
Frequently asked questions →Troubleshoot errors →