概述

SeeDream 4.0 (seedream-4-0-250828) 是来自 BytePlus 火山方舟海外版的高品质图像生成模型,API易已达成官方战略合作,提供稳定可靠的服务。

📚 最新文档

飞书完整使用指南 - 更新最快,支持评论互动访问飞书文档获取最新的使用教程、技巧分享和问题解答。文档持续更新,遇到问题可直接在飞书上评论交流。

核心优势
  • 🎨 高品质出图:支持 4K 高清图像生成,视觉一致性优秀
  • 💰 价格优势0.025/张(官网0.025/张(官网 0.03/张,相当于 65% 折扣)
  • 🚀 生成速度:平均 15 秒左右一张图,响应迅速
  • 🤝 官方合作:BytePlus 火山方舟战略合作,资源可靠稳定
  • 🔧 标准接口:完全兼容 OpenAI Image API 格式

调用方式

正确端点 ✅

POST /v1/images/generations
重要提示:SeeDream 4.0 使用标准的 OpenAI 图像生成端点,完全兼容 OpenAI Image API 格式,按次计费,简单透明。

Python 示例代码

以下是完整的 Python 示例代码,展示如何使用 SeeDream 4.0 生成图像:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
SeeDream 4.0 图片生成 - Python版本
支持标准 OpenAI Image API 格式
"""

import requests
import json
import base64
import os
import datetime
from typing import Optional, Dict, Any

class SeeDreamImageGenerator:
    def __init__(self, api_key: str, api_url: str = "https://api.apiyi.com/v1/images/generations"):
        """
        初始化 SeeDream 图片生成器

        Args:
            api_key: API密钥
            api_url: API地址
        """
        self.api_key = api_key
        self.api_url = api_url
        self.headers = {
            "Content-Type": "application/json",
            "Authorization": f"Bearer {api_key}"
        }

    def generate_image(self,
                      prompt: str,
                      model: str = "seedream-4-0-250828",
                      size: str = "2048x2048",
                      quality: str = "standard",
                      n: int = 1,
                      response_format: str = "url",
                      output_dir: str = ".") -> Dict[str, Any]:
        """
        生成图片

        Args:
            prompt: 图片描述提示词
            model: 使用的模型
            size: 图片尺寸
                  方法1: 分辨率规格 ("1K", "2K", "4K") - 让模型根据提示词决定最终尺寸
                  方法2: 精确像素 ("2048x2048", "1920x1080" 等) - 范围[1280x720, 4096x4096]
            quality: 图片质量 (standard 或 hd)
            n: 生成数量
            response_format: 响应格式 (url 或 b64_json)
            output_dir: 输出目录(仅当response_format为b64_json时使用)

        Returns:
            API响应结果
        """
        print("🚀 开始生成图片...")
        print(f"提示词: {prompt}")
        print(f"模型: {model}")
        print(f"尺寸: {size}")
        print(f"质量: {quality}")

        try:
            # 准备请求数据
            payload = {
                "model": model,
                "prompt": prompt,
                "size": size,
                "quality": quality,
                "n": n,
                "response_format": response_format
            }

            print("📡 发送API请求...")

            # 发送请求
            response = requests.post(
                self.api_url,
                headers=self.headers,
                json=payload,
                timeout=60
            )

            if response.status_code != 200:
                error_msg = f"API请求失败,状态码: {response.status_code}"
                try:
                    error_detail = response.json()
                    error_msg += f", 错误详情: {error_detail}"
                except:
                    error_msg += f", 响应内容: {response.text[:500]}"
                print(f"❌ {error_msg}")
                return {"error": error_msg}

            print("✅ API请求成功")

            # 解析响应
            result = response.json()

            # 处理响应数据
            if response_format == "b64_json" and "data" in result:
                print("🔍 正在保存base64图片...")
                for i, item in enumerate(result["data"]):
                    if "b64_json" in item:
                        self._save_base64_image(
                            item["b64_json"],
                            output_dir,
                            f"seedream_{datetime.datetime.now().strftime('%Y%m%d_%H%M%S')}_{i}.png"
                        )
            elif response_format == "url" and "data" in result:
                print("🎨 生成的图片URL:")
                for item in result["data"]:
                    if "url" in item:
                        print(f"  🔗 {item['url']}")

            return result

        except requests.exceptions.Timeout:
            error_msg = "请求超时(60秒)"
            print(f"❌ {error_msg}")
            return {"error": error_msg}
        except requests.exceptions.ConnectionError as e:
            error_msg = f"连接错误: {str(e)}"
            print(f"❌ {error_msg}")
            return {"error": error_msg}
        except Exception as e:
            error_msg = f"未知错误: {str(e)}"
            print(f"❌ {error_msg}")
            return {"error": error_msg}

    def _save_base64_image(self, b64_data: str, output_dir: str, filename: str):
        """
        保存base64图片到本地

        Args:
            b64_data: base64编码的图片数据
            output_dir: 输出目录
            filename: 文件名
        """
        try:
            # 解码base64数据
            image_data = base64.b64decode(b64_data)

            # 创建输出目录
            os.makedirs(output_dir, exist_ok=True)

            # 保存文件
            output_path = os.path.join(output_dir, filename)
            with open(output_path, 'wb') as f:
                f.write(image_data)

            print(f"🖼️  图片保存成功: {output_path}")
            print(f"📊 文件大小: {len(image_data)} 字节")

        except Exception as e:
            print(f"❌ 保存图片失败: {str(e)}")

def main():
    """
    主函数 - 演示 SeeDream 4.0 图片生成
    """
    # 配置参数
    API_KEY = "sk-"  # 请替换为你的实际API密钥

    # 示例提示词
    prompts = [
        "A serene Japanese garden with cherry blossoms in full bloom, koi pond, traditional bridge, 4K, ultra detailed",
        "Futuristic cityscape at night with neon lights and flying vehicles, cyberpunk style, high quality",
        "Cute cartoon cat astronaut floating in space with planets in background, pixar style"
    ]

    print("="*60)
    print("SeeDream 4.0 图片生成器 - Python版本")
    print("="*60)
    print(f"开始时间: {datetime.datetime.now()}")

    # 创建生成器实例
    generator = SeeDreamImageGenerator(API_KEY)

    # 生成示例图片
    for i, prompt in enumerate(prompts, 1):
        print(f"\n🎯 示例 {i}/{len(prompts)}")
        print("-"*40)

        result = generator.generate_image(
            prompt=prompt,
            size="2K",          # 可选: "1K", "2K", "4K" 或精确尺寸如 "2048x2048"
            quality="hd",       # 可选: standard, hd
            n=1,                # 生成数量
            response_format="url"  # 可选: url, b64_json
        )

        if "error" not in result:
            print(f"✅ 图片 {i} 生成成功!")
        else:
            print(f"❌ 图片 {i} 生成失败")

        print("-"*40)

    print(f"\n结束时间: {datetime.datetime.now()}")
    print("="*60)

if __name__ == "__main__":
    main()

使用步骤

  1. 替换 API Key:将代码中的 API_KEY 替换为你的实际 API 密钥
  2. 设置参数
    • prompt: 详细描述你想要生成的图片
    • size: 选择图片尺寸
      • 方法1:使用分辨率规格 (“1K”, “2K”, “4K”) - 模型根据提示词自动决定宽高比
      • 方法2:指定精确像素 (如 “2048x2048”) - 总像素范围 [1280×720, 4096×4096],宽高比范围 [1/16, 16]
    • quality: 选择质量等级(standard 或 hd)
    • response_format: 选择返回格式(url 或 b64_json)
  3. 运行脚本:执行 Python 脚本即可生成图片

cURL 示例

如果你更喜欢使用 cURL 命令行工具:
curl -X POST "https://api.apiyi.com/v1/images/generations" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "model": "seedream-4-0-250828",
    "prompt": "A beautiful sunset over mountains with dramatic clouds",
    "size": "4K",
    "quality": "hd",
    "n": 1,
    "response_format": "url"
  }'

价格对比

模型官网价格API易价格折扣特点
SeeDream 4.0$0.03/张$0.025/张65%⭐ 4K高清,视觉一致性优秀
Nano Banana$0.04/张$0.025/张62.5%谷歌技术,10秒快速
GPT-Image-1更高--OpenAI技术
DALL·E 3按尺寸计费--经典模型
性价比建议:SeeDream 4.0 在高清图片生成方面表现出色,特别适合需要高质量、视觉一致性强的应用场景。结合充值加赠15%,实际成本约 ¥0.14/张。

特性对比

质量特点

  • 4K 高清输出:支持高分辨率图像生成
  • 视觉一致性:生成的图片风格统一,细节丰富
  • 响应速度:15秒左右完成生成,速度适中

API 特性

  • ✅ 标准 OpenAI Image API 格式
  • ✅ 支持多种图片尺寸
  • ✅ 支持 URL 和 Base64 两种返回格式
  • ✅ 按次计费,透明简单
  • ✅ 批量生成支持(n 参数)

支持的尺寸

SeeDream 4.0 支持两种尺寸设置方式:

方法1:分辨率规格

使用分辨率规格,让模型根据提示词中的描述自动决定最佳宽高比:
  • 1K - 约 1024×1024 像素
  • 2K - 约 2048×2048 像素
  • 4K - 约 4096×4096 像素

方法2:精确像素尺寸

直接指定宽度和高度(单位:像素):
  • 默认值2048x2048
  • 总像素范围:[1280×720, 4096×4096]
  • 宽高比范围:[1/16, 16]

常用尺寸示例:

  • 2048x2048 - 正方形(默认)
  • 1920x1080 - 16:9 横屏(Full HD)
  • 3840x2160 - 16:9 横屏(4K)
  • 1080x1920 - 9:16 竖屏(手机屏幕)
  • 2560x1440 - 16:9 横屏(2K)
注意:两种方法不能同时使用。选择其中一种即可。

常见问题

最佳实践

提示词优化

  1. 详细描述:提供具体的场景、风格、颜色等描述
  2. 添加质量标签:如 “4K”, “ultra detailed”, “high quality”
  3. 指定风格:如 “photorealistic”, “cartoon style”, “oil painting”
  4. 包含光线信息:如 “golden hour”, “soft lighting”, “dramatic shadows”

示例提示词

好的提示词:
"A majestic mountain landscape at golden hour, snow-capped peaks reflecting
warm sunlight, crystal clear lake in foreground, pine forests, ultra detailed,
4K resolution, photorealistic"

简单提示词:
"mountain landscape"  # 结果可能不够理想

相关资源

SeeDream 4.0 是 API易与 BytePlus 火山方舟达成战略合作后推出的高品质图像生成服务,持续优化中。如有问题或建议,欢迎访问飞书文档留言交流。