Gemini 原生格式
curl --request POST \
--url https://api.poyo.ai:{method}/v1beta/models/{model}:62437 \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data @- <<EOF
{
"contents": [
{
"role": "user",
"parts": [
{
"text": "Summarize the 'new night mode' requirements in 3 points and provide next steps."
}
]
}
]
}
EOFimport requests
url = "https://api.poyo.ai:{method}/v1beta/models/{model}:62437"
payload = { "contents": [
{
"role": "user",
"parts": [{ "text": "Summarize the 'new night mode' requirements in 3 points and provide next steps." }]
}
] }
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: 'Summarize the \'new night mode\' requirements in 3 points and provide next steps.'
}
]
}
]
})
};
fetch('https://api.poyo.ai:{method}/v1beta/models/{model}:62437', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_PORT => "62437",
CURLOPT_URL => "https://api.poyo.ai:{method}/v1beta/models/{model}:62437",
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' => 'user',
'parts' => [
[
'text' => 'Summarize the \'new night mode\' requirements in 3 points and provide next steps.'
]
]
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$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.poyo.ai:{method}/v1beta/models/{model}:62437"
payload := strings.NewReader("{\n \"contents\": [\n {\n \"role\": \"user\",\n \"parts\": [\n {\n \"text\": \"Summarize the 'new night mode' requirements in 3 points and provide next steps.\"\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))
}HttpResponse<String> response = Unirest.post("https://api.poyo.ai:{method}/v1beta/models/{model}:62437")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"contents\": [\n {\n \"role\": \"user\",\n \"parts\": [\n {\n \"text\": \"Summarize the 'new night mode' requirements in 3 points and provide next steps.\"\n }\n ]\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.poyo.ai:{method}/v1beta/models/{model}:62437")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"contents\": [\n {\n \"role\": \"user\",\n \"parts\": [\n {\n \"text\": \"Summarize the 'new night mode' requirements in 3 points and provide next steps.\"\n }\n ]\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"candidates": [
{
"content": {
"role": "model",
"parts": [
{
"text": "Hello! I'm pleased to introduce myself."
}
]
},
"finishReason": "STOP",
"index": 0
}
],
"promptFeedback": {
"safetyRatings": [
{
"category": "HARM_CATEGORY_HATE_SPEECH",
"probability": "NEGLIGIBLE"
},
{
"category": "HARM_CATEGORY_DANGEROUS_CONTENT",
"probability": "NEGLIGIBLE"
},
{
"category": "HARM_CATEGORY_HARASSMENT",
"probability": "NEGLIGIBLE"
},
{
"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
"probability": "NEGLIGIBLE"
}
]
},
"usageMetadata": {
"promptTokenCount": 15,
"candidatesTokenCount": 29,
"totalTokenCount": 44,
"thoughtsTokenCount": 0,
"promptTokensDetails": [
{
"modality": "TEXT",
"tokenCount": 15
}
]
}
}{
"error": {
"code": 400,
"message": "URI '/v1beta/models/deepseek-v4-flash:generateContent' is not supported by this model. Supported URIs: ['/v1/chat/completions']",
"status": "INVALID_ARGUMENT"
}
}{
"code": 401,
"error": {
"message": "Invalid API key",
"type": "authentication_error"
}
}{
"error": {
"message": "Model not found: no-such-model",
"type": "invalid_request_error",
"code": "model_not_found"
}
}API 格式
Gemini Native
Gemini 原生格式 API 调用 generateContent 和 streamGenerateContent。请求使用 contents 和 parts,可包含文本和内联图像数据。
POST
/
v1beta
/
models
/
{model}
:
{method}
Gemini 原生格式
curl --request POST \
--url https://api.poyo.ai:{method}/v1beta/models/{model}:62437 \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data @- <<EOF
{
"contents": [
{
"role": "user",
"parts": [
{
"text": "Summarize the 'new night mode' requirements in 3 points and provide next steps."
}
]
}
]
}
EOFimport requests
url = "https://api.poyo.ai:{method}/v1beta/models/{model}:62437"
payload = { "contents": [
{
"role": "user",
"parts": [{ "text": "Summarize the 'new night mode' requirements in 3 points and provide next steps." }]
}
] }
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: 'Summarize the \'new night mode\' requirements in 3 points and provide next steps.'
}
]
}
]
})
};
fetch('https://api.poyo.ai:{method}/v1beta/models/{model}:62437', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_PORT => "62437",
CURLOPT_URL => "https://api.poyo.ai:{method}/v1beta/models/{model}:62437",
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' => 'user',
'parts' => [
[
'text' => 'Summarize the \'new night mode\' requirements in 3 points and provide next steps.'
]
]
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$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.poyo.ai:{method}/v1beta/models/{model}:62437"
payload := strings.NewReader("{\n \"contents\": [\n {\n \"role\": \"user\",\n \"parts\": [\n {\n \"text\": \"Summarize the 'new night mode' requirements in 3 points and provide next steps.\"\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))
}HttpResponse<String> response = Unirest.post("https://api.poyo.ai:{method}/v1beta/models/{model}:62437")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"contents\": [\n {\n \"role\": \"user\",\n \"parts\": [\n {\n \"text\": \"Summarize the 'new night mode' requirements in 3 points and provide next steps.\"\n }\n ]\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.poyo.ai:{method}/v1beta/models/{model}:62437")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"contents\": [\n {\n \"role\": \"user\",\n \"parts\": [\n {\n \"text\": \"Summarize the 'new night mode' requirements in 3 points and provide next steps.\"\n }\n ]\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"candidates": [
{
"content": {
"role": "model",
"parts": [
{
"text": "Hello! I'm pleased to introduce myself."
}
]
},
"finishReason": "STOP",
"index": 0
}
],
"promptFeedback": {
"safetyRatings": [
{
"category": "HARM_CATEGORY_HATE_SPEECH",
"probability": "NEGLIGIBLE"
},
{
"category": "HARM_CATEGORY_DANGEROUS_CONTENT",
"probability": "NEGLIGIBLE"
},
{
"category": "HARM_CATEGORY_HARASSMENT",
"probability": "NEGLIGIBLE"
},
{
"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
"probability": "NEGLIGIBLE"
}
]
},
"usageMetadata": {
"promptTokenCount": 15,
"candidatesTokenCount": 29,
"totalTokenCount": 44,
"thoughtsTokenCount": 0,
"promptTokensDetails": [
{
"modality": "TEXT",
"tokenCount": 15
}
]
}
}{
"error": {
"code": 400,
"message": "URI '/v1beta/models/deepseek-v4-flash:generateContent' is not supported by this model. Supported URIs: ['/v1/chat/completions']",
"status": "INVALID_ARGUMENT"
}
}{
"code": 401,
"error": {
"message": "Invalid API key",
"type": "authentication_error"
}
}{
"error": {
"message": "Model not found: no-such-model",
"type": "invalid_request_error",
"code": "model_not_found"
}
}- 使用 Google 原生 API 格式调用 Gemini 模型
- 支持同步和流式两种生成方法
- 参数精简,便于快速上手
使用示例
生成内容
接口:POST /v1beta/models/gemini-3-flash-preview:generateContent
{
"contents": [
{
"role": "user",
"parts": [
{
"text": "Summarize the goals of the new night mode in one sentence."
}
]
}
],
"generationConfig": {
"maxOutputTokens": 256,
"temperature": 0.7
}
}
流式生成内容
接口:POST /v1beta/models/gemini-3-flash-preview:streamGenerateContent
{
"contents": [
{
"role": "user",
"parts": [
{
"text": "Generate 5 short feature names for an AI writing assistant."
}
]
}
],
"generationConfig": {
"maxOutputTokens": 256
}
}
多模态输入
{
"contents": [
{
"role": "user",
"parts": [
{
"text": "Describe the image and write concise alt text."
},
{
"inlineData": {
"mimeType": "image/png",
"data": "BASE64_IMAGE_DATA"
}
}
]
}
]
}
注意事项
- 使用
generateContent获取完整 JSON 响应。 - 使用
streamGenerateContent进行流式生成。 - 尽可能把文本指令放在多模态 part 之前。
响应
generateContent 直接返回 Gemini GenerateContentResponse 对象,不带 code / data 包装。文本位于 candidates[].content.parts[].text,token 计数位于 usageMetadata。思考模型可能会添加带 thought: true 或 thoughtSignature 的 part;跳过没有 text 的 part 即可。
流式输出
streamGenerateContent 返回 text/event-stream。每个事件是一行包含部分 GenerateContentResponse 的 data:,流以 data: [DONE] 结束。接受 alt=sse 查询参数,但不是必需的。
data: {"candidates":[{"content":{"parts":[{"thought":true}],"role":"model"}}],"usageMetadata":{"promptTokenCount":260,...}}
data: {"candidates":[{"content":{"parts":[{"text":"OK."}],"role":"model"}}],"usageMetadata":{"candidatesTokenCount":2,...}}
data: {"candidates":[{"content":{"parts":[{"thoughtSignature":"..."}],"role":"model"},"finishReason":"STOP"}],"usageMetadata":{...}}
data: [DONE]
- 按顺序拼接各个
textpart。最后一个事件携带finishReason。
错误
401:缺少 API Key 或 API Key 无效。400:请求无效,或模型不是 Gemini 模型。响应体使用 Google 错误结构:{"error": {"code": 400, "message": "...", "status": "INVALID_ARGUMENT"}}。404:未知的 model id。
授权
所有 API 接口都需要 Bearer Token 认证。
创建 API Key:登录 PoYo,进入 仪表盘 → API 密钥(poyo.ai/zh/dashboard/api-key),点击创建 Key。
在请求头中添加:
Authorization: Bearer YOUR_API_KEY
路径参数
Gemini 模型名称。示例:gemini-3-flash-preview。
示例:
"gemini-3-flash-preview"
请求方法。generateContent 返回完整 JSON 响应,streamGenerateContent 用于流式生成。
可用选项:
generateContent, streamGenerateContent 示例:
"generateContent"
请求体
application/json