Gemini native streaming text generation
curl --request POST \
--url https://api.omnimux.ai/v1beta/models/{model}:streamGenerateContent \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"contents": [
{
"role": "user",
"parts": [
{
"text": "Hello."
}
]
}
]
}
'import requests
url = "https://api.omnimux.ai/v1beta/models/{model}:streamGenerateContent"
payload = { "contents": [
{
"role": "user",
"parts": [{ "text": "Hello." }]
}
] }
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({contents: [{role: 'user', parts: [{text: 'Hello.'}]}]})
};
fetch('https://api.omnimux.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://api.omnimux.ai/v1beta/models/{model}:streamGenerateContent"
payload := strings.NewReader("{\n \"contents\": [\n {\n \"role\": \"user\",\n \"parts\": [\n {\n \"text\": \"Hello.\"\n }\n ]\n }\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
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":"model","parts":[{"text":"Hello"}]}}]}
data: {"candidates":[{"finishReason":"STOP"}],"usageMetadata":{"promptTokenCount":74,"candidatesTokenCount":6,"thoughtsTokenCount":115,"totalTokenCount":195}}
{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}Gemini
Gemini · 原生流式理解
使用原生事件流接收生成内容并检查最终结果和用量。
POST
/
v1beta
/
models
/
{model}
:streamGenerateContent
Gemini native streaming text generation
curl --request POST \
--url https://api.omnimux.ai/v1beta/models/{model}:streamGenerateContent \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"contents": [
{
"role": "user",
"parts": [
{
"text": "Hello."
}
]
}
]
}
'import requests
url = "https://api.omnimux.ai/v1beta/models/{model}:streamGenerateContent"
payload = { "contents": [
{
"role": "user",
"parts": [{ "text": "Hello." }]
}
] }
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({contents: [{role: 'user', parts: [{text: 'Hello.'}]}]})
};
fetch('https://api.omnimux.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://api.omnimux.ai/v1beta/models/{model}:streamGenerateContent"
payload := strings.NewReader("{\n \"contents\": [\n {\n \"role\": \"user\",\n \"parts\": [\n {\n \"text\": \"Hello.\"\n }\n ]\n }\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
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":"model","parts":[{"text":"Hello"}]}}]}
data: {"candidates":[{"finishReason":"STOP"}],"usageMetadata":{"promptTokenCount":74,"candidatesTokenCount":6,"thoughtsTokenCount":115,"totalTokenCount":195}}
{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}- 型号:
gemini-4-argon、gemini-4-hydrogen、gemini-4-neon、gemini-4-carbon;请求地址需带alt=sse。 - 请求正文与原生多模态理解相同。
- 读取
data:事件中的原生回复片段,等待正常结束并检查finishReason与最终可用的usageMetadata。 - 已收到部分文字不能证明完整成功;中断后先核对结果与费用,避免重复发起。
responseSchema。
用量与错误
累计用量快照不逐条相加。输入含已报告工具输入,输出含已报告思考,缓存是输入子集。费用以已公布账户价格与最终结算为准;自动切换服务线路不会改变该模型的已公布售价。余额不足除402 外,也可能返回 403 和 insufficient_user_quota。请求体
application/json
响应
SSE data events containing native response chunks
The response is of type string.