Voice API

Text-to-speech, voice cloning, and emotion control. 17 models, 168 voices. From $0.001/clip.

POST /v1/generations/voice

Generate speech from text. Returns synchronously for short text, async for long-form.

Request body

FieldTypeRequiredDescription
modelstringYesModel key (e.g. "cosyvoice2", "elevenlabs-v2", "kokoro-v1").
promptstringYesText to speak.
voicestringNoVoice preset name (e.g. "alloy", "nova"). See GET /v1/voices.
speednumberNoSpeaking speed. 0.5 to 2.0. Default: 1.0.
ref_audio_urlstring (URL)NoReference audio URL for voice cloning.
emotionstringNoEmotion control: "neutral", "happy", "sad", "excited". Model-dependent.
confirmbooleanNoSet to false for cost estimate only. Default: true.

Response fields

FieldTypeDescription
idstringGeneration ID.
statusstring"completed" or "failed".
urlstringCDN URL of the generated audio (MP3).
cost.microintegerCost in microdollars.
cost.displaystringHuman-readable cost.
metadata.durationnumberAudio duration in seconds.
metadata.sample_rateintegerAudio sample rate in Hz.
metadata.voicestringVoice preset used.

Code examples

curl

curl -X POST https://api.fairstack.ai/v1/generations/voice \
  -H "Authorization: Bearer $FAIRSTACK_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "cosyvoice2",
    "prompt": "Welcome to FairStack. The best AI models, at fair prices.",
    "voice": "alloy"
  }'

Python

from fairstack import FairStack

client = FairStack(api_key="fs_live_YOUR_KEY")

result = client.generate.voice(
    model="cosyvoice2",
    prompt="Welcome to FairStack. The best AI models, at fair prices.",
    voice="alloy"
)
print(result.url)   # https://media.fairstack.ai/voice/...
print(result.cost)  # $0.001

Node.js

import { FairStack } from "fairstack";

const client = new FairStack({ apiKey: "fs_live_YOUR_KEY" });

const result = await client.generate.voice({
  model: "cosyvoice2",
  prompt: "Welcome to FairStack. The best AI models, at fair prices.",
  voice: "alloy",
});
console.log(result.url);   // https://media.fairstack.ai/voice/...
console.log(result.cost);  // { micro: 1000, display: "$0.001" }

Response

{
  "id": "gen_voice_abc",
  "status": "completed",
  "url": "https://media.fairstack.ai/voice/.../output.mp3",
  "model": "cosyvoice2",
  "modality": "voice",
  "cost": {
    "micro": 1000,
    "display": "$0.001",
    "currency": "USD"
  },
  "metadata": {
    "duration": 3.2,
    "sample_rate": 44100,
    "voice": "alloy"
  }
}

Cost estimation

Set confirm: false to get the exact cost without generating audio.

curl -X POST https://api.fairstack.ai/v1/generations/voice \
  -H "Authorization: Bearer $FAIRSTACK_API_KEY" \
  -d '{ "model": "cosyvoice2", "prompt": "test", "confirm": false }'

# Response: { "estimated_cost": { "micro": 1000, "display": "$0.001" } }

Voice cloning

Provide a reference audio URL to clone any voice. Works with models that support cloning (CosyVoice 2, FishSpeech).

{
  "model": "cosyvoice2",
  "prompt": "Your cloned voice reads this sentence perfectly.",
  "ref_audio_url": "https://example.com/my-voice-sample.mp3"
}

For best results, use a 10-30 second clear audio sample with minimal background noise. See the Voice Cloning Guide for details.

GET /v1/voices

List available voice presets for a given model.

curl https://api.fairstack.ai/v1/voices \
  -H "Authorization: Bearer $FAIRSTACK_API_KEY"

Returns an array of voice objects with name, language, gender, and preview_url.

Next steps