基于 Google Gemini 的 AI 图片生成接口 · 最后更新: 2026-02-24
所有接口需要鉴权,二选一:
// 方式1: Header Authorization: Bearer gemini_2026 // 方式2: URL参数 ?key=gemini_2026
根据文字描述生成图片,支持中英文提示词。通常耗时 10-30 秒。
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
prompt | string | 必填 | 图片描述,中英文均可 |
return_base64 | boolean | 可选 | 是否在返回中包含 base64 数据,默认 false |
{
"prompt": "一只戴墨镜的橘猫在海滩冲浪,数字艺术风格"
}{
"success": true,
"count": 1,
"text": null,
"images": [
{
"index": 0,
"path": "output/2026-02-21/gen_1234567_0/xxx.png",
"url": "/images/2026-02-21/gen_1234567_0/xxx.png",
"base64": "...(仅 return_base64=true 时存在)",
"mime_type": "image/png"
}
]
}查看/下载图片:拼接域名 + url 字段,如:
http://gemini.666douyin.cn/images/2026-02-21/gen_xxx/xxx.png
curl -X POST http://gemini.666douyin.cn/api/generate \
-H "Authorization: Bearer gemini_2026" \
-H "Content-Type: application/json" \
-d '{"prompt":"a cute cat wearing sunglasses, digital art"}'import requests
resp = requests.post(
"http://gemini.666douyin.cn/api/generate",
headers={"Authorization": "Bearer gemini_2026"},
json={"prompt": "一只可爱的猫咪"},
timeout=60 # 重要:设置足够长的超时!
)
data = resp.json()
if data["success"]:
img_url = "http://gemini.666douyin.cn" + data["images"][0]["url"]
print("图片地址:", img_url)const resp = await fetch("http://gemini.666douyin.cn/api/generate", {
method: "POST",
headers: {
"Authorization": "Bearer gemini_2026",
"Content-Type": "application/json"
},
body: JSON.stringify({ prompt: "a cute cat" })
});
const data = await resp.json();
if (data.success) {
const imgUrl = "http://gemini.666douyin.cn" + data.images[0].url;
console.log("图片地址:", imgUrl);
}对已有图片进行 AI 编辑修改。
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
prompt | string | 必填 | 编辑描述,如"给人物加上墨镜"、"把背景换成星空" |
image_url | string | 三选一 | 本服务生成的图片路径,如 /images/2026-02-21/gen_xxx/xxx.png |
image_base64 | string | 图片的 base64 编码数据(适合上传外部图片) | |
image_path | string | 服务器上的本地文件绝对路径 |
# Python 图生图示例
import requests, base64
with open("my_photo.jpg", "rb") as f:
img_b64 = base64.b64encode(f.read()).decode()
resp = requests.post("http://gemini.666douyin.cn/api/edit",
headers={"Authorization": "Bearer gemini_2026"},
json={"prompt": "改成赛博朋克风格", "image_base64": img_b64},
timeout=90)
print(resp.json()){
"prompt": "把背景换成星空",
"image_url": "/images/2026-02-21/gen_1234567_0/xxx.png"
}同文生图接口,返回编辑后的新图片。
当 Google Cookie 过期时,调用此接口热更新,无需重启服务。
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
psid | string | 必填 | Google __Secure-1PSID cookie 值 |
psidts | string | 可选 | Google __Secure-1PSIDTS cookie 值 |
{"success": true, "message": "Cookie updated and verified"}查询服务运行状态和 Cookie 是否有效。
{
"status": "running",
"has_cookie": true,
"cookie_prefix": "g.a0007Ah...",
"client_initialized": true
}直接访问生成的图片文件。可用于 <img> 标签、浏览器打开或下载。
无需鉴权。
success: false。
/api/cookie 更新即可。
| HTTP状态码 | 含义 | 处理方式 |
|---|---|---|
| 200 | 成功(检查 success 字段) | - |
| 400 | 参数错误 | 检查请求体格式和必填字段 |
| 401 | 鉴权失败或Cookie过期 | 检查 API Key 或更新 Cookie |
| 404 | 图片不存在 | 检查 image_url 路径 |
| 500 | 服务器内部错误 | 查看返回的 error 字段 |