图像生成 API
Star API 提供兼容 OpenAI DALL-E 格式的图像生成接口,支持多种图像生成模型。
请求端点
POST https://star.zhxyclaw.cn/v1/images/generations请求参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
model | string | 是 | - | 图像生成模型名称 |
prompt | string | 是 | - | 图像描述文本 |
n | integer | 否 | 1 | 生成图像数量 |
size | string | 否 | 1024x1024 | 图像尺寸,如 256x256、512x512、1024x1024 |
quality | string | 否 | standard | 图像质量:standard 或 hd |
response_format | string | 否 | url | 返回格式:url 或 b64_json |
style | string | 否 | vivid | 图像风格:vivid 或 natural |
请求示例
curl
bash
curl https://star.zhxyclaw.cn/v1/images/generations \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-your-api-key" \
-d '{
"model": "dall-e-3",
"prompt": "一只可爱的橘猫坐在书桌上,窗外是星空",
"n": 1,
"size": "1024x1024",
"quality": "standard"
}'Python
python
from openai import OpenAI
client = OpenAI(
api_key="sk-your-api-key",
base_url="https://star.zhxyclaw.cn/v1"
)
response = client.images.generate(
model="dall-e-3",
prompt="一只可爱的橘猫坐在书桌上,窗外是星空",
n=1,
size="1024x1024",
quality="standard"
)
print(response.data[0].url)Node.js
javascript
import OpenAI from "openai";
const client = new OpenAI({
apiKey: "sk-your-api-key",
baseURL: "https://star.zhxyclaw.cn/v1",
});
const response = await client.images.generate({
model: "dall-e-3",
prompt: "一只可爱的橘猫坐在书桌上,窗外是星空",
n: 1,
size: "1024x1024",
quality: "standard",
});
console.log(response.data[0].url);响应格式
json
{
"created": 1720000000,
"data": [
{
"url": "https://example.com/generated-image.png",
"revised_prompt": "A cute orange cat sitting on a desk, with a starry sky visible through the window"
}
]
}响应字段说明
| 字段 | 类型 | 说明 |
|---|---|---|
created | integer | 创建时间(Unix 时间戳) |
data | array | 生成的图像列表 |
data[].url | string | 图像 URL(当 response_format 为 url 时) |
data[].b64_json | string | 图像的 Base64 编码(当 response_format 为 b64_json 时) |
data[].revised_prompt | string | 模型优化后的提示词(部分模型返回) |
注意事项
提示
- 图像 URL 通常有时效性,请及时下载保存
prompt长度建议不超过 4000 字符- 部分模型可能不支持所有参数,请以实际返回为准
