curl --request POST \
--url https://api.tikway.ai/v1beta/models/{model}:streamGenerateContent \
--header 'Content-Type: application/json' \
--header 'x-goog-api-key: <api-key>' \
--data '
{
"systemInstruction": {
"parts": [
{
"text": "You are a helpful assistant."
}
]
},
"contents": [
{
"role": "user",
"parts": [
{
"text": "Write a short bedtime story about a unicorn."
}
]
}
],
"generationConfig": {
"maxOutputTokens": 1024
}
}
'import requests
url = "https://api.tikway.ai/v1beta/models/{model}:streamGenerateContent"
payload = {
"systemInstruction": { "parts": [{ "text": "You are a helpful assistant." }] },
"contents": [
{
"role": "user",
"parts": [{ "text": "Write a short bedtime story about a unicorn." }]
}
],
"generationConfig": { "maxOutputTokens": 1024 }
}
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({
systemInstruction: {parts: [{text: 'You are a helpful assistant.'}]},
contents: [
{role: 'user', parts: [{text: 'Write a short bedtime story about a unicorn.'}]}
],
generationConfig: {maxOutputTokens: 1024}
})
};
fetch('https://api.tikway.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.tikway.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([
'systemInstruction' => [
'parts' => [
[
'text' => 'You are a helpful assistant.'
]
]
],
'contents' => [
[
'role' => 'user',
'parts' => [
[
'text' => 'Write a short bedtime story about a unicorn.'
]
]
]
],
'generationConfig' => [
'maxOutputTokens' => 1024
]
]),
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.tikway.ai/v1beta/models/{model}:streamGenerateContent"
payload := strings.NewReader("{\n \"systemInstruction\": {\n \"parts\": [\n {\n \"text\": \"You are a helpful assistant.\"\n }\n ]\n },\n \"contents\": [\n {\n \"role\": \"user\",\n \"parts\": [\n {\n \"text\": \"Write a short bedtime story about a unicorn.\"\n }\n ]\n }\n ],\n \"generationConfig\": {\n \"maxOutputTokens\": 1024\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.tikway.ai/v1beta/models/{model}:streamGenerateContent")
.header("x-goog-api-key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"systemInstruction\": {\n \"parts\": [\n {\n \"text\": \"You are a helpful assistant.\"\n }\n ]\n },\n \"contents\": [\n {\n \"role\": \"user\",\n \"parts\": [\n {\n \"text\": \"Write a short bedtime story about a unicorn.\"\n }\n ]\n }\n ],\n \"generationConfig\": {\n \"maxOutputTokens\": 1024\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.tikway.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 \"systemInstruction\": {\n \"parts\": [\n {\n \"text\": \"You are a helpful assistant.\"\n }\n ]\n },\n \"contents\": [\n {\n \"role\": \"user\",\n \"parts\": [\n {\n \"text\": \"Write a short bedtime story about a unicorn.\"\n }\n ]\n }\n ],\n \"generationConfig\": {\n \"maxOutputTokens\": 1024\n }\n}"
response = http.request(request)
puts response.read_body{
"candidates": [
{
"index": 0,
"content": {
"role": "model",
"parts": [
{
"text": "Once upon a time, a magic backpack..."
}
]
},
"finishReason": "STOP"
}
],
"usageMetadata": {
"promptTokenCount": 10,
"candidatesTokenCount": 12,
"totalTokenCount": 22
},
"modelVersion": "gemini-2.0-flash"
}Stream Generate Content
curl --request POST \
--url https://api.tikway.ai/v1beta/models/{model}:streamGenerateContent \
--header 'Content-Type: application/json' \
--header 'x-goog-api-key: <api-key>' \
--data '
{
"systemInstruction": {
"parts": [
{
"text": "You are a helpful assistant."
}
]
},
"contents": [
{
"role": "user",
"parts": [
{
"text": "Write a short bedtime story about a unicorn."
}
]
}
],
"generationConfig": {
"maxOutputTokens": 1024
}
}
'import requests
url = "https://api.tikway.ai/v1beta/models/{model}:streamGenerateContent"
payload = {
"systemInstruction": { "parts": [{ "text": "You are a helpful assistant." }] },
"contents": [
{
"role": "user",
"parts": [{ "text": "Write a short bedtime story about a unicorn." }]
}
],
"generationConfig": { "maxOutputTokens": 1024 }
}
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({
systemInstruction: {parts: [{text: 'You are a helpful assistant.'}]},
contents: [
{role: 'user', parts: [{text: 'Write a short bedtime story about a unicorn.'}]}
],
generationConfig: {maxOutputTokens: 1024}
})
};
fetch('https://api.tikway.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.tikway.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([
'systemInstruction' => [
'parts' => [
[
'text' => 'You are a helpful assistant.'
]
]
],
'contents' => [
[
'role' => 'user',
'parts' => [
[
'text' => 'Write a short bedtime story about a unicorn.'
]
]
]
],
'generationConfig' => [
'maxOutputTokens' => 1024
]
]),
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.tikway.ai/v1beta/models/{model}:streamGenerateContent"
payload := strings.NewReader("{\n \"systemInstruction\": {\n \"parts\": [\n {\n \"text\": \"You are a helpful assistant.\"\n }\n ]\n },\n \"contents\": [\n {\n \"role\": \"user\",\n \"parts\": [\n {\n \"text\": \"Write a short bedtime story about a unicorn.\"\n }\n ]\n }\n ],\n \"generationConfig\": {\n \"maxOutputTokens\": 1024\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.tikway.ai/v1beta/models/{model}:streamGenerateContent")
.header("x-goog-api-key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"systemInstruction\": {\n \"parts\": [\n {\n \"text\": \"You are a helpful assistant.\"\n }\n ]\n },\n \"contents\": [\n {\n \"role\": \"user\",\n \"parts\": [\n {\n \"text\": \"Write a short bedtime story about a unicorn.\"\n }\n ]\n }\n ],\n \"generationConfig\": {\n \"maxOutputTokens\": 1024\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.tikway.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 \"systemInstruction\": {\n \"parts\": [\n {\n \"text\": \"You are a helpful assistant.\"\n }\n ]\n },\n \"contents\": [\n {\n \"role\": \"user\",\n \"parts\": [\n {\n \"text\": \"Write a short bedtime story about a unicorn.\"\n }\n ]\n }\n ],\n \"generationConfig\": {\n \"maxOutputTokens\": 1024\n }\n}"
response = http.request(request)
puts response.read_body{
"candidates": [
{
"index": 0,
"content": {
"role": "model",
"parts": [
{
"text": "Once upon a time, a magic backpack..."
}
]
},
"finishReason": "STOP"
}
],
"usageMetadata": {
"promptTokenCount": 10,
"candidatesTokenCount": 12,
"totalTokenCount": 22
},
"modelVersion": "gemini-2.0-flash"
}授权
Tikway API Key。按 Gemini 原生协议通过 x-goog-api-key 请求头传递。
路径参数
请求体
当前对话内容。单轮请求通常只有一个 Content;多轮对话按顺序包含历史与最新请求。
1Hide child attributes
Hide child attributes
内容部分列表。
1Hide child attributes
Hide child attributes
文本输入。
该部分是否属于模型思考内容。
思考内容签名;回传时保持原样。
内容角色。省略时通常视为 user。
user, model 模型可使用的工具列表,例如函数调用或代码执行。
Hide child attributes
Hide child attributes
启用代码执行工具。
启用 Google 搜索工具。
启用 URL 上下文工具。
安全过滤规则;同一类别最多配置一次,覆盖该类别的默认阈值。
Hide child attributes
Hide child attributes
生成与输出配置。
Hide child attributes
Hide child attributes
采样温度。
核采样阈值。
每步保留的最高概率候选数。
返回候选回复数量。
x >= 1最大输出词元数。
停止序列。
输出 MIME 类型。
text/plain, application/json application/json 输出应遵循的 JSON Schema。
JSON 输出的原始 JSON Schema。
请求的输出模态。
TEXT, IMAGE, AUDIO 媒体输入解析度设置。
作为上下文使用的缓存内容名称,格式为 cachedContents/{cachedContent}。
请求服务层级。
是否记录本请求;若设置,会覆盖项目级日志配置。
响应
Gemini API:models.generateContent 普通响应。完全内联,适合导入 Apifox。
模型生成的候选回复列表。
Hide child attributes
Hide child attributes
候选回复索引。
候选回复内容。
Hide child attributes
Hide child attributes
角色,固定为 model。
model 回复内容部分。
Hide child attributes
Hide child attributes
生成的文本。
是否为思考内容。
思考签名。
候选回复的结束原因。
结束原因的说明。
引用元数据。
候选回复词元数。
候选回复的平均对数概率。
词元对数概率结果。
URL 上下文元数据。
词元使用统计。
Hide child attributes
Hide child attributes
实际使用的模型版本。
响应唯一 ID。