← 返回
未分类 Key

Doubao API Toolkit

Doubao (Volcengine ARK) API Toolkit - Cross-platform Python implementation for text-to-image, image-to-image, text-to-video, and vision analysis. 豆包API工具包 -...
豆包(VolcengineARK)API工具包 - 跨平台Python实现,支持文本生成图像、图像生成图像、文本生成视频及视觉分析功能。
systiger
未分类 clawhub v1.0.0 1 版本 100000 Key: 需要
★ 0
Stars
📥 395
下载
💾 1
安装
1
版本
#latest

概述

Doubao API Toolkit / 豆包 API 工具包

> English: A cross-platform Python toolkit for Doubao (ByteDance Volcengine ARK) API, supporting text-to-image, text-to-video, image/video analysis, and more.

>

> 中文: 豆包(字节跳动火山引擎ARK)API的跨平台Python工具包,支持文生图、文生视频、图片/视频分析等功能。


🚀 Quick Start / 快速开始

Prerequisites / 前置条件

  • English: Python 3.8+ with requests library
  • 中文: Python 3.8+ 及 requests
pip install requests

Configuration / 配置

Set your ARK API Key as an environment variable:

将 ARK API Key 设置为环境变量:

# Linux/Mac
export ARK_API_KEY="your_api_key_here"

# Windows PowerShell
$env:ARK_API_KEY="your_api_key_here"

# Windows CMD
set ARK_API_KEY=your_api_key_here

Get your API Key from: https://console.volcengine.com/ark

从控制台获取 API Key:https://console.volcengine.com/ark


📚 Usage / 使用方法

1. Generate Image from Text / 文生图

English: Generate an image using text description

中文: 使用文本描述生成图片

python doubao_toolkit.py img "一只可爱的橘猫在阳光下睡觉" --size 1024x1024

Output / 输出:

{
  "status": "success",
  "image_url": "https://...",
  "local_path": "/path/to/img_20260322_201500.jpeg",
  "prompt": "一只可爱的橘猫在阳光下睡觉"
}

2. Generate Video from Text / 文生视频

English: Generate a video using text description

中文: 使用文本描述生成视频

# Synchronous mode (wait for completion) / 同步模式(等待完成)
python doubao_toolkit.py vid "一只猫在草地上奔跑" --duration 5 --ratio 16:9

# Asynchronous mode (return task ID) / 异步模式(返回任务ID)
python doubao_toolkit.py vid "一只猫在草地上奔跑" --duration 5 --async

3. Generate Video from Image / 图生视频

English: Generate video using an image as the first frame

中文: 使用图片作为首帧生成视频

python doubao_toolkit.py vid "让这只猫动起来" --image "https://example.com/cat.jpg"

4. Analyze Image / 图片分析

English: Analyze image content using vision model

中文: 使用视觉模型分析图片内容

python doubao_toolkit.py analyze-img "https://example.com/image.jpg" --prompt "描述这张图片的细节"

5. Analyze Video / 视频分析

English: Analyze video content using vision model

中文: 使用视觉模型分析视频内容

python doubao_toolkit.py analyze-vid "/path/to/video.mp4" --prompt "总结这个视频的主要内容"

6. Check Video Status / 检查视频状态

English: Check the status of a video generation task

中文: 检查视频生成任务的状态

python doubao_toolkit.py status "cgt-20260322xxxxx"

🔧 Available Models / 可用模型

Model IDFunctionDescription
---------------------------------
doubao-seedream-3-0-t2i-250415Text-to-Image / 文生图Generate images from text
doubao-seededit-3-0-i2i-250628Image-to-Image / 图生图Edit images
doubao-seedance-1-0-pro-250528Text-to-Video / 文生视频Generate videos from text or images
doubao-1-5-vision-pro-32k-250115Vision Analysis / 视觉分析Analyze images and videos
doubao-1-5-pro-32k-250115Chat / 对话General chat and text generation

📖 API Reference / API 参考

Class: DoubaoClient

generate_image(prompt, size="1024x1024", n=1)

