跳到主要内容

生成图像

用途​

基于文本提示生成 AI 图像。可选择上传参考图像,以参考生成结果的样式或构图。

方法和路径​

POST /public/v1/generate/image

认证​

请参阅 认证 页面。需要 Bearer 令牌。

必需头信息:

Authorization: Bearer {your_api_key}

请求字段​

字段名类型必需说明
promptstring是图像生成的文本提示
ai_modelstring是使用的 AI 模型。可能的值: GPT Image 1.5, GPT Image 2, GPT Image 2.5 High, GPT Image 2.5 XHigh, GPT Image 2.6 High, GPT Image 2.6 XHigh, Grok Imagine, Grok Imagine Pro, Nano Banana, Nano Banana 2, Nano Banana Pro (deprecated: GPT Image 1.5, Grok Imagine, Grok Imagine Pro, Nano Banana, Nano Banana 2)
ref_imagesfile[]否参考图像文件 (multipart/form-data)。根据 AI 模型不同,最大上传数量不同
aspect_ratiostring否输出图像比例。可选 1:1(默认,正方形)、2:3(竖向)、3:2(横向)。已弃用模型(GPT Image 1.5、Grok Imagine、Grok Imagine Pro)将忽略此项

响应​

成功响应 (200 OK):

{
"job_id": "uuid-string"
}
字段类型说明
job_idstring创建的作业的唯一标识符。使用 Get Job Status 查询结果

错误 / 验证规则​

情况HTTP 状态错误消息
Invalid image file400"Invalid image file"
aspect_ratio 无效422Validation error (aspect_ratio must be one of 1:1, 2:3, 3:2)
Grok Imagine 模型中 ref_images 超过 5 个400"The Grok Imagine model supports up to 5 ref_images."
Grok Imagine Pro 模型中 ref_images 超过 1 个400"The Grok Imagine Pro model supports up to 1 ref_images."
其他模型中 ref_images 超过 10 个400"ref_images supports up to 10 images only"
认证失败401无效的 API 密钥

参考图像限制:

  • GPT Image 1.5: 最多 10 个
  • GPT Image 2 / 2.5 High / 2.5 XHigh: 最多 10 个
  • Grok Imagine: 最多 5 个
  • Grok Imagine Pro: 最多 1 个
  • Nano Banana 系列: 最多 10 个

异步作业行为​

此端点创建异步作业。请求立即返回 job_id,实际图像生成在后台进行。

轮询方法:

  1. 保存响应中收到的 job_id
  2. 轮询 GET /public/v1/job/{job_id} 检查状态
  3. 当状态变为 Succeed 时,从 image_urls 查看结果

状态流程: Pending → Succeed 或 Failed

每次请求还会在网页的历史页面创建一个聊天室,显示在 API/MCP 标签下,你可以在那里查看结果并继续生成。

请求示例​

cURL (无参考图像):

curl -X POST "https://api.aetherforgeai.com/public/v1/generate/image" \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "prompt=a beautiful sunset over mountains" \
-F "ai_model=GPT Image 2.5 High" \
-F "aspect_ratio=3:2"

cURL (包含参考图像):

curl -X POST "https://api.aetherforgeai.com/public/v1/generate/image" \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "prompt=a cat in the style of the reference" \
-F "ai_model=Grok Imagine" \
-F "ref_images=@/path/to/ref1.jpg" \
-F "ref_images=@/path/to/ref2.jpg"