Gemini 兼容接口

使用 Gemini API 协议的客户端可以把 base URL 指向 https://inferstream.cn/gemini,路径保持 /v1beta/models/<模型名>:generateContent(流式用 :streamGenerateContent),Key 放在 x-goog-api-key 头里,也接受 ?key= 查询参数。模型名同样是模型库里的裸名,不限于 Gemini 系列。

请求

POST /gemini/v1beta/models/…:generateContent
curl "https://inferstream.cn/gemini/v1beta/models/gemini-2.5-flash:generateContent" \
  -H "x-goog-api-key: $INFERSTREAM_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [{"parts": [{"text": "用一句话介绍杭州。"}]}]
  }'

GET /gemini/v1beta/models 返回 Gemini 格式的模型列表。错误码含义与其他接口一致,见错误码与限流。

google-genai SDK

Python(google-genai SDK,需自行验证)
from google import genai
from google.genai import types

client = genai.Client(
    api_key="sk-...",
    http_options=types.HttpOptions(base_url="https://inferstream.cn/gemini"),
)
response = client.models.generate_content(
    model="gemini-2.5-flash",
    contents="用一句话介绍杭州。",
)
print(response.text)
注意

未逐版本验证:google-genai 通过 http_options.base_url 改地址,SDK 自己拼接 /v1beta/models/…;此写法未在本站逐版本验证,若 SDK 版本不同请对照其文档调整。curl 路径是确定的。