Docs

创建图像

POST/v1/images/generations

根据提示词创建图像

本页目录
  1. 请求体
  2. 响应
  3. 内联响应
  4. 请求示例
  5. 响应示例
  6. 可用模型

对于编码 Agent,请先从 GET /v1/models 选择模型,再把选中的 model 显式传给这个端点。

请求体

参数 model

类型:string

位置:body

要使用的模型(例如:dall-e-3、gpt-image-1.5、flux-1.1-pro)。

参数 prompt

类型:string

位置:body

必填:是

所需图像的文本描述。

参数 n

类型:integer

位置:body

要生成的图像数量(1-4,取决于模型)。

参数 size

类型:string

位置:body

图像尺寸。选项因模型而异:

  • DALL-E 3:1024x1024、1792x1024、1024x1792
  • 其他模型:512x512、1024x1024 等。

参数 quality

类型:string

位置:body

图像质量(standard 或 hd)。仅限 DALL-E 3。

参数 response_format

类型:string

位置:body

响应格式:url 或 b64_json。

参数 style

类型:string

位置:body

DALL-E 3 的风格:vivid 或 natural。

参数 user

类型:string

位置:body

终端用户的唯一标识符。

响应

内联响应

响应字段 created

类型:integer

创建时的 Unix 时间戳。

响应字段 data

类型:array

生成的图像数组。

每个对象包含:

  • url (string):生成的图像 URL
  • b64_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-3OpenAI提示词增强;支持 quality 和 style
gpt-image-1.5OpenAIOpenAI 当前的图像生成与编辑模型
gemini-2.5-flash-imageGeminiGemini 图像生成
grok-4-imagexAIxAI 图像生成
flux-1.1-pro聚合网关带厂商前缀的映射

你的 Key 当前可用的确切模型,请以 GET /v1/models 的返回为准。