跳转至

Gemini(Google 原生格式)

端点 /v1beta/... · 原样转发至 Google 官方

用 Google 原生格式调用 Gemini。请求体、响应体、流式、多轮托管、Google 搜索都与直连 Google 官方一致——直接用官方 @google/genai SDK,改 http_options.base_url 即可。常用模型:gemini-3-pro-proview

端点 说明
POST /v1beta/interactions Interactions API(推荐),服务端托管历史
POST /v1beta/models/{model}:generateContent 经典单次生成
POST /v1beta/models/{model}:streamGenerateContent 经典流式

认证差异

Google 官方原用 x-goog-api-key;六哥统一用 Authorization: Bearer。用官方 SDK 时 SDK 会自动处理,你只要把 api_key 设成六哥 Key、base_url 指向六哥。

最小请求与响应

curl -X POST "https://6geapi.com/v1beta/interactions" \
  -H "Authorization: Bearer $LIUGE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "gemini-3-pro-proview", "input": "AI 是怎么工作的?"}'
from google import genai
client = genai.Client(api_key="你的Key",
                      http_options={"base_url": "https://6geapi.com"})
it = client.interactions.create(model="gemini-3-pro-proview", input="AI 是怎么工作的?")
print(it.output_text)
import { GoogleGenAI } from "@google/genai";
const ai = new GoogleGenAI({ apiKey: process.env.LIUGE_API_KEY,
                             httpOptions: { baseUrl: "https://6geapi.com" } });
const it = await ai.interactions.create({ model: "gemini-3-pro-proview", input: "AI 是怎么工作的?" });
console.log(it.output_text);

响应(节选):

{
  "id": "interactions/...",
  "model": "gemini-3-pro-proview",
  "output_text": "AI 通过大量数据训练……",
  "steps": []
}

请求参数(Interactions API)

参数 类型 说明
model string ✅ 如 gemini-3-pro-proview
input string/array ✅ 文本或 part 数组(多模态)
system_instruction string 系统提示,顶级字段
generation_config object temperaturethinking_level
tools array [{"type":"google_search"}]
stream bool 流式
previous_interaction_id string 串联上一轮(多轮)
response_format object/array 输出形态(文本 / 图像、宽高比、分辨率)
store bool false 关闭服务端历史

流式输出

URL 加 ?alt=sse(或 SDK 传 stream:true),按 step.delta 事件增量接收。

stream = client.interactions.create(
    model="gemini-3-pro-proview", input="讲讲 AI 的工作原理", stream=True)
for ev in stream:
    if ev.event_type == "step.delta" and ev.delta.type == "text":
        print(ev.delta.text, end="")

多轮对话

previous_interaction_id 串联,历史服务端托管,无需客户端回传:

i1 = client.interactions.create(model="gemini-3-pro-proview", input="我家有 2 只狗。")
i2 = client.interactions.create(
    model="gemini-3-pro-proview",
    input="那我家里一共有几只爪子?",
    previous_interaction_id=i1.id,
)
print(i2.output_text)   # 它记得「2 只狗」

思考(Thinking)

Gemini 默认开思考;用 generation_config.thinking_level 控制深度,平衡成本 / 延迟。

it = client.interactions.create(
    model="gemini-3-pro-proview",
    input="如何实现一个 LRU 缓存?",
    generation_config={"thinking_level": "low"},
)

经典 generateContent

curl -X POST \
  "https://6geapi.com/v1beta/models/gemini-3-pro-proview:generateContent" \
  -H "Authorization: Bearer $LIUGE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"contents":[{"parts":[{"text":"法国的首都是哪里?"}]}]}'

经典接口无状态、无托管历史,需要自己维护 contents 数组。需要生图则改用图像模型,见 图像生成