Skip to content

图像生成 API

Star API 提供兼容 OpenAI DALL-E 格式的图像生成接口,支持多种图像生成模型。

请求端点

POST https://star.zhxyclaw.cn/v1/images/generations

请求参数

参数类型必填默认值说明
modelstring-图像生成模型名称
promptstring-图像描述文本
ninteger1生成图像数量
sizestring1024x1024图像尺寸,如 256x256512x5121024x1024
qualitystringstandard图像质量:standardhd
response_formatstringurl返回格式:urlb64_json
stylestringvivid图像风格:vividnatural

请求示例

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"
    }
  ]
}

响应字段说明

字段类型说明
createdinteger创建时间(Unix 时间戳)
dataarray生成的图像列表
data[].urlstring图像 URL(当 response_formaturl 时)
data[].b64_jsonstring图像的 Base64 编码(当 response_formatb64_json 时)
data[].revised_promptstring模型优化后的提示词(部分模型返回)

注意事项

提示

  • 图像 URL 通常有时效性,请及时下载保存
  • prompt 长度建议不超过 4000 字符
  • 部分模型可能不支持所有参数,请以实际返回为准

Star API - 统一的大模型接口网关