API 文档
将 AI 图片生成集成到你的应用中
概述
GirlGeneratorAI API 允许你以编程方式生成 AI 图片。所有请求使用 JSON 格式,需要通过 API Key 进行认证。
Base URL
https://girlgenerator.app认证
所有 API 请求需要 Bearer token。请在以下页面创建 API Key: 设置 → API Keys.
请求头
Authorization: Bearer YOUR_API_KEY生成图片
提交图片生成任务。响应包含用于轮询的任务 ID。
POST /api/v1/generate
参数
scenestringrequired"text-to-image" 或 "image-to-image"
promptstringrequired描述图片的文本提示词(最多 2000 字符)
aspect_ratiostring可选。可选值:auto, 1:1, 3:2, 2:3, 9:16, 16:9, 3:4, 4:3。默认:auto
image_inputstring[]image-to-image 模式必填。参考图片 URL 数组
响应
201 Created
{
"task_id": "abc123",
"status": "pending",
"credits_used": 1,
"credits_remaining": 12762
}示例
cURL
curl -X POST https://girlgenerator.app/api/v1/generate \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"scene": "text-to-image",
"prompt": "a cute anime girl with blue hair, detailed portrait",
"aspect_ratio": "1:1"
}'Python
import requests
response = requests.post(
"https://girlgenerator.app/api/v1/generate",
headers={"Authorization": "Bearer YOUR_API_KEY"},
json={
"scene": "text-to-image",
"prompt": "a cute anime girl with blue hair, detailed portrait",
"aspect_ratio": "1:1",
},
)
data = response.json()
print(data["task_id"]) # Use this to poll for resultsJavaScript (fetch)
const response = await fetch("https://girlgenerator.app/api/v1/generate", {
method: "POST",
headers: {
"Authorization": "Bearer YOUR_API_KEY",
"Content-Type": "application/json",
},
body: JSON.stringify({
scene: "text-to-image",
prompt: "a cute anime girl with blue hair, detailed portrait",
aspect_ratio: "1:1",
}),
});
const data = await response.json();
console.log(data.task_id); // Use this to poll for results查询任务
轮询任务以检查状态并获取生成的图片。
GET /api/v1/tasks/task_id
响应
Pending / Processing
{
"task_id": "abc123",
"status": "processing"
}Success
{
"task_id": "abc123",
"status": "success",
"images": [
"https://example.com/generated-image.png"
]
}Failed
{
"task_id": "abc123",
"status": "failed",
"error": "Generation failed due to content policy."
}状态值
pending任务排队中processing图片生成中success生成完成,可获取图片failed生成失败,包含错误信息Polling Example
Python
import time
import requests
API_KEY = "YOUR_API_KEY"
BASE_URL = "https://girlgenerator.app"
# 1. Submit generation task
resp = requests.post(
f"{BASE_URL}/api/v1/generate",
headers={"Authorization": f"Bearer {API_KEY}"},
json={"scene": "text-to-image", "prompt": "a cute anime girl"},
)
task_id = resp.json()["task_id"]
# 2. Poll until complete
while True:
result = requests.get(
f"{BASE_URL}/api/v1/tasks/{task_id}",
headers={"Authorization": f"Bearer {API_KEY}"},
).json()
if result["status"] == "success":
print("Images:", result["images"])
break
elif result["status"] == "failed":
print("Error:", result["error"])
break
time.sleep(5) # Wait 5 seconds before polling again错误码
所有错误遵循以下格式:
{
"error": {
"code": "error_code",
"message": "Human-readable description."
}
}| HTTP 状态码 | 错误码 | 说明 |
|---|---|---|
| 401 | unauthorized | 缺少或无效的 API Key |
| 403 | insufficient_credits | Credits 不足 |
| 404 | task_not_found | 任务不存在或属于其他用户 |
| 422 | invalid_params | 请求参数校验失败 |
| 429 | rate_limit_exceeded | 请求过于频繁(限制:10次/分钟) |
| 500 | internal_error | 服务器错误 |
速率限制与 Credits
⚡
每个 API Key 每分钟 10 次请求
💰
每次生成消耗的积分因模型不同而异,范围为 1-3 积分。详见模型列表。
🛈
API 和网页端共享同一 Credits 余额。