EasyXAI 文档
API 接入

火山方舟生图协议

POST https://api.easyx.ai/api/v3/images/generations
Authorization: Bearer easyx_ws_xxx
Content-Type: application/json

请求示例

文生图

curl https://api.easyx.ai/api/v3/images/generations \
  -H "Authorization: Bearer easyx_ws_xxx" \
  -H "Content-Type: application/json" \
  -d '{
  "model": "doubao-seedream-5-0-pro",
  "prompt": "一只戴红帽子的柴犬,水彩画风。",
  "size": "2K",
  "watermark": false
}'

单张参考图

curl https://api.easyx.ai/api/v3/images/generations \
  -H "Authorization: Bearer easyx_ws_xxx" \
  -H "Content-Type: application/json" \
  -d '{
  "model": "doubao-seedream-5-0-pro",
  "prompt": "给图中的柴犬戴上蓝帽子。",
  "image": "https://example.com/input.png"
}'

多张参考图

curl https://api.easyx.ai/api/v3/images/generations \
  -H "Authorization: Bearer easyx_ws_xxx" \
  -H "Content-Type: application/json" \
  -d '{
  "model": "doubao-seedream-5-0-pro",
  "prompt": "将图一的商品放到图二的背景中。",
  "image": [
    "https://example.com/product.png",
    "https://example.com/background.png"
  ]
}'

image 支持单个图片 URL / data URL,也可传参考图数组。将示例 URL 替换为可访问的图片地址。base64 输入使用 data:image/png;base64,BASE64_IMAGE 格式。图片格式、张数和尺寸限制随模型而不同。

请求参数

参数类型必填说明
modelstring是生图模型名称。
promptstring是图片描述或修改指令。
imagestring / array否参考图 URL 或 data URL;单图传字符串,多图传数组。
sizestring否像素尺寸(如 1024x1024)或模型支持的分辨率档位(如 2K)。
response_formatstring否支持该参数的模型可选 url 或 b64_json;部分模型固定返回 base64。
output_formatstring否支持该参数的模型可选 jpeg 或 png。
watermarkboolean否是否添加水印,true 为添加,false 为关闭。
seedinteger否随机种子,仅支持该参数的模型生效。
guidance_scalenumber否提示词引导强度,仅支持该参数的模型生效。
sequential_image_generationstring否支持组图的模型可设 auto 或 disabled。
sequential_image_generation_options.max_imagesinteger否组图数量上限,需要模型支持。
streamboolean否支持流式的模型可设 true 接收 SSE 事件。
optimize_prompt_optionsobject否提示词优化选项,支持情况由模型决定。
toolsarray否模型支持的工具配置,例如 web_search。

响应

{
  "model": "doubao-seedream-5-0-pro",
  "created": 1741569952,
  "data": [
    {
      "b64_json": "BASE64_IMAGE",
      "size": "2048x2048"
    }
  ],
  "usage": {
    "generated_images": 1,
    "output_tokens": 100,
    "total_tokens": 100
  }
}
{
  "model": "doubao-seedream-5-0-pro",
  "created": 1741569952,
  "data": [
    {
      "url": "https://example.com/generated-image.jpeg",
      "size": "2048x2048"
    }
  ]
}
字段类型说明
modelstring响应中的模型名称。
createdinteger生成时间戳。
dataarray图片结果列表。
data[].urlstring返回 URL 时的图片地址。
data[].b64_jsonstring返回 base64 时的图片内容。
data[].sizestring返回时表示实际图片尺寸。
usageobject模型返回的使用量统计,可能不提供。
usage.generated_imagesinteger生成图片数量。
usage.output_tokens / total_tokensinteger模型返回的 token 统计。
errorobject返回时包含 code 和 message。

读取图片结果

import base64
from pathlib import Path

# response is the parsed JSON response
for index, image in enumerate(response["data"]):
    if image.get("b64_json"):
        Path(f"image-{index}").write_bytes(base64.b64decode(image["b64_json"]))
    elif image.get("url"):
        print(image["url"])

流式生图

支持流式的模型可以传 stream=true。处理以下事件,其中 image_generation.completed 表示本次请求结束。

curl -N https://api.easyx.ai/api/v3/images/generations \
  -H "Authorization: Bearer easyx_ws_xxx" \
  -H "Content-Type: application/json" \
  -d '{
  "model": "doubao-seedream-4-5-251128",
  "prompt": "一组四季风景。",
  "stream": true
}'
事件说明
image_generation.partial_succeeded一张图片生成成功,读取 image_index 与 url 或 b64_json。
image_generation.partial_failed一张图片生成失败,检查 error。
image_generation.completed本次生成结束,检查最终 usage 与错误。

Python

pip install requests
import requests

response = requests.post(
    "https://api.easyx.ai/api/v3/images/generations",
    headers={"Authorization": "Bearer easyx_ws_xxx"},
    json={
        "model": "doubao-seedream-5-0-pro",
        "prompt": "A dog wearing a red hat",
    },
    timeout=600,
)
response.raise_for_status()
result = response.json()
print(result["data"])

Node.js

const response = await fetch("https://api.easyx.ai/api/v3/images/generations", {
  method: "POST",
  headers: {
    Authorization: "Bearer easyx_ws_xxx",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    model: "doubao-seedream-5-0-pro",
    prompt: "A dog wearing a red hat",
  }),
});

if (!response.ok) throw new Error(await response.text());
const result = await response.json();
console.log(result.data);

Volcano Engine image generation reference