POST
文生图
POST /v1/images/generations — 根据文本生成图片
文生图
根据文字描述(Prompt)生成图片,兼容 OpenAI DALL-E API 格式,同时支持 Flux 等主流图像模型。
POST
https://api000.com/v1/images/generations
请求参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
model |
string | 必填 | 绘图模型 ID,如 dall-e-3、flux-1.1-pro |
prompt |
string | 必填 | 图片描述(Prompt),推荐英文,最长 4000 字符 |
n |
integer | 可选 | 生成数量,默认 1,DALL-E 3 最多 1 张 |
size |
string | 可选 | 图片尺寸,如 1024x1024 |
quality |
string | 可选 | "standard"(默认)或 "hd"(DALL-E 3) |
style |
string | 可选 | "natural" 或 "vivid"(DALL-E 3) |
response_format |
string | 可选 | "url"(默认)或 "b64_json"(Base64 数据) |
请求示例
cURL
curl https://api000.com/v1/images/generations \
-H "Authorization: Bearer sk-xxxxxxxxxxxxxxxx" \
-H "Content-Type: application/json" \
-d '{
"model": "dall-e-3",
"prompt": "一只在宇宙中漂浮的橙色猫咪,背景是紫色星云,写实摄影风格",
"size": "1024x1024",
"quality": "hd",
"n": 1
}'
Python
from openai import OpenAI
import httpx
client = OpenAI(
base_url="https://api000.com/v1",
api_key="sk-xxxxxxxxxxxxxxxx"
)
response = client.images.generate(
model="dall-e-3",
prompt="A cute orange cat floating in space with purple nebula background, photorealistic",
size="1024x1024",
quality="hd",
n=1
)
image_url = response.data[0].url
print(f"图片URL: {image_url}")
# 可选:下载图片到本地
img_data = httpx.get(image_url).content
with open("output.png", "wb") as f:
f.write(img_data)
print("已保存为 output.png")
Node.js
import OpenAI from "openai";
import fs from "fs";
import https from "https";
const client = new OpenAI({
baseURL: "https://api000.com/v1",
apiKey: "sk-xxxxxxxxxxxxxxxx",
});
const response = await client.images.generate({
model: "dall-e-3",
prompt: "A futuristic cityscape at night with neon lights, cyberpunk style",
size: "1792x1024",
quality: "hd",
n: 1,
});
console.log("图片URL:", response.data[0].url);
响应示例
{
"created": 1677652288,
"data": [
{
"url": "https://cdn.example.com/images/generated/xxx.png",
"revised_prompt": "A cute orange cat with bright fur floating in deep space..."
}
]
}
revised_prompt是 DALL-E 3 模型对你 Prompt 的优化版本,可以参考它来改进提示词。
支持的尺寸
| 模型 | 支持尺寸 |
|---|---|
dall-e-3 |
1024x1024、1792x1024(横版)、1024x1792(竖版) |
dall-e-2 |
256x256、512x512、1024x1024 |
flux-1.1-pro |
灵活指定,最大 2048×2048 |
flux-schnell |
灵活指定,速度极快 |
Prompt 技巧
- 指定风格:photorealistic(写实)、oil painting(油画)、anime style(动漫风)
- 指定构图:wide shot(全景)、close-up(特写)、bird's eye view(俯视)
- 指定光照:golden hour(黄金时段)、dramatic lighting(戏剧性光线)
- 指定细节:8K resolution、highly detailed、sharp focus