Gemini Streaming Chat
Interface description: Compatible endpoint (streaming output, SSE) of the Gemini :streamGenerateContent API. The request and response formats follow the Gemini specification; authentication uses the x-goog-api-key header (carried by Gemini SDK by default). Existing Gemini SDK can be accessed by simply replacing the baseURL and API Key, and billing is based on AiToEarn points.
Before calling this interface, please request the “Conversation Model List” interface (GET /api/ai/models/chat) to obtain the currently available model list.
curl --request POST \
--url https://aitoearn.cn/api/ai/v1beta/models/{model}:streamGenerateContent \
--header 'Content-Type: application/json' \
--header 'x-goog-api-key: <api-key>' \
--data '
{
"model": "gemini-3.5-flash",
"contents": [
{
"role": "user",
"parts": [
{
"text": "Reply with OK only."
}
]
}
]
}
'import requests
url = "https://aitoearn.cn/api/ai/v1beta/models/{model}:streamGenerateContent"
payload = {
"model": "gemini-3.5-flash",
"contents": [
{
"role": "user",
"parts": [{ "text": "Reply with OK only." }]
}
]
}
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({
model: 'gemini-3.5-flash',
contents: [{role: 'user', parts: [{text: 'Reply with OK only.'}]}]
})
};
fetch('https://aitoearn.cn/api/ai/v1beta/models/{model}:streamGenerateContent', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://aitoearn.cn/api/ai/v1beta/models/{model}:streamGenerateContent"
payload := strings.NewReader("{\n \"model\": \"gemini-3.5-flash\",\n \"contents\": [\n {\n \"role\": \"user\",\n \"parts\": [\n {\n \"text\": \"Reply with OK only.\"\n }\n ]\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))
}data: {"candidates":[{"content":{"role":"string","parts":[{"text":"string"}]},"index":"integer"}],"modelVersion":"string","sdkHttpResponse":{"headers":"object"}}
data: {"candidates":[{"finishReason":"string","index":"integer"}],"modelVersion":"string","usageMetadata":{"promptTokenCount":"integer","candidatesTokenCount":"integer","totalTokenCount":"integer"},"sdkHttpResponse":{"headers":"object"}}Authorizations
Pass an API Key obtained from AiToEarn. For Gemini SDK compatibility, this endpoint uses the x-goog-api-key request header; a Google Gemini API Key is not required.
Path Parameters
Model ID. First call the "Conversation Model List" interface (GET /api/ai/models/chat) and pass in the data[n].name returned by it.
"gemini-3.5-flash"
Body
Model ID, consistent with the path parameter model. The value comes from data[n].name returned by the "Conversation Model List" interface.
"gemini-3.5-flash"
Contents list
Hide child attributes
Hide child attributes
Generate configuration
Hide child attributes
Hide child attributes
Controls the randomness of the output. The higher the value, the more divergent it is. The lower the value, the more stable it is.
Kernel sampling parameters, limiting the maximum cumulative probability of tokens considered during sampling.
Top-K sampling parameters, limiting the number of highest probability tokens considered during sampling
The number of candidate answers to be returned
Maximum number of output tokens for candidate answers
Whether to return token logarithmic probability information
The number of high-probability candidate tokens returned in each decoding step, only takes effect when responseLogprobs=true
There is a penalty that is used to reduce or increase the tendency of tokens to appear again.
Frequency penalty, which suppresses or encourages repetition based on the number of occurrences of the token
Decode random seeds to improve output reproducibility
expected response type
JSON output structure constraints, usually used with responseMimeType=application/json
Response
Native third-party protocol response or SSE data, not wrapped in the AiToEarn common response envelope.
SSE streaming response.
curl --request POST \
--url https://aitoearn.cn/api/ai/v1beta/models/{model}:streamGenerateContent \
--header 'Content-Type: application/json' \
--header 'x-goog-api-key: <api-key>' \
--data '
{
"model": "gemini-3.5-flash",
"contents": [
{
"role": "user",
"parts": [
{
"text": "Reply with OK only."
}
]
}
]
}
'import requests
url = "https://aitoearn.cn/api/ai/v1beta/models/{model}:streamGenerateContent"
payload = {
"model": "gemini-3.5-flash",
"contents": [
{
"role": "user",
"parts": [{ "text": "Reply with OK only." }]
}
]
}
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({
model: 'gemini-3.5-flash',
contents: [{role: 'user', parts: [{text: 'Reply with OK only.'}]}]
})
};
fetch('https://aitoearn.cn/api/ai/v1beta/models/{model}:streamGenerateContent', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://aitoearn.cn/api/ai/v1beta/models/{model}:streamGenerateContent"
payload := strings.NewReader("{\n \"model\": \"gemini-3.5-flash\",\n \"contents\": [\n {\n \"role\": \"user\",\n \"parts\": [\n {\n \"text\": \"Reply with OK only.\"\n }\n ]\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))
}data: {"candidates":[{"content":{"role":"string","parts":[{"text":"string"}]},"index":"integer"}],"modelVersion":"string","sdkHttpResponse":{"headers":"object"}}
data: {"candidates":[{"finishReason":"string","index":"integer"}],"modelVersion":"string","usageMetadata":{"promptTokenCount":"integer","candidatesTokenCount":"integer","totalTokenCount":"integer"},"sdkHttpResponse":{"headers":"object"}}
