📚 快速开始
本镜像将 Gemini API 转换为 OpenAI 兼容格式,您可以直接使用 OpenAI SDK 调用。
1️⃣ 获取 API Key
访问 Google AI Studio 免费获取 Gemini API Key
2️⃣ 调用示例
curl -X POST https://geproxy.pages.dev/v1beta/chat/completions \
-H "Content-Type: application/json" \
-H "X-API-Key: YOUR_GEMINI_API_KEY" \
-d '{
"model": "gemini-pro",
"messages": [
{"role": "user", "content": "Hello!"}
],
"stream": false
}'
3️⃣ Python 示例
import requests
response = requests.post(
"https://geproxy.pages.dev/v1beta/chat/completions",
headers={
"Content-Type": "application/json",
"X-API-Key": "YOUR_GEMINI_API_KEY"
},
json={
"model": "gemini-1.5-pro",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Explain quantum computing"}
],
"temperature": 0.7,
"max_tokens": 500
}
)
print(response.json()["choices"][0]["message"]["content"])
4️⃣ JavaScript/Node.js 示例
const response = await fetch("https://geproxy.pages.dev/v1beta/chat/completions", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-Key": "YOUR_GEMINI_API_KEY"
},
body: JSON.stringify({
model: "gemini-pro",
messages: [
{ role: "user", content: "Hello!" }
],
stream: false
})
});
const data = await response.json();
console.log(data.choices[0].message.content);
⚙️ 请求参数
| 参数 | 类型 | 说明 |
|---|---|---|
model | string | 模型名称(支持所有 Google 模型,如 gemini-pro, gemini-1.5-pro 等) |
messages | array | 消息列表,支持 system/user/assistant 角色 |
stream | boolean | 是否启用流式响应(默认 false) |
temperature | float | 温度参数 (0-1),控制随机性 |
max_tokens | int | 最大输出 token 数(默认 2048) |
top_p | float | 核采样参数(默认 0.95) |
🛡️ 限流规则
每个 IP 每分钟最多 60 次请求,防止滥用。使用自己的 API Key,不限制总用量。
💡 提示:本服务仅做代理转发,不会存储您的 API Key,所有费用由您的 Google 账号承担。
⚠️ 注意:请妥善保管您的 API Key,不要在客户端代码中暴露。
🎮 在线演示
输入你的 Gemini API Key 试试看:
📖 支持的模型
gemini-pro- Gemini 1.0 Progemini-1.5-pro- Gemini 1.5 Progemini-1.5-flash- Gemini 1.5 Flash(快速版)gemini-1.5-pro-exp-0801- 实验版- 以及其他 Google 支持的模型...
🔧 QQ机器人集成示例
# nonebot2 / yiri 等框架中使用
import httpx
async def call_gemini(user_message: str, api_key: str):
async with httpx.AsyncClient() as client:
resp = await client.post(
"https://geproxy.pages.dev/v1beta/chat/completions",
headers={"X-API-Key": api_key},
json={
"model": "gemini-pro",
"messages": [{"role": "user", "content": user_message}]
}
)
return resp.json()["choices"][0]["message"]["content"]