https://api.eggapi.ai
1. 获取 API Key
登录 eggapi.ai,进入 dashboard 创建 API Key。公开 API 只接受Authorization 请求头中的 API Key:
Authorization: Bearer YOUR_API_KEY
2. 提交任务
当前文档列出的公开生成模型都是异步模型。POST /v1/generate 会返回 202 Accepted 和一个任务对象。
curl -X POST https://api.eggapi.ai/v1/generate \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "nanobanana",
"prompt": "A cinematic product photo of a matte green travel mug",
"aspect_ratio": "16:9",
"num_outputs": 1,
"webhook_url": "https://webhook.site/your-webhook-id"
}'
import requests
response = requests.post(
"https://api.eggapi.ai/v1/generate",
headers={"Authorization": "Bearer YOUR_API_KEY"},
json={
"model": "nanobanana",
"prompt": "A cinematic product photo of a matte green travel mug",
"aspect_ratio": "16:9",
"num_outputs": 1,
"webhook_url": "https://webhook.site/your-webhook-id",
},
)
response.raise_for_status()
task = response.json()["data"]
print(task["id"])
const response = await fetch("https://api.eggapi.ai/v1/generate", {
method: "POST",
headers: {
"Authorization": "Bearer YOUR_API_KEY",
"Content-Type": "application/json"
},
body: JSON.stringify({
model: "nanobanana",
prompt: "A cinematic product photo of a matte green travel mug",
aspect_ratio: "16:9",
num_outputs: 1,
webhook_url: "https://webhook.site/your-webhook-id"
})
});
if (!response.ok) throw new Error(await response.text());
const { data: task } = await response.json();
console.log(task.id);
{
"data": {
"id": "gen_abc123def456",
"status": "pending",
"model": "nanobanana",
"type": "image_generate",
"cost": "$0.00",
"created_at": "2026-05-08T10:30:00Z"
},
"error": null
}
3. 轮询任务
使用响应里的任务 ID 查询状态:curl https://api.eggapi.ai/v1/tasks/gen_abc123def456 \
-H "Authorization: Bearer YOUR_API_KEY"
{
"data": {
"id": "gen_abc123def456",
"status": "completed",
"model": "nanobanana",
"type": "image_generate",
"output": {
"url": "https://file.eggapi.ai/images/gen_abc123def456/0.png",
"urls": ["https://file.eggapi.ai/images/gen_abc123def456/0.png"]
},
"cost": "$0.0100",
"created_at": "2026-05-08T10:30:00Z",
"started_at": "2026-05-08T10:30:01Z",
"completed_at": "2026-05-08T10:30:12Z"
},
"error": null
}
4. 查看用量
用量接口必须使用 API Key:curl https://api.eggapi.ai/v1/usage/summary \
-H "Authorization: Bearer YOUR_API_KEY"
{
"data": [
{
"model": "nanobanana",
"total_units": 1,
"total_cost": "$0.0100",
"request_count": 1
}
],
"error": null
}
下一步
模型
选择模型 ID 和参数。
异步任务
了解轮询、webhook 和重试处理。