Gemini streamGenerateContent
curl --request POST \
--url https://api-vip.apigo.ai/v1beta/models/{model}:streamGenerateContent \
--header 'Content-Type: application/json' \
--header 'x-goog-api-key: <api-key>' \
--data '
{
"contents": [
{
"role": "<string>",
"parts": [
{
"text": "<string>",
"inlineData": {
"mimeType": "<string>",
"data": "<string>"
},
"fileData": {
"mimeType": "<string>",
"fileUri": "<string>"
}
}
]
}
],
"systemInstruction": {
"role": "<string>",
"parts": [
{
"text": "<string>",
"inlineData": {
"mimeType": "<string>",
"data": "<string>"
},
"fileData": {
"mimeType": "<string>",
"fileUri": "<string>"
}
}
]
},
"generationConfig": {
"temperature": 0.7,
"topP": 123,
"maxOutputTokens": 123,
"responseMimeType": "<string>"
},
"safetySettings": [
{
"category": "<string>",
"threshold": "<string>"
}
],
"tools": [
{}
]
}
'import requests
url = "https://api-vip.apigo.ai/v1beta/models/{model}:streamGenerateContent"
payload = {
"contents": [
{
"role": "<string>",
"parts": [
{
"text": "<string>",
"inlineData": {
"mimeType": "<string>",
"data": "<string>"
},
"fileData": {
"mimeType": "<string>",
"fileUri": "<string>"
}
}
]
}
],
"systemInstruction": {
"role": "<string>",
"parts": [
{
"text": "<string>",
"inlineData": {
"mimeType": "<string>",
"data": "<string>"
},
"fileData": {
"mimeType": "<string>",
"fileUri": "<string>"
}
}
]
},
"generationConfig": {
"temperature": 0.7,
"topP": 123,
"maxOutputTokens": 123,
"responseMimeType": "<string>"
},
"safetySettings": [
{
"category": "<string>",
"threshold": "<string>"
}
],
"tools": [{}]
}
headers = {
"x-goog-api-key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'x-goog-api-key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
contents: [
{
role: '<string>',
parts: [
{
text: '<string>',
inlineData: {mimeType: '<string>', data: '<string>'},
fileData: {mimeType: '<string>', fileUri: '<string>'}
}
]
}
],
systemInstruction: {
role: '<string>',
parts: [
{
text: '<string>',
inlineData: {mimeType: '<string>', data: '<string>'},
fileData: {mimeType: '<string>', fileUri: '<string>'}
}
]
},
generationConfig: {
temperature: 0.7,
topP: 123,
maxOutputTokens: 123,
responseMimeType: '<string>'
},
safetySettings: [{category: '<string>', threshold: '<string>'}],
tools: [{}]
})
};
fetch('https://api-vip.apigo.ai/v1beta/models/{model}:streamGenerateContent', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api-vip.apigo.ai/v1beta/models/{model}:streamGenerateContent",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'contents' => [
[
'role' => '<string>',
'parts' => [
[
'text' => '<string>',
'inlineData' => [
'mimeType' => '<string>',
'data' => '<string>'
],
'fileData' => [
'mimeType' => '<string>',
'fileUri' => '<string>'
]
]
]
]
],
'systemInstruction' => [
'role' => '<string>',
'parts' => [
[
'text' => '<string>',
'inlineData' => [
'mimeType' => '<string>',
'data' => '<string>'
],
'fileData' => [
'mimeType' => '<string>',
'fileUri' => '<string>'
]
]
]
],
'generationConfig' => [
'temperature' => 0.7,
'topP' => 123,
'maxOutputTokens' => 123,
'responseMimeType' => '<string>'
],
'safetySettings' => [
[
'category' => '<string>',
'threshold' => '<string>'
]
],
'tools' => [
[
]
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"x-goog-api-key: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api-vip.apigo.ai/v1beta/models/{model}:streamGenerateContent"
payload := strings.NewReader("{\n \"contents\": [\n {\n \"role\": \"<string>\",\n \"parts\": [\n {\n \"text\": \"<string>\",\n \"inlineData\": {\n \"mimeType\": \"<string>\",\n \"data\": \"<string>\"\n },\n \"fileData\": {\n \"mimeType\": \"<string>\",\n \"fileUri\": \"<string>\"\n }\n }\n ]\n }\n ],\n \"systemInstruction\": {\n \"role\": \"<string>\",\n \"parts\": [\n {\n \"text\": \"<string>\",\n \"inlineData\": {\n \"mimeType\": \"<string>\",\n \"data\": \"<string>\"\n },\n \"fileData\": {\n \"mimeType\": \"<string>\",\n \"fileUri\": \"<string>\"\n }\n }\n ]\n },\n \"generationConfig\": {\n \"temperature\": 0.7,\n \"topP\": 123,\n \"maxOutputTokens\": 123,\n \"responseMimeType\": \"<string>\"\n },\n \"safetySettings\": [\n {\n \"category\": \"<string>\",\n \"threshold\": \"<string>\"\n }\n ],\n \"tools\": [\n {}\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("x-goog-api-key", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api-vip.apigo.ai/v1beta/models/{model}:streamGenerateContent")
.header("x-goog-api-key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"contents\": [\n {\n \"role\": \"<string>\",\n \"parts\": [\n {\n \"text\": \"<string>\",\n \"inlineData\": {\n \"mimeType\": \"<string>\",\n \"data\": \"<string>\"\n },\n \"fileData\": {\n \"mimeType\": \"<string>\",\n \"fileUri\": \"<string>\"\n }\n }\n ]\n }\n ],\n \"systemInstruction\": {\n \"role\": \"<string>\",\n \"parts\": [\n {\n \"text\": \"<string>\",\n \"inlineData\": {\n \"mimeType\": \"<string>\",\n \"data\": \"<string>\"\n },\n \"fileData\": {\n \"mimeType\": \"<string>\",\n \"fileUri\": \"<string>\"\n }\n }\n ]\n },\n \"generationConfig\": {\n \"temperature\": 0.7,\n \"topP\": 123,\n \"maxOutputTokens\": 123,\n \"responseMimeType\": \"<string>\"\n },\n \"safetySettings\": [\n {\n \"category\": \"<string>\",\n \"threshold\": \"<string>\"\n }\n ],\n \"tools\": [\n {}\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api-vip.apigo.ai/v1beta/models/{model}:streamGenerateContent")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["x-goog-api-key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"contents\": [\n {\n \"role\": \"<string>\",\n \"parts\": [\n {\n \"text\": \"<string>\",\n \"inlineData\": {\n \"mimeType\": \"<string>\",\n \"data\": \"<string>\"\n },\n \"fileData\": {\n \"mimeType\": \"<string>\",\n \"fileUri\": \"<string>\"\n }\n }\n ]\n }\n ],\n \"systemInstruction\": {\n \"role\": \"<string>\",\n \"parts\": [\n {\n \"text\": \"<string>\",\n \"inlineData\": {\n \"mimeType\": \"<string>\",\n \"data\": \"<string>\"\n },\n \"fileData\": {\n \"mimeType\": \"<string>\",\n \"fileUri\": \"<string>\"\n }\n }\n ]\n },\n \"generationConfig\": {\n \"temperature\": 0.7,\n \"topP\": 123,\n \"maxOutputTokens\": 123,\n \"responseMimeType\": \"<string>\"\n },\n \"safetySettings\": [\n {\n \"category\": \"<string>\",\n \"threshold\": \"<string>\"\n }\n ],\n \"tools\": [\n {}\n ]\n}"
response = http.request(request)
puts response.read_body"data: {\"candidates\":[{\"content\":{\"parts\":[{\"text\":\"这里是第一段\"}]}}]}\n\n"{
"error": 123,
"message": "<string>"
}Text
/v1beta/models/{model}:streamGenerateContent
Streams incremental Gemini generation events.
POST
/
v1beta
/
models
/
{model}
:streamGenerateContent
Gemini streamGenerateContent
curl --request POST \
--url https://api-vip.apigo.ai/v1beta/models/{model}:streamGenerateContent \
--header 'Content-Type: application/json' \
--header 'x-goog-api-key: <api-key>' \
--data '
{
"contents": [
{
"role": "<string>",
"parts": [
{
"text": "<string>",
"inlineData": {
"mimeType": "<string>",
"data": "<string>"
},
"fileData": {
"mimeType": "<string>",
"fileUri": "<string>"
}
}
]
}
],
"systemInstruction": {
"role": "<string>",
"parts": [
{
"text": "<string>",
"inlineData": {
"mimeType": "<string>",
"data": "<string>"
},
"fileData": {
"mimeType": "<string>",
"fileUri": "<string>"
}
}
]
},
"generationConfig": {
"temperature": 0.7,
"topP": 123,
"maxOutputTokens": 123,
"responseMimeType": "<string>"
},
"safetySettings": [
{
"category": "<string>",
"threshold": "<string>"
}
],
"tools": [
{}
]
}
'import requests
url = "https://api-vip.apigo.ai/v1beta/models/{model}:streamGenerateContent"
payload = {
"contents": [
{
"role": "<string>",
"parts": [
{
"text": "<string>",
"inlineData": {
"mimeType": "<string>",
"data": "<string>"
},
"fileData": {
"mimeType": "<string>",
"fileUri": "<string>"
}
}
]
}
],
"systemInstruction": {
"role": "<string>",
"parts": [
{
"text": "<string>",
"inlineData": {
"mimeType": "<string>",
"data": "<string>"
},
"fileData": {
"mimeType": "<string>",
"fileUri": "<string>"
}
}
]
},
"generationConfig": {
"temperature": 0.7,
"topP": 123,
"maxOutputTokens": 123,
"responseMimeType": "<string>"
},
"safetySettings": [
{
"category": "<string>",
"threshold": "<string>"
}
],
"tools": [{}]
}
headers = {
"x-goog-api-key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'x-goog-api-key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
contents: [
{
role: '<string>',
parts: [
{
text: '<string>',
inlineData: {mimeType: '<string>', data: '<string>'},
fileData: {mimeType: '<string>', fileUri: '<string>'}
}
]
}
],
systemInstruction: {
role: '<string>',
parts: [
{
text: '<string>',
inlineData: {mimeType: '<string>', data: '<string>'},
fileData: {mimeType: '<string>', fileUri: '<string>'}
}
]
},
generationConfig: {
temperature: 0.7,
topP: 123,
maxOutputTokens: 123,
responseMimeType: '<string>'
},
safetySettings: [{category: '<string>', threshold: '<string>'}],
tools: [{}]
})
};
fetch('https://api-vip.apigo.ai/v1beta/models/{model}:streamGenerateContent', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api-vip.apigo.ai/v1beta/models/{model}:streamGenerateContent",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'contents' => [
[
'role' => '<string>',
'parts' => [
[
'text' => '<string>',
'inlineData' => [
'mimeType' => '<string>',
'data' => '<string>'
],
'fileData' => [
'mimeType' => '<string>',
'fileUri' => '<string>'
]
]
]
]
],
'systemInstruction' => [
'role' => '<string>',
'parts' => [
[
'text' => '<string>',
'inlineData' => [
'mimeType' => '<string>',
'data' => '<string>'
],
'fileData' => [
'mimeType' => '<string>',
'fileUri' => '<string>'
]
]
]
],
'generationConfig' => [
'temperature' => 0.7,
'topP' => 123,
'maxOutputTokens' => 123,
'responseMimeType' => '<string>'
],
'safetySettings' => [
[
'category' => '<string>',
'threshold' => '<string>'
]
],
'tools' => [
[
]
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"x-goog-api-key: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api-vip.apigo.ai/v1beta/models/{model}:streamGenerateContent"
payload := strings.NewReader("{\n \"contents\": [\n {\n \"role\": \"<string>\",\n \"parts\": [\n {\n \"text\": \"<string>\",\n \"inlineData\": {\n \"mimeType\": \"<string>\",\n \"data\": \"<string>\"\n },\n \"fileData\": {\n \"mimeType\": \"<string>\",\n \"fileUri\": \"<string>\"\n }\n }\n ]\n }\n ],\n \"systemInstruction\": {\n \"role\": \"<string>\",\n \"parts\": [\n {\n \"text\": \"<string>\",\n \"inlineData\": {\n \"mimeType\": \"<string>\",\n \"data\": \"<string>\"\n },\n \"fileData\": {\n \"mimeType\": \"<string>\",\n \"fileUri\": \"<string>\"\n }\n }\n ]\n },\n \"generationConfig\": {\n \"temperature\": 0.7,\n \"topP\": 123,\n \"maxOutputTokens\": 123,\n \"responseMimeType\": \"<string>\"\n },\n \"safetySettings\": [\n {\n \"category\": \"<string>\",\n \"threshold\": \"<string>\"\n }\n ],\n \"tools\": [\n {}\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("x-goog-api-key", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api-vip.apigo.ai/v1beta/models/{model}:streamGenerateContent")
.header("x-goog-api-key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"contents\": [\n {\n \"role\": \"<string>\",\n \"parts\": [\n {\n \"text\": \"<string>\",\n \"inlineData\": {\n \"mimeType\": \"<string>\",\n \"data\": \"<string>\"\n },\n \"fileData\": {\n \"mimeType\": \"<string>\",\n \"fileUri\": \"<string>\"\n }\n }\n ]\n }\n ],\n \"systemInstruction\": {\n \"role\": \"<string>\",\n \"parts\": [\n {\n \"text\": \"<string>\",\n \"inlineData\": {\n \"mimeType\": \"<string>\",\n \"data\": \"<string>\"\n },\n \"fileData\": {\n \"mimeType\": \"<string>\",\n \"fileUri\": \"<string>\"\n }\n }\n ]\n },\n \"generationConfig\": {\n \"temperature\": 0.7,\n \"topP\": 123,\n \"maxOutputTokens\": 123,\n \"responseMimeType\": \"<string>\"\n },\n \"safetySettings\": [\n {\n \"category\": \"<string>\",\n \"threshold\": \"<string>\"\n }\n ],\n \"tools\": [\n {}\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api-vip.apigo.ai/v1beta/models/{model}:streamGenerateContent")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["x-goog-api-key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"contents\": [\n {\n \"role\": \"<string>\",\n \"parts\": [\n {\n \"text\": \"<string>\",\n \"inlineData\": {\n \"mimeType\": \"<string>\",\n \"data\": \"<string>\"\n },\n \"fileData\": {\n \"mimeType\": \"<string>\",\n \"fileUri\": \"<string>\"\n }\n }\n ]\n }\n ],\n \"systemInstruction\": {\n \"role\": \"<string>\",\n \"parts\": [\n {\n \"text\": \"<string>\",\n \"inlineData\": {\n \"mimeType\": \"<string>\",\n \"data\": \"<string>\"\n },\n \"fileData\": {\n \"mimeType\": \"<string>\",\n \"fileUri\": \"<string>\"\n }\n }\n ]\n },\n \"generationConfig\": {\n \"temperature\": 0.7,\n \"topP\": 123,\n \"maxOutputTokens\": 123,\n \"responseMimeType\": \"<string>\"\n },\n \"safetySettings\": [\n {\n \"category\": \"<string>\",\n \"threshold\": \"<string>\"\n }\n ],\n \"tools\": [\n {}\n ]\n}"
response = http.request(request)
puts response.read_body"data: {\"candidates\":[{\"content\":{\"parts\":[{\"text\":\"这里是第一段\"}]}}]}\n\n"{
"error": 123,
"message": "<string>"
}Use this endpoint for Gemini streaming text generation and incremental event output.
- The common auth pattern is
x-goog-api-key: {API_KEY}, though query-string API keys are also supported - The request structure is mostly the same as
generateContent, withcontentsas the core field - The response is an event stream rather than one final JSON payload
- Finish state and safety metadata may only become complete in later chunks
Authorizations
Path Parameters
Gemini model name.
Example:
"gemini-2.5-pro"
Body
application/json
Response
Successful Gemini streaming response
The response is of type string.
⌘I
