POST /v1/images/generations
POST/v1/images/generations
根据文本提示生成图像。兼容 OpenAI DALL-E 格式。
请求
请求头
| 请求头 | 值 |
|---|
Authorization | Bearer {api_key} |
Content-Type | application/json |
请求体
{
"model": "imagen-3",
"prompt": "A futuristic city skyline at sunset, digital art",
"n": 1,
"size": "1024x1024",
"response_format": "b64_json"
}
参数
| 参数 | 类型 | 必填 | 描述 |
|---|
model | string | 是 | 图像模型 ID。 |
prompt | string | 是 | 期望图像的文本描述。 |
n | integer | 否 | 图像数量。默认 1。 |
size | string | 否 | 图像尺寸,如 "1024x1024"。 |
quality | string | 否 | "standard" 或 "hd"。 |
response_format | string | 否 | "url"(默认)或 "b64_json"。 |
style | string | 否 | "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
}
}
| 字段 | 类型 | 描述 |
|---|
created | integer | Unix 时间戳。 |
data[].url | string | 图像 URL(当 response_format 为 "url" 时)。 |
data[].b64_json | string | Base64 图像数据(当 response_format 为 "b64_json" 时)。 |
data[].revised_prompt | string | 模型理解的提示词。 |
状态码
| 状态码 | 描述 |
|---|
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);