Kuai API

Text-to-Speech (Gemini TTS)

Endpoint: POST https://api.kuai.host/v1beta/models/gemini-3.8-flash-tts:generateContent

Official documentation: https://ai.google.dev/gemini-api/docs/speech-generation

Synthesize speech from text in Gemini native format. Replace the model name in the request path with the TTS model you want:

Model Request path
gemini-3.8-flash-tts /v1beta/models/gemini-3.8-flash-tts:generateContent
gemini-3.1-flash-tts-preview /v1beta/models/gemini-3.1-flash-tts-preview:generateContent
gemini-2.5-flash-preview-tts /v1beta/models/gemini-2.5-flash-preview-tts:generateContent
gemini-2.5-pro-preview-tts /v1beta/models/gemini-2.5-pro-preview-tts:generateContent

Notes

  • Set generationConfig.responseModalities to ["AUDIO"] and pick the voice in generationConfig.speechConfig.voiceConfig.prebuiltVoiceConfig.voiceName.
  • Describe the tone in the text itself (e.g. Say cheerfully: ...), or pass a style separately in parts[].speechMetadata.style.
  • Do not send systemInstruction: gemini-3.8-flash-tts returns 400 "Request contains an invalid argument".
  • The audio is in candidates[0].content.parts[0].inlineData.data: base64-encoded raw PCM (audio/L16;codec=pcm;rate=24000: 16-bit, mono, 24000 Hz). Add a WAV header yourself to save it as a WAV file.
  • Billed by token: input by text, output by audio. See the model marketplace for prices.

Parameters

  • key (query, string, required): API Key (Authorization: Bearer also supported)
  • Content-Type (header, string, required): Request body content type, usually application/json

Request body (application/json)

  • contents (array<object>, required): Content to synthesize; usually a single item.
  • generationConfig (object, required): Generation config; must include the audio modality and a voice.
  • safetySettings (array<object>): Safety settings (optional); usually not needed. If omitted, the gateway adds default settings to reduce "200 with no audio" responses.

Request example

{
  "contents": [
    {
      "parts": [
        {
          "text": "Say cheerfully: Have a wonderful day!"
        }
      ]
    }
  ],
  "generationConfig": {
    "responseModalities": [
      "AUDIO"
    ],
    "speechConfig": {
      "voiceConfig": {
        "prebuiltVoiceConfig": {
          "voiceName": "Kore"
        }
      }
    }
  }
}