Background texture

POST /v1/images/generations

POST/v1/images/generations

根据文本提示生成图像。兼容 OpenAI DALL-E 格式。

请求

请求头

请求头
AuthorizationBearer {api_key}
Content-Typeapplication/json

请求体

{
  "model": "imagen-3",
  "prompt": "A futuristic city skyline at sunset, digital art",
  "n": 1,
  "size": "1024x1024",
  "response_format": "b64_json"
}

参数

参数类型必填描述
modelstring图像模型 ID。
promptstring期望图像的文本描述。
ninteger图像数量。默认 1
sizestring图像尺寸,如 "1024x1024"
qualitystring"standard""hd"
response_formatstring"url"(默认)或 "b64_json"
stylestring"natural""vivid"

响应

{
  "created": 1709123456,
  "data": [
    {
      "url": "https://storage.example.com/generated-image.png",
      "revised_prompt": "A futuristic city skyline at golden hour sunset..."
    }
  ],
  "usage": {
    "prompt_tokens": 0,
    "completion_tokens": 0,
    "total_tokens": 0
  }
}
字段类型描述
createdintegerUnix 时间戳。
data[].urlstring图像 URL(当 response_format"url" 时)。
data[].b64_jsonstringBase64 图像数据(当 response_format"b64_json" 时)。
data[].revised_promptstring模型理解的提示词。

状态码

状态码描述
200成功
400无效请求或模型不支持图像生成
401未授权
402余额不足
502上游供应商错误

示例

curl -X POST https://api.modelmax.io/v1/images/generations \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $MODELMAX_API_KEY" \
  -d '{
    "model": "imagen-3",
    "prompt": "A watercolor painting of a mountain lake",
    "n": 1,
    "size": "1024x1024"
  }'
from openai import OpenAI

client = OpenAI(api_key="your-key", base_url="https://api.modelmax.io/v1")

response = client.images.generate(
    model="imagen-3",
    prompt="A watercolor painting of a mountain lake",
    n=1,
    size="1024x1024",
)

print(response.data[0].url)
import OpenAI from "openai";

const client = new OpenAI({ apiKey: "your-key", baseURL: "https://api.modelmax.io/v1" });

const response = await client.images.generate({
  model: "imagen-3",
  prompt: "A watercolor painting of a mountain lake",
  n: 1,
  size: "1024x1024",
});

console.log(response.data[0].url);