文本生成+思考-流 Gemini原生
![]()
POST
https://api.quickrouter.ai/v1beta/models/gemini-2.5-pro:streamGenerateContent?key=&alt=sse
在线调试 →
▼
Authorization
在 Header 添加参数 Authorization,其值为 Bearer 之后拼接 Token
示例:
Authorization: Bearer ********************
请求参数
Header 参数
Content-Type
string
必需
示例: application/json
Authorization
string
必需
示例: Bearer $OPENAI_API_KEY
Body 参数 application/json
contents
array [object]
必需
对话内容列表,每条包含 role 和 parts。
systemInstruction
object
可选
系统指令,用于设定模型角色和行为。
generationConfig
object
可选
生成配置,包含 thinkingConfig 启用思考模式。
示例
{
"contents": [
{
"parts": [
{
"text": "1+2+3+4+5+....+999?"
}
],
"role": "user"
}
],
"systemInstruction": {
"parts": [
{
"text": "hi"
}
],
"role": "user"
},
"generationConfig": {
"temperature": 1,
"topP": 1,
"thinkingConfig": {
"includeThoughts": true,
"thinkingBudget": 26240
}
}
}
请求示例代码
curl --location -g --request POST 'https://api.quickrouter.ai/v1beta/models/gemini-2.5-pro:streamGenerateContent?key=&alt=sse' \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data-raw '{
"contents": [
{
"parts": [
{
"text": "1+2+3+4+5+....+999?"
}
],
"role": "user"
}
],
"systemInstruction": {
"parts": [
{
"text": "hi"
}
],
"role": "user"
},
"safetySettings": [
{
"category": "HARM_CATEGORY_HATE_SPEECH",
"threshold": "OFF"
},
{
"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
"threshold": "OFF"
},
{
"category": "HARM_CATEGORY_HARASSMENT",
"threshold": "OFF"
},
{
"category": "HARM_CATEGORY_DANGEROUS_CONTENT",
"threshold": "OFF"
},
{
"category": "HARM_CATEGORY_CIVIC_INTEGRITY",
"threshold": "BLOCK_NONE"
}
],
"tools": [],
"generationConfig": {
"temperature": 1,
"topP": 1,
"thinkingConfig": {
"includeThoughts": true,
"thinkingBudget": 26240
}
}
}'
var myHeaders = new Headers();
myHeaders.append("Authorization", "Bearer <token>");
myHeaders.append("Content-Type", "application/json");
var raw = JSON.stringify({
"contents": [
{
"parts": [
{
"text": "1+2+3+4+5+....+999?"
}
],
"role": "user"
}
],
"systemInstruction": {
"parts": [
{
"text": "hi"
}
],
"role": "user"
},
"safetySettings": [
{
"category": "HARM_CATEGORY_HATE_SPEECH",
"threshold": "OFF"
},
{
"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
"threshold": "OFF"
},
{
"category": "HARM_CATEGORY_HARASSMENT",
"threshold": "OFF"
},
{
"category": "HARM_CATEGORY_DANGEROUS_CONTENT",
"threshold": "OFF"
},
{
"category": "HARM_CATEGORY_CIVIC_INTEGRITY",
"threshold": "BLOCK_NONE"
}
],
"tools": [],
"generationConfig": {
"temperature": 1,
"topP": 1,
"thinkingConfig": {
"includeThoughts": true,
"thinkingBudget": 26240
}
}
});
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: raw,
redirect: 'follow'
};
fetch("https://api.quickrouter.ai/v1beta/models/gemini-2.5-pro:streamGenerateContent?key=&alt=sse", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
import http.client
import json
conn = http.client.HTTPSConnection("api.quickrouter.ai")
payload = json.dumps({
"contents": [
{
"parts": [
{
"text": "1+2+3+4+5+....+999?"
}
],
"role": "user"
}
],
"systemInstruction": {
"parts": [
{
"text": "hi"
}
],
"role": "user"
},
"safetySettings": [
{
"category": "HARM_CATEGORY_HATE_SPEECH",
"threshold": "OFF"
},
{
"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
"threshold": "OFF"
},
{
"category": "HARM_CATEGORY_HARASSMENT",
"threshold": "OFF"
},
{
"category": "HARM_CATEGORY_DANGEROUS_CONTENT",
"threshold": "OFF"
},
{
"category": "HARM_CATEGORY_CIVIC_INTEGRITY",
"threshold": "BLOCK_NONE"
}
],
"tools": [],
"generationConfig": {
"temperature": 1,
"topP": 1,
"thinkingConfig": {
"includeThoughts": True,
"thinkingBudget": 26240
}
}
})
headers = {
'Authorization': 'Bearer <token>',
'Content-Type': 'application/json'
}
conn.request("POST", "/v1beta/models/gemini-2.5-pro:streamGenerateContent?key=&alt=sse", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
返回响应
响应参数 🟢 200 OK · application/json
candidates
array [object]
必需
modelVersion
string
必需
示例
{
"candidates": [
{
"content": {
"parts": [
{
"text": "499500"
}
],
"role": "model"
},
"finishReason": "STOP"
}
],
"modelVersion": "gemini-2.5-pro"
}