cURL
curl --request POST \
--url https://api.ttapi.io/gemini/chat/completions \
--header 'Content-Type: application/json' \
--header 'TT-API-KEY: <api-key>' \
--data '
{
"messages": [
{
"role": "user",
"content": "Hello!"
}
],
"model": "<string>",
"stream": "false"
}
'import requests
url = "https://api.ttapi.io/gemini/chat/completions"
payload = {
"messages": [
{
"role": "user",
"content": "Hello!"
}
],
"model": "<string>",
"stream": "false"
}
headers = {
"TT-API-KEY": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'TT-API-KEY': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
messages: [{role: 'user', content: 'Hello!'}],
model: '<string>',
stream: 'false'
})
};
fetch('https://api.ttapi.io/gemini/chat/completions', 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.ttapi.io/gemini/chat/completions",
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([
'messages' => [
[
'role' => 'user',
'content' => 'Hello!'
]
],
'model' => '<string>',
'stream' => 'false'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"TT-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.ttapi.io/gemini/chat/completions"
payload := strings.NewReader("{\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"Hello!\"\n }\n ],\n \"model\": \"<string>\",\n \"stream\": \"false\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("TT-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.ttapi.io/gemini/chat/completions")
.header("TT-API-KEY", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"Hello!\"\n }\n ],\n \"model\": \"<string>\",\n \"stream\": \"false\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.ttapi.io/gemini/chat/completions")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["TT-API-KEY"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"Hello!\"\n }\n ],\n \"model\": \"<string>\",\n \"stream\": \"false\"\n}"
response = http.request(request)
puts response.read_body{
"choices": [
{
"finish_reason": "stop",
"index": 0,
"message": {
"content": "你好!很高兴和你聊天。\n\n有什么可以帮你的吗?或者想聊点什么? 😊",
"role": "assistant"
}
}
],
"created": 1757472417,
"id": "oebAaMTvMfCUjMcP_prYwAs",
"model": "gemini-2.5-pro",
"object": "chat.completion",
"usage": {
"completion_tokens": 21,
"prompt_tokens": 3,
"total_tokens": 1466
}
}{
"status": "FAILED",
"message": "\"prompt\" cannot be empty.",
"data": {}
}{
"status": "FAILED",
"message": "Wrong TT-API-KEY or email is not activated."
}Google
Completions
POST
/
gemini
/
chat
/
completions
cURL
curl --request POST \
--url https://api.ttapi.io/gemini/chat/completions \
--header 'Content-Type: application/json' \
--header 'TT-API-KEY: <api-key>' \
--data '
{
"messages": [
{
"role": "user",
"content": "Hello!"
}
],
"model": "<string>",
"stream": "false"
}
'import requests
url = "https://api.ttapi.io/gemini/chat/completions"
payload = {
"messages": [
{
"role": "user",
"content": "Hello!"
}
],
"model": "<string>",
"stream": "false"
}
headers = {
"TT-API-KEY": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'TT-API-KEY': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
messages: [{role: 'user', content: 'Hello!'}],
model: '<string>',
stream: 'false'
})
};
fetch('https://api.ttapi.io/gemini/chat/completions', 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.ttapi.io/gemini/chat/completions",
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([
'messages' => [
[
'role' => 'user',
'content' => 'Hello!'
]
],
'model' => '<string>',
'stream' => 'false'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"TT-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.ttapi.io/gemini/chat/completions"
payload := strings.NewReader("{\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"Hello!\"\n }\n ],\n \"model\": \"<string>\",\n \"stream\": \"false\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("TT-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.ttapi.io/gemini/chat/completions")
.header("TT-API-KEY", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"Hello!\"\n }\n ],\n \"model\": \"<string>\",\n \"stream\": \"false\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.ttapi.io/gemini/chat/completions")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["TT-API-KEY"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"Hello!\"\n }\n ],\n \"model\": \"<string>\",\n \"stream\": \"false\"\n}"
response = http.request(request)
puts response.read_body{
"choices": [
{
"finish_reason": "stop",
"index": 0,
"message": {
"content": "你好!很高兴和你聊天。\n\n有什么可以帮你的吗?或者想聊点什么? 😊",
"role": "assistant"
}
}
],
"created": 1757472417,
"id": "oebAaMTvMfCUjMcP_prYwAs",
"model": "gemini-2.5-pro",
"object": "chat.completion",
"usage": {
"completion_tokens": 21,
"prompt_tokens": 3,
"total_tokens": 1466
}
}{
"status": "FAILED",
"message": "\"prompt\" cannot be empty.",
"data": {}
}{
"status": "FAILED",
"message": "Wrong TT-API-KEY or email is not activated."
}请求参数及响应参数与官方一致,
具体参考Google官方文档。
请求体
application/json
Show child attributes
Show child attributes
示例:
[{ "role": "user", "content": "Hello!" }]
TTAPI 支持使用的模型,详见Gemini支持模型
是否使用服务器发送的事件逐步传输响应
响应
成功响应(stream=false 返回JSON,stream=true 返回Gemini流式)
最后修改于 2026年7月15日
⌘I