Skip to content

图像生成 API

BeesAI 支持通过文本描述生成图片,兼容 OpenAI Images API 格式。

Endpoint

POST https://api.beesai.cn/v1/images/generations

请求参数

参数类型必填说明
modelstring图像生成模型 ID
promptstring图片描述文本
ninteger生成图片数量 (1-10),默认 1
sizestring图片尺寸,默认 1024x1024
qualitystring图片质量:standardhd
response_formatstring返回格式:urlb64_json

支持的尺寸

模型支持的尺寸
dall-e-31024x1024, 1024x1792, 1792x1024
dall-e-2256x256, 512x512, 1024x1024

请求示例

cURL

bash
curl https://api.beesai.cn/v1/images/generations \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-你的API_KEY" \
  -d '{
    "model": "dall-e-3",
    "prompt": "一只穿着宇航服的猫在月球上漫步,赛博朋克风格",
    "n": 1,
    "size": "1024x1024"
  }'

Python

python
from openai import OpenAI

client = OpenAI(
    api_key="sk-你的API_KEY",
    base_url="https://api.beesai.cn/v1"
)

response = client.images.generate(
    model="dall-e-3",
    prompt="一只穿着宇航服的猫在月球上漫步,赛博朋克风格",
    size="1024x1024",
    quality="standard",
    n=1
)

print(response.data[0].url)

JavaScript

javascript
import OpenAI from 'openai';

const client = new OpenAI({
  apiKey: 'sk-你的API_KEY',
  baseURL: 'https://api.beesai.cn/v1'
});

const response = await client.images.generate({
  model: 'dall-e-3',
  prompt: '一只穿着宇航服的猫在月球上漫步,赛博朋克风格',
  size: '1024x1024',
  n: 1
});

console.log(response.data[0].url);

响应格式

json
{
  "created": 1677858242,
  "data": [
    {
      "url": "https://cdn.beesai.cn/images/abc123.png",
      "revised_prompt": "A cat wearing a spacesuit walking on the moon, cyberpunk style"
    }
  ]
}

Base64 响应

设置 "response_format": "b64_json" 可获取 Base64 编码的图片数据:

json
{
  "created": 1677858242,
  "data": [
    {
      "b64_json": "iVBORw0KGgoAAAANSUhEUg..."
    }
  ]
}

Prompt 编写技巧

1. 具体描述

❌ 一只猫
✅ 一只橘色的英国短毛猫,坐在窗台上,阳光洒在身上,温暖的光线,写实风格

2. 指定风格

水彩画风格 / 油画风格 / 赛博朋克 / 极简主义 / 日系动漫 / 3D渲染

3. 添加细节

高细节 / 8K / 电影级光影 / 景深效果 / 微距摄影

对话补全 → | 文本向量化 → | 错误码 →

© 2026 BeesAI. All rights reserved.