APIKO
Audio Series

Gemini 3.8 Flash TTS: API Reference

  • Google's Gemini text-to-speech model: send text, get spoken audio back. One speaker per request, with 30 prebuilt voices.
  • Gemini native format: POST https://api.apiko.app/v1/models/gemini-3.8-flash-tts:generateContent. Only /v1 is served; the same path under /v1beta returns 404.
  • Google GenAI SDKs work unchanged: set the base URL to https://api.apiko.app and the API version to v1.
  • Billed per token: text input tokens, plus audio output tokens at 25 tokens per second of speech. Live prices are on the model page.
POST
/
v1
/
models
/
gemini-3.8-flash-tts:generateContent
curl -sS "https://api.apiko.app/v1/models/gemini-3.8-flash-tts:generateContent" \
  -H "Authorization: Bearer $APIKO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "contents": [
    {
      "role": "user",
      "parts": [
        {
          "text": "Hello! This is a quick test of text to speech."
        }
      ]
    }
  ],
  "generationConfig": {
    "responseModalities": [
      "AUDIO"
    ],
    "speechConfig": {
      "voiceConfig": {
        "prebuiltVoiceConfig": {
          "voiceName": "Kore"
        }
      }
    }
  }
}' \
  | python3 -c '
import base64, io, json, re, sys, wave
res = json.load(sys.stdin)
if "candidates" not in res:
    sys.exit(json.dumps(res))
pcm, rate = b"", 24000
for part in res["candidates"][0]["content"]["parts"]:
    inline = part.get("inlineData")
    if not inline:
        continue
    data = base64.b64decode(inline["data"])
    if data[:4] == b"RIFF":  # audio/wav: already a WAV file, keep its samples
        with wave.open(io.BytesIO(data)) as w:
            rate, data = w.getframerate(), w.readframes(w.getnframes())
    else:  # audio/L16: raw 16-bit little-endian mono PCM
        m = re.search(r"rate=(\d+)", inline["mimeType"])
        rate = int(m.group(1)) if m else 24000
    pcm += data

with wave.open("speech.wav", "wb") as out:
    out.setnchannels(1)
    out.setsampwidth(2)
    out.setframerate(rate)
    out.writeframes(pcm)
print("saved speech.wav", res.get("usageMetadata"))
'
{
  "candidates": [
    {
      "content": {
        "role": "model",
        "parts": [
          {
            "inlineData": {
              "mimeType": "audio/L16;codec=pcm;rate=24000",
              "data": "AAABAAIA…"
            }
          }
        ]
      },
      "finishReason": "STOP"
    }
  ],
  "usageMetadata": {
    "promptTokenCount": 11,
    "candidatesTokenCount": 87,
    "totalTokenCount": 98
  }
}

Authorizations

Authorization
stringrequired
Send Authorization: Bearer <API_KEY>. Create keys in Console → API Keys.
x-goog-api-key
string
Alternative to Authorization: x-goog-api-key: <API_KEY>, the header Google GenAI SDKs send.

Body

application/json
contents
object[]required
The text to read, as one user turn: [{"role": "user", "parts": [{"text": "…"}]}]. The text is read as written. Text input only; audio, images and files are not accepted. The website playground takes up to 1,000 characters per request.
generationConfig.responseModalities
string[]required
Must be ["AUDIO"].
Example:["AUDIO"]
generationConfig.speechConfig.voiceConfig.prebuiltVoiceConfig.voiceName
enum<string>required
One of the 30 prebuilt voices. Names are case-sensitive.
Available options: Zephyr, Puck, Charon, Kore, Fenrir, Leda, Orus, Aoede, Callirrhoe, Autonoe, Enceladus, Iapetus, Umbriel, Algieba, Despina, Erinome, Algenib, Rasalgethi, Laomedeia, Achernar, Alnilam, Schedar, Gacrux, Pulcherrima, Achird, Zubenelgenubi, Vindemiatrix, Sadachbia, Sadaltager, Sulafat
Example:"Kore"
multiSpeakerVoiceConfig
not supported
Multi-speaker audio is not available through APIKO: send one voiceConfig per request. Per-part speaker or style metadata is dropped by the gateway, and streaming has not been verified on this route, so use the non-streaming generateContent call shown here.

Response

200 - application/json
candidates[0].content.parts[].inlineData
object
The audio, base64-encoded in data. Check mimeType: depending on the upstream route it is one of two formats.
  • audio/wav: data is already a complete WAV file. Decode and save it as is.
  • audio/L16;codec=pcm;rate=24000 or audio/l16; rate=24000; channels=1: raw 16-bit little-endian mono PCM at 24 kHz with no header. Prepend a 44-byte WAV header (or wrap it with any audio library) before playing it.
  • When several parts carry audio, join their samples in order under one header. Every example on this page handles both formats and writes speech.wav.
usageMetadata
object
Billed tokens: promptTokenCount for the text you sent, candidatesTokenCount for the generated audio (about 25 tokens per second of speech).

Errors

Errors use the OpenAI error shape <code>{"error": {"message", "type", "code"}}</code>.

400
invalid_request_error
The request is malformed. Fix it; do not retry it unchanged.
401
authentication_error
The API key is missing, invalid or revoked.
403
insufficient_user_quota
The balance cannot cover the request. Top up in Console → Billing.
404
not found
Wrong path: the speech route is only served under /v1, not /v1beta.
model_not_found: the model id is wrong or the model was retired. Check it with GET /v1/models; do not retry.
429
rate_limit_error
Too many requests. Retry with exponential backoff.
503
model_not_found
The model exists but none of its routes can take the request right now. Retry later with exponential backoff.