name: seedream-4.5 description: 使用即梦 Seedream 4.5 AI 图像生成模型生成高质量图片。支持文生图、图生图、多图融合、组图生成等功能。当用户需要生成图片、使用 Seedream/即梦/字节跳动图像 API、或进行 AI 绘画时调用。
Seedream 4.5 Skill
Seedream 4.5 是字节跳动即梦 AI 推出的高质量图像生成模型,支持文生图、图生图、多图融合、组图生成等功能。
能力概述
- 文生图: 根据文本提示词生成单图或组图
- 图生图: 根据参考图片+文本提示词生成新图片
- 多图融合: 支持 2-14 张参考图片融合生成
- 组图生成: 生成一组内容关联的图片(最多15张)
- 流式输出: 支持实时返回生成进度
- 高分辨率: 支持 1K/2K/4K 分辨率,最高 4096x4096
快速开始
1. 文生图
import sys
sys.path.insert(0, '${SKILL_DIR}/scripts')
from seedream_client import SeedreamClient
# 方式 1: 直接传入 API key
client = SeedreamClient(api_key="your-api-key")
# 方式 2: 从环境变量读取 (需先设置 SEEDREAM_API_KEY)
import os
os.environ["SEEDREAM_API_KEY"] = "your-api-key"
client = SeedreamClient() # 自动读取环境变量
result = client.generate_image(
prompt="一只可爱的橘猫在阳光下打盹,高品质,8K",
size="2K", # 可选: 1K, 2K, 4K 或具体尺寸如 "2048x2048"
n=1
)
print(result["data"][0]["url"])
2. 图生图 (单图)
# 方式 1: 使用 URL
result = client.image_to_image(
prompt="将这张图片转换成赛博朋克风格",
image="https://example.com/image.jpg",
size="2K"
)
# 方式 2: 使用本地文件路径(自动转 Base64)
result = client.image_to_image(
prompt="添加油画效果",
image="/path/to/photo.jpg"
)
# 方式 3: 使用 Path 对象
from pathlib import Path
result = client.image_to_image(
prompt="转换成动漫风格",
image=Path("./myphoto.png")
)
3. 多图融合 (2-14张)
# 两张图融合
result = client.blend_images(
prompt="将人物照片与油画风格融合",
images=["portrait.jpg", "oil_painting.jpg"]
)
# 多张图融合
result = client.blend_images(
prompt="融合多张参考图的风格特征",
images=["ref1.jpg", "ref2.jpg", "ref3.jpg"]
)
# 混合 URL 和本地文件
result = client.image_to_image(
prompt="融合多种元素",
image=["https://example.com/a.jpg", "./local/b.png"]
)
图生图完整示例
import sys
sys.path.insert(0, '${SKILL_DIR}/scripts')
from seedream_client import SeedreamClient
import os
os.environ["SEEDREAM_API_KEY"] = "your-api-key"
client = SeedreamClient()
# 示例 1: 风格转换
result = client.image_to_image(
prompt="将这张图片转换成宫崎骏动画风格,色彩明亮,梦幻氛围",
image="input_photo.jpg",
size="2K"
)
if "data" in result:
url = result["data"][0]["url"]
client.download_image(url, "output_ghibli.png")
# 示例 2: 多图融合 - 人物 + 风格
result = client.blend_images(
prompt="保持左边人物的面容特征,应用右边的赛博朋克霓虹灯光风格",
images=["person.jpg", "cyberpunk_city.jpg"],
size="2K"
)
# 示例 3: 图片编辑
result = client.image_to_image(
prompt="给这只猫加上一副墨镜,保持原有背景",
image="cat.jpg",
size="1024x1024"
)
4. 生成组图
result = client.generate_image(
prompt="生成一组展示春季日本京都不同景点的图片",
sequential_image_generation="auto",
sequential_image_generation_options={"max_images": 5}
)
API 参数说明
请求参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| model | string | 是 | 模型 ID,如 doubao-seedream-4-5-251128 |
| prompt | string | 是 | 提示词,建议不超过 300 汉字或 600 英文单词 |
| image | string/array | 否 | 参考图片,支持 URL 或 Base64 |
| size | string | 否 | 尺寸:1K/2K/4K 或具体像素如 2048x2048 |
| sequential_image_generation | string | 否 | 组图开关:auto(开启) / disabled(关闭) |
| stream | boolean | 否 | 是否流式输出 |
| response_format | string | 否 | 返回格式:url 或 b64_json |
| watermark | boolean | 否 | 是否添加水印,默认 true |
| optimize_prompt_options | object | 否 | 提示词优化配置 |
尺寸规范
方式 1 - 分辨率规格: 1K, 2K, 4K
- 模型会根据提示词中的宽高比描述自动决定最终尺寸
方式 2 - 具体像素值:
- 总像素范围: [921600, 16777216] (即 1280x720 到 4096x4096)
- 宽高比范围: [1/16, 16]
常用尺寸推荐:
| 比例 | 1K | 2K | 4K |
|---|---|---|---|
| 1:1 | 1024x1024 | 2048x2048 | 4096x4096 |
| 4:3 | 864x1152 | 2304x1728 | 4704x3520 |
| 3:4 | 1152x864 | 1728x2304 | 3520x4704 |
| 16:9 | 1280x720 | 2560x1440 | 5504x3040 |
| 9:16 | 720x1280 | 1440x2560 | 3040x5504 |
命令行使用
脚本支持通过命令行参数直接调用,无需编写 Python 代码。
Script Directory
Important: All scripts are located in the scripts/ subdirectory of this skill.
Agent Execution Instructions:
- Determine this SKILL.md file's directory path as
SKILL_DIR - Script path =
${SKILL_DIR}/scripts/<script-name>.py - Replace all
${SKILL_DIR}in this document with the actual path
Script Reference:
| Script | Purpose |
|---|---|
scripts/seedream_client.py |
Seedream 4.5 图像生成客户端 |
快速开始
# 设置环境变量
export SEEDREAM_API_KEY="your-api-key"
# 文生图
python ${SKILL_DIR}/scripts/seedream_client.py --prompt "一只可爱的橘猫"
# 图生图
python ${SKILL_DIR}/scripts/seedream_client.py --prompt "转换成动漫风格" --image ./photo.jpg
# 多图融合
python ${SKILL_DIR}/scripts/seedream_client.py --prompt "融合风格" --image ./img1.jpg --image ./img2.jpg
命令行参数
| 参数 | 简写 | 说明 | 默认值 |
|---|---|---|---|
--prompt |
-p |
提示词(必填) | - |
--api-key |
- | API 密钥 | SEEDREAM_API_KEY 环境变量 |
--base-url |
- | API 基础地址 | 传入值 > SEEDREAM_BASE_URL > 默认值 |
--model |
- | 模型 ID | doubao-seedream-4-5-251128 |
--size |
-s |
图片尺寸 | 2K |
--num |
-n |
生成数量 | 1 |
--image |
- | 参考图片(可多次指定) | - |
--output |
-o |
输出路径 | output.png |
--sequential |
- | 开启组图模式 | False |
--max-images |
- | 组图最大数量 | 4 |
--stream |
- | 流式输出 | False |
--verbose |
-v |
显示详细日志 | False |
--no-download |
- | 仅输出 URL 不下载 | False |
--no-watermark |
- | 不添加水印 | False |
使用示例
# 基础文生图
python ${SKILL_DIR}/scripts/seedream_client.py -p "海边日落,金色沙滩"
# 指定尺寸和输出
python ${SKILL_DIR}/scripts/seedream_client.py -p "山水风景" -s 4K -o landscape.png
# 指定自定义尺寸
python ${SKILL_DIR}/scripts/seedream_client.py -p "城市夜景" -s 1920x1080 -o city.png
# 指定 base_url(优先级最高)
python ${SKILL_DIR}/scripts/seedream_client.py -p "一只猫" --base-url "https://api.example.com/v1"
# 或者通过环境变量设置 base_url
export SEEDREAM_BASE_URL="https://api.example.com/v1"
python ${SKILL_DIR}/scripts/seedream_client.py -p "一只猫"
# 组图生成
python ${SKILL_DIR}/scripts/seedream_client.py -p "四季风景" --sequential --max-images 4
# 多图融合(人物 + 风格)
python ${SKILL_DIR}/scripts/seedream_client.py \
-p "将人物转换成赛博朋克风格" \
--image ./portrait.jpg \
--image ./cyberpunk_style.jpg \
-o result.png
# 显示详细日志
python ${SKILL_DIR}/scripts/seedream_client.py -p "雪山日出" -v
# 仅输出 URL 不下载
python ${SKILL_DIR}/scripts/seedream_client.py -p "星空银河" --no-download
base_url 优先级
base_url 的获取优先级如下:
- 命令行参数
--base-url- 优先级最高 - 环境变量
SEEDREAM_BASE_URL- 次之 - 默认值
https://ark.cn-beijing.volces.com/api/v3- 最后
# 示例:优先级演示
# 方式1:命令行参数(优先级最高)
python ${SKILL_DIR}/scripts/seedream_client.py -p "测试" --base-url "https://api.a.com"
# 使用: https://api.a.com
# 方式2:环境变量
export SEEDREAM_BASE_URL="https://api.b.com"
python ${SKILL_DIR}/scripts/seedream_client.py -p "测试"
# 使用: https://api.b.com
# 方式3:默认值(未设置前两种方式时)
python ${SKILL_DIR}/scripts/seedream_client.py -p "测试"
# 使用: https://ark.cn-beijing.volces.com/api/v3
客户端使用
基础使用
import sys
sys.path.insert(0, '${SKILL_DIR}/scripts')
from seedream_client import SeedreamClient
import os
# 设置环境变量 (推荐方式)
os.environ["SEEDREAM_API_KEY"] = "your-api-key"
# 初始化客户端 (自动读取环境变量)
client = SeedreamClient(
base_url="https://ark.cn-beijing.volces.com/api/v3" # 火山方舟
)
# 或者显式传入 API key
# client = SeedreamClient(api_key="your-api-key")
# 简单文生图
result = client.generate_image("一只可爱的柯基犬")
# 保存生成的图片
client.download_image(result["data"][0]["url"], "output.png")
高级配置
client = SeedreamClient(
api_key="your-api-key",
base_url="https://ark.cn-beijing.volces.com/api/v3",
default_model="doubao-seedream-4-5-251128",
default_size="2K"
)
# 批量生成
prompts = [
"海边日落,金色沙滩",
"雪山日出,云海翻腾",
"城市夜景,霓虹灯光"
]
for prompt in prompts:
result = client.generate_image(prompt, quality="hd")
客户端方法列表
| 方法 | 说明 |
|---|---|
generate_image() |
通用图片生成,支持文生图和图生图 |
image_to_image() |
图生图,支持本地文件自动转 Base64 |
blend_images() |
多图融合(2-14张) |
generate_sequential_images() |
生成组图(最多15张) |
download_image() |
下载生成的图片到本地 |
save_base64_image() |
保存 Base64 编码的图片 |
get_size_preset() |
获取推荐尺寸 |
validate_size() |
验证尺寸是否有效 |
提示词技巧
有效提示词结构
[主体] + [细节描述] + [风格/氛围] + [质量修饰词]
示例:
- ✅ "一只毛茸茸的英国短毛猫,蓝灰色毛发,坐在窗台上,午后阳光,温馨治愈风格,高细节,8K"
- ❌ "一只猫" (过于简单,缺少细节)
风格关键词
- 写实风格: photorealistic, hyper realistic, 8K, ultra detailed
- 动漫风格: anime style, studio ghibli, pixar style, cartoon
- 艺术风格: oil painting, watercolor, digital art, concept art
- 氛围: dreamy, cinematic lighting, golden hour, moody atmosphere
错误处理
result = client.generate_image("测试提示词")
if "error" in result:
print(f"生成失败: {result['error']}")
else:
for item in result.get("data", []):
if "url" in item:
print(f"图片URL: {item['url']}")
elif "error" in item:
print(f"单张图片生成失败: {item['error']}")
图生图规范
支持的图片格式
- 格式: JPEG, PNG, WebP, BMP, TIFF, GIF
- 大小: 单张不超过 10MB
- 总像素: 不超过 6000x6000 (3600万像素)
- 宽高比: [1/16, 16]
图生图限制
| 类型 | 参考图数量 | 说明 |
|---|---|---|
| 单图生图 | 1张 | 基于单张图片生成新图 |
| 多图融合 | 2-14张 | 融合多张图片特征 |
| 单图生组图 | 1张 + 文本 | 生成最多14张关联图片 |
| 多图生组图 | 2-14张 + 文本 | 生成组图,参考图+生成图≤15张 |
图片输入方式
- URL: 图片链接,需确保可访问
- 本地文件: 自动转换为 Base64 编码
- Base64: 格式
data:image/png;base64,xxxxx
# URL
image="https://example.com/photo.jpg"
# 本地文件(自动处理)
image="./myphoto.png"
# Base64
image="data:image/jpeg;base64,/9j/4AAQSkZJRg..."
# 多图混合
image=["url1.jpg", "./local.png", "data:image/png;base64,..."]
常见问题
- 图片生成慢: 开启流式输出
stream=True可实时获取进度 - 提示词被忽略: 确保提示词不超过 300 汉字,重要信息放在前面
- 组图数量不对: 输入参考图数量 + 生成图片数量 ≤ 15
- 尺寸报错: 确保总像素在有效范围内,且宽高比在 [1/16, 16] 之间
- 图生图失败: 检查图片格式和大小是否符合规范
脚本参考
scripts/seedream_client.py- Python 客户端封装