创建图像
POST
/v1/images/generations根据提示词创建图像
对于编码 Agent,请先从
GET /v1/models选择模型,再把选中的model显式传给这个端点。
请求体
参数 model
要使用的模型(例如:dall-e-3、gpt-image-1.5、flux-1.1-pro)。
参数 prompt
所需图像的文本描述。
参数 n
要生成的图像数量(1-4,取决于模型)。
参数 size
图像尺寸。选项因模型而异:
- DALL-E 3:
1024x1024、1792x1024、1024x1792 - 其他模型:
512x512、1024x1024等。
参数 quality
图像质量(standard 或 hd)。仅限 DALL-E 3。
参数 response_format
响应格式:url 或 b64_json。
参数 style
DALL-E 3 的风格:vivid 或 natural。
参数 user
终端用户的唯一标识符。
响应
内联响应
响应字段 created
创建时的 Unix 时间戳。
响应字段 data
生成的图像数组。
每个对象包含:
url(string):生成的图像 URLb64_json(string):Base64 编码的图像(如果请求)revised_prompt(string):使用的提示词(DALL-E 3)
请求示例
curl -X POST "https://api.anypath.dev/v1/images/generations" \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "dall-e-3",
"prompt": "A white cat sitting on a windowsill watching rain",
"size": "1024x1024",
"quality": "standard",
"n": 1
}'
from openai import OpenAI
client = OpenAI(
api_key="sk-your-api-key",
base_url="https://api.anypath.dev/v1"
)
response = client.images.generate(
model="dall-e-3",
prompt="A white cat sitting on a windowsill watching rain",
size="1024x1024",
quality="standard",
n=1
)
print(response.data[0].url)
import OpenAI from 'openai';
const client = new OpenAI({
apiKey: 'sk-your-api-key',
baseURL: 'https://api.anypath.dev/v1'
});
const response = await client.images.generate({
model: 'dall-e-3',
prompt: 'A white cat sitting on a windowsill watching rain',
size: '1024x1024',
quality: 'standard',
n: 1
});
console.log(response.data[0].url);
<?php
$ch = curl_init('https://api.anypath.dev/v1/images/generations');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => [
'Content-Type: application/json',
'Authorization: Bearer sk-your-api-key'
],
CURLOPT_POSTFIELDS => json_encode([
'model' => 'dall-e-3',
'prompt' => 'A white cat sitting on a windowsill watching rain',
'size' => '1024x1024',
'quality' => 'standard',
'n' => 1
])
]);
$response = curl_exec($ch);
curl_close($ch);
$data = json_decode($response, true);
echo $data['data'][0]['url'];
响应示例
{
"created": 1706000000,
"data": [
{
"url": "https://...",
"revised_prompt": "A fluffy white cat with bright eyes sitting peacefully on a wooden windowsill, watching raindrops stream down the glass window..."
}
]
}
可用模型
可用图像模型会随路由供给变化。当前示例:
| 模型 | 供应商 | 说明 |
|---|---|---|
dall-e-3 | OpenAI | 提示词增强;支持 quality 和 style |
gpt-image-1.5 | OpenAI | OpenAI 当前的图像生成与编辑模型 |
gemini-2.5-flash-image | Gemini | Gemini 图像生成 |
grok-4-image | xAI | xAI 图像生成 |
flux-1.1-pro | 聚合网关 | 带厂商前缀的映射 |
你的 Key 当前可用的确切模型,请以 GET /v1/models 的返回为准。