AI 服务/大语言模型
Gemini 对话
接口说明:Gemini :generateContent API 的兼容端点(非流式,聚合返回完整结果)。请求与响应格式遵循 Gemini 规范;鉴权使用 x-goog-api-key 头(Gemini SDK 默认携带),已有 Gemini SDK 只需替换 baseURL 与 API Key 即可接入,按 AiToEarn 积分计费。
调用本接口前,请先请求「对话模型列表」接口(GET /api/ai/models/chat),获取当前可用的模型列表。
POST
/
api
/
ai
/
v1beta
/
models
/
{model}
:generateContent
Gemini 对话
curl --request POST \
--url https://aitoearn.cn/api/ai/v1beta/models/{model}:generateContent \
--header 'Content-Type: application/json' \
--header 'x-goog-api-key: <api-key>' \
--data '
{
"model": "gemini-3.5-flash",
"contents": [
{
"role": "user",
"parts": [
{
"text": "请只回复 OK。"
}
]
}
]
}
'import requests
url = "https://aitoearn.cn/api/ai/v1beta/models/{model}:generateContent"
payload = {
"model": "gemini-3.5-flash",
"contents": [
{
"role": "user",
"parts": [{ "text": "请只回复 OK。" }]
}
]
}
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({
model: 'gemini-3.5-flash',
contents: [{role: 'user', parts: [{text: '请只回复 OK。'}]}]
})
};
fetch('https://aitoearn.cn/api/ai/v1beta/models/{model}:generateContent', 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://aitoearn.cn/api/ai/v1beta/models/{model}:generateContent"
payload := strings.NewReader("{\n \"model\": \"gemini-3.5-flash\",\n \"contents\": [\n {\n \"role\": \"user\",\n \"parts\": [\n {\n \"text\": \"请只回复 OK。\"\n }\n ]\n }\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))
}{
"candidates": [
{
"content": {
"role": "string",
"parts": [
{
"text": "string"
}
]
},
"index": "integer"
}
],
"modelVersion": "string",
"sdkHttpResponse": {
"headers": "object"
},
"usageMetadata": {
"promptTokenCount": "integer",
"candidatesTokenCount": "integer",
"totalTokenCount": "integer"
}
}⌘I
Gemini 对话
curl --request POST \
--url https://aitoearn.cn/api/ai/v1beta/models/{model}:generateContent \
--header 'Content-Type: application/json' \
--header 'x-goog-api-key: <api-key>' \
--data '
{
"model": "gemini-3.5-flash",
"contents": [
{
"role": "user",
"parts": [
{
"text": "请只回复 OK。"
}
]
}
]
}
'import requests
url = "https://aitoearn.cn/api/ai/v1beta/models/{model}:generateContent"
payload = {
"model": "gemini-3.5-flash",
"contents": [
{
"role": "user",
"parts": [{ "text": "请只回复 OK。" }]
}
]
}
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({
model: 'gemini-3.5-flash',
contents: [{role: 'user', parts: [{text: '请只回复 OK。'}]}]
})
};
fetch('https://aitoearn.cn/api/ai/v1beta/models/{model}:generateContent', 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://aitoearn.cn/api/ai/v1beta/models/{model}:generateContent"
payload := strings.NewReader("{\n \"model\": \"gemini-3.5-flash\",\n \"contents\": [\n {\n \"role\": \"user\",\n \"parts\": [\n {\n \"text\": \"请只回复 OK。\"\n }\n ]\n }\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))
}{
"candidates": [
{
"content": {
"role": "string",
"parts": [
{
"text": "string"
}
]
},
"index": "integer"
}
],
"modelVersion": "string",
"sdkHttpResponse": {
"headers": "object"
},
"usageMetadata": {
"promptTokenCount": "integer",
"candidatesTokenCount": "integer",
"totalTokenCount": "integer"
}
}