English: Generate image from text description

中文: 根据文本描述生成图片

Parameters / 参数:

  • prompt (str): Text description / 文本描述
  • size (str): Image size (1024x1024, 1024x1536, 1536x1024) / 图片尺寸
  • n (int): Number of images to generate / 生成数量

Returns / 返回:

{
    "status": "success",
    "image_url": "https://...",
    "local_path": "/path/to/image.jpeg",
    "prompt": "..."
}

generate_video(prompt, duration=5, ratio="16:9", image_url=None, sync=True)

English: Generate video from text or image

中文: 根据文本或图片生成视频

Parameters / 参数:

  • prompt (str): Text description / 文本描述
  • duration (int): Video duration in seconds (2-12) / 视频时长(秒)
  • ratio (str): Aspect ratio (16:9, 4:3, 1:1, 9:16) / 宽高比
  • image_url (str, optional): Image URL for image-to-video / 图生视频的图片URL
  • sync (bool): Wait for completion if True / 是否同步等待

analyze_image(image_url, prompt="描述这张图片")

English: Analyze image content

中文: 分析图片内容

Parameters / 参数:

  • image_url (str): URL of the image / 图片URL
  • prompt (str): Analysis prompt / 分析提示词

Returns / 返回: Analysis result text / 分析结果文本

analyze_video(video_path, prompt="分析这个视频")

English: Analyze video content

中文: 分析视频内容

Parameters / 参数:

  • video_path (str): Path to local video file / 本地视频文件路径
  • prompt (str): Analysis prompt / 分析提示词

📊 Performance / 性能指标

OperationExpected TimeNotes
---------------------------------
Text-to-Image / 文生图10-30 secondsDepends on complexity
Text-to-Video / 文生视频1-3 minutes5-second video
Image Analysis / 图片分析5-15 secondsDepends on image size
Video Analysis / 视频分析10-30 secondsDepends on video length

🐛 Troubleshooting / 故障排除

Error: "ARK_API_KEY environment variable not set"

Solution / 解决方法:

export ARK_API_KEY="your_api_key"

Error: "InvalidEndpointOrModel.NotFound"

English: The model is not activated. Go to Volcengine Console → Model Management and activate the required models.

中文: 模型未开通。请前往火山引擎控制台 → 模型管理,开通所需模型。

Required models / 需要开通的模型:

  • Doubao-SeeDream-3.0-T2I (Text-to-Image)
  • Doubao-Seedance-1.0-Pro (Text-to-Video)
  • Doubao-1.5-Vision-Pro (Vision Analysis)

Error: "Insufficient balance"

English: Your account balance is insufficient. Please recharge your account.

中文: 账户余额不足,请充值。


🔐 Security / 安全

English:

  • Never hardcode API keys in your code
  • Use environment variables to store sensitive information
  • Regularly rotate your API keys

中文:

  • 永远不要在代码中硬编码 API Key
  • 使用环境变量存储敏感信息
  • 定期轮换 API Key

📁 Output Directory / 输出目录

Generated files are saved to:

生成的文件保存在:

~/.openclaw/workspace/output/
├── img_YYYYMMDD_HHMMSS.jpeg    # Generated images / 生成的图片
└── vid_YYYYMMDD_HHMMSS.mp4     # Generated videos / 生成的视频

📚 References / 参考资源


Version / 版本: 1.0.0

Last Updated / 最后更新: 2026-03-22

版本历史

共 1 个版本

  • v1.0.0 当前
    2026-05-03 07:58 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

AI Animation Studio

systiger
自动将用户故事转为分镜与动画视频,支持多风格、自动配音、字幕和背景音乐。
★ 0 📥 625

Ai Animation Studio

systiger
自动将故事转分镜并生成风格化动画视频,支持双模式、自动配音、字幕烧录及30+首BGM。
★ 0 📥 413

Skill Memory

systiger
将任务路由至预设参数的首选技能,支持图片、视频、截图、语音合成、新闻聚合和热门话题。
★ 0 📥 440