生成内容
curl --request POST \
--url https://geekai.co/api/v1beta/models/{model}:generateContent \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"contents": [
{
"role": "user",
"parts": [
{
"text": "你好,请介绍一下自己。"
}
]
}
]
}
'import requests
url = "https://geekai.co/api/v1beta/models/{model}:generateContent"
payload = { "contents": [
{
"role": "user",
"parts": [{ "text": "你好,请介绍一下自己。" }]
}
] }
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: '你好,请介绍一下自己。'}]}]})
};
fetch('https://geekai.co/api/v1beta/models/{model}:generateContent', 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://geekai.co/api/v1beta/models/{model}:generateContent",
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' => '你好,请介绍一下自己。'
]
]
]
]
]),
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://geekai.co/api/v1beta/models/{model}:generateContent"
payload := strings.NewReader("{\n \"contents\": [\n {\n \"role\": \"user\",\n \"parts\": [\n {\n \"text\": \"你好,请介绍一下自己。\"\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://geekai.co/api/v1beta/models/{model}:generateContent")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"contents\": [\n {\n \"role\": \"user\",\n \"parts\": [\n {\n \"text\": \"你好,请介绍一下自己。\"\n }\n ]\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://geekai.co/api/v1beta/models/{model}:generateContent")
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\": \"你好,请介绍一下自己。\"\n }\n ]\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"candidates": [
{
"content": {
"role": "model",
"parts": [
{
"text": "你好!我是 Gemini,很高兴为你提供帮助。"
}
]
},
"finishReason": "STOP",
"index": 0
}
],
"usageMetadata": {
"promptTokenCount": 10,
"candidatesTokenCount": 16,
"totalTokenCount": 26
}
}{
"error": {
"code": 123,
"message": "<string>",
"status": "<string>",
"details": [
{}
]
}
}文本模型
生成内容
POST
/
models
/
{model}
:generateContent
生成内容
curl --request POST \
--url https://geekai.co/api/v1beta/models/{model}:generateContent \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"contents": [
{
"role": "user",
"parts": [
{
"text": "你好,请介绍一下自己。"
}
]
}
]
}
'import requests
url = "https://geekai.co/api/v1beta/models/{model}:generateContent"
payload = { "contents": [
{
"role": "user",
"parts": [{ "text": "你好,请介绍一下自己。" }]
}
] }
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: '你好,请介绍一下自己。'}]}]})
};
fetch('https://geekai.co/api/v1beta/models/{model}:generateContent', 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://geekai.co/api/v1beta/models/{model}:generateContent",
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' => '你好,请介绍一下自己。'
]
]
]
]
]),
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://geekai.co/api/v1beta/models/{model}:generateContent"
payload := strings.NewReader("{\n \"contents\": [\n {\n \"role\": \"user\",\n \"parts\": [\n {\n \"text\": \"你好,请介绍一下自己。\"\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://geekai.co/api/v1beta/models/{model}:generateContent")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"contents\": [\n {\n \"role\": \"user\",\n \"parts\": [\n {\n \"text\": \"你好,请介绍一下自己。\"\n }\n ]\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://geekai.co/api/v1beta/models/{model}:generateContent")
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\": \"你好,请介绍一下自己。\"\n }\n ]\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"candidates": [
{
"content": {
"role": "model",
"parts": [
{
"text": "你好!我是 Gemini,很高兴为你提供帮助。"
}
]
},
"finishReason": "STOP",
"index": 0
}
],
"usageMetadata": {
"promptTokenCount": 10,
"candidatesTokenCount": 16,
"totalTokenCount": 26
}
}{
"error": {
"code": 123,
"message": "<string>",
"status": "<string>",
"details": [
{}
]
}
}Gemini GenerateContent API 用于生成模型回复,支持多轮对话、多模态内容和工具调用;具体功能取决于模型和代理渠道。
调用时使用国内入口
https://geekai.co/api/v1beta/models/{model}:generateContent,并在 x-goog-api-key 请求头中填写极客智坊 API KEY。将 {model} 替换为模型 ID;该兼容接口目前仅支持 Gemini 系列模型。
请求和响应格式参考 Gemini 官方接口文档。关于 SDK 的配置和调用示例,请参阅 Gemini 兼容。部分功能和参数的支持情况以所选模型及渠道为准。
需要逐步接收生成结果时,请使用流式生成内容接口。请求体
application/json
响应
生成结果。请求被安全策略拦截时,可能没有 candidates,请查看 promptFeedback。
此页面对您有帮助吗?
