Images
POST /v1/images/generations — 使用 DALL-E 模型根据文字描述生成 AI 图片。
请求示例
cURLBash
curl https://www.ulovegpt.com/v1/images/generations \
-H "Authorization: Bearer <你的 API_KEY>" \
-H "Content-Type: application/json" \
-d '{
"model": "openai/dall-e-3",
"prompt": "一只穿着宇航服的猫咪在月球表面行走,背景是地球",
"n": 1,
"size": "1024x1024",
"quality": "hd",
"response_format": "url"
}'PythonPython
from openai import OpenAI
client = OpenAI(
base_url="https://www.ulovegpt.com/v1",
api_key="<你的 API_KEY>"
)
response = client.images.generate(
model="openai/dall-e-3",
prompt="一只穿着宇航服的猫咪在月球表面行走,背景是地球",
n=1,
size="1024x1024",
quality="hd"
)
# 获取图片 URL
print(response.data[0].url)
# 或保存图片
import urllib.request
urllib.request.urlretrieve(response.data[0].url, "astronaut_cat.png")请求参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | 是 | 图片生成模型,如 dall-e-3 |
prompt | string | 是 | 图片描述文字,最多 4000 字符 |
n | integer | 否 | 生成图片数量,1-10(默认 1) |
size | string | 否 | 图片尺寸:1024x1024 / 1024x1792 / 1792x1024 |
quality | string | 否 | 图片质量:standard / hd |
style | string | 否 | 风格:vivid / natural |
response_format | string | 否 | 返回格式:url / b64_json |
响应格式
响应示例Json
{
"created": 1704067200,
"data": [
{
"revised_prompt": "A cat wearing an astronaut suit walking on the lunar surface, with Earth visible in the background",
"url": "https://oaidalleapiprodscus.blob.core.windows.net/private/..."
}
]
}Prompt 技巧
- 细节越多越好:描述场景、光线、颜色、风格等细节
- 指定风格:添加 "photorealistic"、"oil painting"、"anime style" 等关键词
- 构图描述:说明主体位置、背景、视角
- 避免歧义:用具体词汇替代抽象描述