1. Model Description
Gemini TTS generates speech from text (and optional multimodal inputs), with invocation methods being Vertex generateContent (synchronous) and streamGenerateContent (SSE streaming).
2. Billing
2.1 Platform Billing Items and Usage
| chargeItemCode | Chinese Name | Usage Calculation (User Side) | Trigger Interface |
|---|---|---|---|
in_token |
input token | Response usageMetadata.promptTokenCount |
Four TTS interfaces |
out_token_audio |
output audio tokens | Sum of tokens with modality equal to AUDIOin the usageMetadata.candidatesTokensDetails of the response |
Four TTS interfaces |
3. Details of Functional Interfaces
3.0 Common Request Body (Shared by Four Interfaces)
Content-Type: application/json. The body is a Vertex GenerateContentRequest JSON (either camelCase or snake_case is acceptable, consistent with the official specification).
Main Fields
| Parameter Name | Field Type | Required or not | Description |
|---|---|---|---|
| contents | array / object | Yes | The content of the current conversation with the model. For single-turn queries, this is a single instance. For multi-turn queries, this is a repeated field that contains the conversation history and the latest request. |
| generationConfig | object | No | Generate configuration settings. In TTS scenarios, the commonly used component is speechConfig (for voice timbre, language, etc.). |
| systemInstruction | object | No | Applicable to gemini-2.0-flash and gemini-2.0-flash-lite. For instructions on guiding the model to achieve better performance. Text strings count towards the token limit. The role field of systemInstruction will be ignored and will not affect the model's performance. |
| safetySettings | array | No | Settings for each request, used to block unsafe content. Enforced on GenerateContentResponse.candidates. |
| tools | array | No | A piece of code that enables the system to interact with external systems to perform an action or a set of actions outside the scope and knowledge of the model. |
| toolConfig | object | No | Please refer to function calls. |
| cachedContent | string | No | The name of the cached content used as context to serve the prediction. Format: projects/{project}/locations/{location}/cachedContents/{cachedContent} |
| labels | object | No | You can add metadata to API calls in the Attribute–Value Pair format. |
generationConfig.speechConfig (commonly used for TTS)
| Parameter Name | Field Type | Required or not | Description |
|---|---|---|---|
| voiceConfig | object | No | Preset timbre configuration (for the structure, refer to the Google TTS / Gemini voice documentation). |
| multiSpeakerVoiceConfig | object | No | Multi-speaker voice configuration. |
| languageCode | string | No | Language code (e. g. en-US). |
Common Response Fields (Synchronous / Streaming Single Chunk)
| Parameter Name | Field Type | Description |
|---|---|---|
| candidates | array | Candidate results generated by the model; TTS audio is usually located at candidates[]. content.parts[]. inlineData (base64 audio). |
| usageMetadata | object | Token usage; includes promptTokenCount, candidatesTokenCount, candidatesTokensDetails, etc. |
| modelVersion | string | The model and version used for generation. |
| responseId | string | Response ID. |
| promptFeedback | object | Provide feedback related to prompts (e. g., security interceptions). |
3.1 Synchronous generateContent (Platform Path)
3.1.1 Request URL
POST https://genaiapi-m2.cloudsway.net/v1/ai/{YOUR_ENDPOINT}/tts/generateContent
3.1.2 Request Body Parameters
See §3.0.
3.1.3 Response Parameters
See §3.0 Public Response Fields. When the HTTP status code is 200, the body is a complete GenerateContentResponseJSON object.
3.1.4 Request Example
curl --location 'https://genaiapi-m2.cloudsway.net/v1/ai/{YOUR_ENDPOINT}/tts/generateContent' \
--header 'Authorization: Bearer {YOUR_AK}' \
--header 'Content-Type: application/json' \
--data '{
"contents": [{
"role": "user",
"parts": [{ "text": "Say hello in a friendly tone." }]
}],
"generationConfig": {
"speechConfig": {
"voiceConfig": {
"voice": "Kore"
}
}
}
}'
3.1.5 Response Example (Excerpt)
{
"candidates": [{
"content": {
"parts": [{
"inlineData": {
"mimeType": "audio/L16;codec=pcm;rate=24000",
"data": "<base64-audio>"
}
}]
}
}],
"usageMetadata": {
"promptTokenCount": 12,
"candidatesTokenCount": 85,
"candidatesTokensDetails": [
{ "modality": "AUDIO", "tokenCount": 80 }
]
}
}
3.2 Streaming streamGenerateContent (Platform Path)
3.2.1 Request URL
POST https://genaiapi-m2.cloudsway.net/v1/ai/{YOUR_ENDPOINT}/tts/streamGenerateContent
Optional Query:
| Parameter Name | Field Type | Required or not | Description |
|---|---|---|---|
| alt | string | No | When set to sse, Servlet SSE (text/event-stream) is used for write-back to adapt to some HTTP Clients; when omitted, a reactive SSE stream (text/event-stream) is returned. |
3.2.2 Request Body Parameters
See §3.0.
3.2.3 Response Description
-
Content-Type:
text/event-stream -
The data of each event is aGenerateContentResponse JSON (some implementations may add a leading space before the JSON, please trim it during parsing). -
On error, the stream may end after pushing a JSON containing the
errorfield. -
The usage shall be based on the last event
containing usageMetadata(see §2.2).
3.2.4 Request Example
curl --location 'https://genaiapi-m2.cloudsway.net/v1/ai/{YOUR_ENDPOINT}/tts/streamGenerateContent?alt=sse' \
--header 'Authorization: Bearer {YOUR_AK}' \
--header 'Content-Type: application/json' \
--header 'Accept: text/event-stream' \
--data '{
"contents": [{
"role": "user",
"parts": [{ "text": "Stream this sentence as speech." }]
}],
"generationConfig": {
"speechConfig": {
"voiceConfig": {
"voice": "Kore"
}
}
}
}'
3.3 Synchronous generateContent (Native Vertex Path)
3.3.1 Request URL
POST https://genaiapi-m2.cloudsway.net/{YOUR_ENDPOINT}/tts/v1beta1/publishers/google/models/{modelName}:generateContent
Path parameter{modelName}: Consistent with the Google model resource name (e. g. gemini-2.5-flash-preview-tts), it is recommended to be the same as the official model configured for the endpoint.
3.3.2 Request Body / Response
Same as §3.1 (for Body, see §3.0).
3.3.3 Request Example
curl --location 'https://genaiapi-m2.cloudsway.net/{YOUR_ENDPOINT}/tts/v1beta1/publishers/google/models/gemini-2.5-flash-preview-tts:generateContent' \
--header 'Authorization: Bearer {YOUR_AK}' \
--header 'Content-Type: application/json' \
--data '{
"contents": [{
"role": "user",
"parts": [{ "text": "Hello." }]
}],
"generationConfig": {
"speechConfig": {
"voiceConfig": {
"voice": "Kore"
}
}
}
}'
3.4 Streaming streamGenerateContent (Native Vertex Path)
3.4.1 Request URL
POST https://genaiapi-m2.cloudsway.net/{YOUR_ENDPOINT}/tts/v1beta1/publishers/google/models/{modelName}:streamGenerateContent
3.4.2 Request Body / Response
Body is the same as §3.0; the response is SSE (text/event-stream), with the semantics identical to §3.2.3 (the native path currently writes back via SSE).
3.4.3 Request Example
curl --location 'https://genaiapi-m2.cloudsway.net/{YOUR_ENDPOINT}/tts/v1beta1/publishers/google/models/gemini-2.5-flash-preview-tts:streamGenerateContent' \
--header 'Authorization: Bearer {YOUR_AK}' \
--header 'Content-Type: application/json' \
--header 'Accept: text/event-stream' \
--data '{
"contents": [{
"role": "user",
"parts": [{ "text": "Hello." }]
}],
"generationConfig": {
"speechConfig": {
"voiceConfig": {
"voice": "Kore"
}
}
}
}'