Search...
Menu

Speech Generation (Native Gemini Format)

Generate speech using Gemini's native generateContent endpoint.

Request

Item Description
Method POST
Path /v1beta/models/{model}:generateContent
Gateway URL https://ailink.nativex.com
Authentication Authorization: Bearer sk-xxxx; replace the placeholder with your API Key
Request format application/json

Replace MODEL_ID with a model from the Model Marketplace that supports this endpoint. Available models, parameters, and permissions depend on your account.

Parameters

Parameter Location Type Required Description
model Path string Yes A Gemini model that supports audio output
contents Body object[] Yes Input messages; provide the text to read in parts[].text
generationConfig.responseModalities Body string[] Yes Use ["AUDIO"] for audio output
generationConfig.speechConfig Body object No Speech settings. A supported voice can be specified in voiceConfig.prebuiltVoiceConfig.voiceName.
Native Gemini audio results are usually Base64 data, rather than an MP3 download URL.

Example

curl -X POST 'https://ailink.nativex.com/v1beta/models/MODEL_ID:generateContent' \
  -H 'Authorization: Bearer sk-xxxx' \
  -H 'Content-Type: application/json' \
  -d '{
  "contents": [
    {
      "parts": [
        {
          "text": "Read naturally: Welcome to AiLink."
        }
      ]
    }
  ],
  "generationConfig": {
    "responseModalities": [
      "AUDIO"
    ]
  }
}'

Response

The following is a simplified response for readability. IDs, URLs, text, and usage values are illustrative.

{
  "candidates": [
    {
      "content": {
        "parts": [
          {
            "inlineData": {
              "mimeType": "audio/L16;codec=pcm;rate=24000",
              "data": "BASE64_AUDIO"
            }
          }
        ]
      }
    }
  ]
}
Field or result Description
candidates[].content.parts[].inlineData Audio MIME type and Base64 data. Decode the data, then save or package it according to the MIME type.

Error handling

For unsuccessful responses, check the HTTP status and error body first. Verify the API Key, model name, account balance, and parameters. If rate limited, reduce concurrency and retry later.

Last modified: 2026-11-17