Communitygithub.com

Runway ML API 技能

通过 Runway ML API 实现 AI 视频生成与编辑——支持 Gen-3 Alpha Turbo、图像转视频和视频转视频。用于从文本或图像生成视频、应用 AI 视频特效或构建自动化创意视频制作流程。

Runway ML API 技能 是什么?

该技能封装了 Runway ML 的 REST API 以编程方式生成和编辑视频。它支持 Gen-3 Alpha Turbo 模型,可执行文本转视频和图像转视频任务,并遵循异步任务模式:创建任务、轮询完成状态以及下载结果。技能提供了清晰的 Python 代码示例,涵盖客户端设置、带可选种子的文本/图像输入生成、通过轮询处理长时间运行的任务以及文件下载。它支持多种宽高比和 5 或 10 秒的视频时长。此 API 面向开发者和 AI Agent,允许他们将 AI 视频生成集成到自动化流水线、用于创建电影预告片、产品动画或社交媒体内容。该技能还包括完整的端到端示例和实用指南,指导用户使用描述性提示、管理速率限制以及安全处理 API 密钥。

兼容平台✓Claude Code✓Codex CLI✓Cursor✓Gemini CLI
npx skills add https://github.com/TerminalSkills/skills/tree/HEAD/skills/runway-ml

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

Runway ML API

概述

Runway 的 Gen-3 Alpha Turbo 模型可根据文本提示或图像生成高质量视频。REST API 遵循异步任务模式:创建任务、轮询完成状态,然后下载结果。可用于制作电影短片、动画图像或构建自动化视频内容流水线。

设置

pip install requests python-dotenv
export RUNWAY_API_KEY="your_api_key_here"

基础 URL:https://api.dev.runwayml.com/v1
API 文档:https://docs.runwayml.com

核心概念

  • 任务:一个异步视频生成作业。立即返回 task_id。
  • Gen-3 Alpha Turbo:最快的 Gen-3 模型——最适合生产流水线。
  • 图像转视频(gen3a_turbo):将静态图像动画化为动态视频。
  • 文本转视频:仅根据文本提示生成视频。
  • 时长:5 或 10 秒。
  • 宽高比:1280:720(横屏)、720:1280(竖屏)、1104:832、832:1104、960:960(正方形)。

操作说明

步骤 1:设置客户端

import os
import time
import requests

API_KEY = os.environ["RUNWAY_API_KEY"]
BASE_URL = "https://api.dev.runwayml.com/v1"
HEADERS = {
    "Authorization": f"Bearer {API_KEY}",
    "Content-Type": "application/json",
    "X-Runway-Version": "2024-11-06"
}

步骤 2:文本转视频生成

def text_to_video(
    prompt_text: str,
    duration: int = 5,
    ratio: str = "1280:720",
    seed: int = None
) -> str:
    """提交一个文本转视频任务并返回 task_id。"""
    payload = {
        "model": "gen3a_turbo",
        "promptText": prompt_text,
        "duration": duration,
        "ratio": ratio
    }
    if seed is not None:
        payload["seed"] = seed

    r = requests.post(f"{BASE_URL}/image_to_video", json=payload, headers=HEADERS)
    r.raise_for_status()
    return r.json()["id"]

task_id = text_to_video(
    prompt_text="A drone shot flying over a misty mountain valley at golden hour, cinematic, slow motion",
    duration=5,
    ratio="1280:720"
)
print(f"任务已提交:{task_id}")

步骤 3:图像转视频生成

import base64
from pathlib import Path

def image_to_video(
    image_path: str,
    prompt_text: str = "",
    duration: int = 5,
    ratio: str = "1280:720",
    seed: int = None
) -> str:
    """将图像动画化为视频。image_path 可以是本地文件或 URL。"""

    if image_path.startswith("http"):
        prompt_image = image_path
    else:
        # 将本地文件编码为数据 URI
        img_bytes = Path(image_path).read_bytes()
        ext = Path(image_path).suffix.lstrip(".").lower()
        mime = {"jpg": "image/jpeg", "jpeg": "image/jpeg", "png": "image/png", "webp": "image/webp"}.get(ext, "image/png")
        b64 = base64.b64encode(img_bytes).decode()
        prompt_image = f"data:{mime};base64,{b64}"

    payload = {
        "model": "gen3a_turbo",
        "promptImage": prompt_image,
        "promptText": prompt_text,
        "duration": duration,
        "ratio": ratio
    }
    if seed is not None:
        payload["seed"] = seed

    r = requests.post(f"{BASE_URL}/image_to_video", json=payload, headers=HEADERS)
    r.raise_for_status()
    return r.json()["id"]

task_id = image_to_video(
    image_path="product_shot.png",
    prompt_text="The product slowly rotates, sparkling particles float around it, luxury feel",
    duration=5,
    ratio="1280:720"
)
print(f"任务已提交:{task_id}")

步骤 4:轮询任务状态

def get_task(task_id: str) -> dict:
    r = requests.get(f"{BASE_URL}/tasks/{task_id}", headers=HEADERS)
    r.raise_for_status()
    return r.json()

def wait_for_task(task_id: str, poll_interval: int = 5, timeout: int = 600) -> list[str]:
    """轮询直到任务完成;返回输出视频 URL 列表。"""
    start = time.time()
    while True:
        task = get_task(task_id)
        status = task["status"]
        progress = task.get("progress", 0)
        print(f"[{int(time.time()-start)}s] 状态:{status} ({int(progress*100)}%)")

        if status == "SUCCEEDED":
            return task["output"]  # 视频 URL 列表
        elif status in ("FAILED", "CANCELLED"):
            raise RuntimeError(f"任务 {status}:{task.get('failure', '')}")
        elif time.time() - start > timeout:
            raise TimeoutError(f"任务在 {timeout}s 内未完成")

        time.sleep(poll_interval)

output_urls = wait_for_task(task_id)
print(f"视频已就绪:{output_urls}")

步骤 5:下载结果

def download_video(url: str, output_path: str = "output.mp4") -> str:
    r = requests.get(url, stream=True)
    r.raise_for_status()
    with open(output_path, "wb") as f:
        for chunk in r.iter_content(chunk_size=8192):
            f.write(chunk)
    size_mb = os.path.getsize(output_path) / 1024 / 1024
    print(f"已保存:{output_path} ({size_mb:.1f} MB)")
    return output_path

download_video(output_urls[0], "mountain_valley.mp4")

完整流水线示例

def generate_and_download(prompt: str, output_path: str = "output.mp4", **kwargs) -> str:
    """一站式操作:根据文本生成视频并下载。"""
    print(f"正在生成:{prompt[:80]}...")
    task_id = text_to_video(prompt, **kwargs)
    urls = wait_for_task(task_id)
    return download_video(urls[0], output_path)

# 生成产品广告片段
generate_and_download(
    prompt="Close-up of a sleek smartphone on a white desk, screen lights up, smooth camera pull-back",
    output_path="product_ad.mp4",
    duration=5,
    ratio="1280:720"
)

参数参考

参数值说明
modelgen3a_turbo使用 Gen-3 Alpha Turbo(最快)
duration5、10视频长度(秒)
ratio1280:720、720:1280、1104:832、832:1104、960:960分辨率宽高比
seed整数用于确定性输出的可重复性种子
promptText字符串描述所需视频的文本提示
promptImageURL 或数据 URI图像转视频的起始图像

使用指南

  • Runway 任务耗时 30–120 秒,具体取决于时长和负载。
  • 输出 URL 有过期时间——生成后请尽快下载视频。
  • 保持提示描述性和电影感:包含镜头运动、光照、情绪。
  • 迭代提示时使用 seed 复现相同结果。
  • 对于批量生成,可并行提交任务但需遵守速率限制(检查 HTTP 429 状态码,并根据 Retry-After 标头值重试)。
  • 将 API 密钥存储在环境变量中——切勿硬编码。
  • 请查看 https://docs.runwayml.com 以获取最新的模型名称和端点,因为它们会频繁更新。

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

TerminalSkills/skills

>- Run GitHub Actions locally with act. Use when a user asks to test GitHub Actions workflows locally, debug CI pipelines without pushing, or run workflows offline.

TerminalSkills/skills

>- You are an expert in AG2 (formerly AutoGen), the open-source multi-agent conversation framework. You help developers build systems where multiple AI agents collaborate through structured conversations — with tool use, human-in-the-loop, code execution, group chat orchestration, and nested conversations — for complex tasks like software development, research, and data analysis.

TerminalSkills/skills

>- Generate short-form videos with AI — script writing, text-to-speech narration, stock footage selection, subtitle generation, and video assembly. Use when: creating TikTok/YouTube Shorts/Reels content, automating video production, building content pipelines.

TerminalSkills/skills

>- Animate 3D objects and characters in Blender with Python. Use when the user wants to keyframe properties, create armatures and rigs, set up IK/FK chains, animate shape keys for facial animation, edit F-Curves, use the NLA editor to blend actions, add drivers for expression-based animation, or script any animation workflow in Blender.

TerminalSkills/skills

>- Automate motion capture and tracking workflows in Blender with Python. Use when the user wants to import BVH or FBX mocap data, retarget motion to armatures, track camera or object motion from video, solve camera motion, clean up motion capture data, or script any tracking pipeline in Blender.

TerminalSkills/skills

>- You are an expert in Bolt.new by StackBlitz, the AI-powered full-stack development environment that runs entirely in the browser. You help developers go from idea to deployed app in minutes using natural language prompts — Bolt generates complete applications with frontend, backend, database, and deployment, all running in a WebContainer without local setup.

TerminalSkills/skills

>- Assists with using Bun as an all-in-one JavaScript/TypeScript runtime, package manager, bundler, and test runner. Use when building HTTP servers, managing packages, running tests, or migrating from Node.js. Trigger words: bun, bun serve, bun install, bun test, bun build, javascript runtime, bun runtime.

TerminalSkills/skills

>- Self-host customer support with Chatwoot. Use when a user asks to set up open-source customer support, add live chat without SaaS costs, build a multi-channel inbox, or deploy a free Intercom alternative.

TerminalSkills/skills

>- You are an expert in Chi, the lightweight, idiomatic Go HTTP router built on `net/http`. You help developers build composable HTTP services using Chi's middleware stack, route groups, URL parameters, sub-routers, and context-based request scoping — providing Express-like ergonomics while staying 100% compatible with Go's standard library.

TerminalSkills/skills

When the user wants to edit, review, or improve existing marketing copy. Also use when the user mentions 'edit this copy,' 'review my copy,' 'copy feedback,' 'proofread,' 'polish this,' 'make this better,' or 'copy sweep.' This skill provides a systematic approach to editing marketing copy through multiple focused passes.

TerminalSkills/skills

>- Add live chat and customer support with Crisp. Use when a user asks to add a chat widget, implement live customer support, set up a help desk, create a knowledge base, or add a chatbot to a website.

TerminalSkills/skills

>- Assists with building custom interactive data visualizations using D3.js. Use when creating charts, graphs, maps, force layouts, or hierarchical diagrams that require fine-grained control beyond what charting libraries provide. Trigger words: d3, data visualization, chart, svg, scales, force graph, treemap, choropleth.

TerminalSkills/skills

dbt (data build tool) transforms data in your warehouse using SQL SELECT statements. Learn project setup, models, tests, documentation, incremental materializations, and integration with data warehouses like PostgreSQL, BigQuery, and Snowflake.

TerminalSkills/skills

>- You are an expert in dlt, the open-source Python library for building data pipelines. You help developers load data from any API, file, or database into warehouses and lakes using simple Python decorators — with automatic schema inference, incremental loading, and built-in data contracts. dlt is the "requests library for data pipelines.

TerminalSkills/skills

Data Version Control for ML projects. Track large datasets and models alongside Git, build reproducible ML pipelines, and run experiments with metric comparison. Works with any storage backend including S3, GCS, Azure, and local filesystems.

TerminalSkills/skills

>- You are an expert in E2B, the cloud platform for running AI-generated code in secure sandboxes. You help developers give AI agents the ability to execute code, install packages, read/write files, and run long processes in isolated cloud environments — each sandbox is a lightweight VM that boots in ~150ms with full Linux, filesystem, and networking.

TerminalSkills/skills

>- Transcode, convert, edit, and process audio and video with FFmpeg. Use when a user asks to convert video formats (webm to mp4, mkv to mp4), extract audio from video, compress video files, trim or cut clips, concatenate videos, add subtitles, create thumbnails, apply filters, change resolution or bitrate, re-encode media, create GIFs from video, add watermarks, normalize audio, stream media, or build automated media processing pipelines.

TerminalSkills/skills

>- Create advanced animations with GSAP. Use when building complex timelines, scroll-driven animations, SVG morphing, text animations, or high-performance web animations beyond CSS capabilities.

TerminalSkills/skills

>- Generate deterministic MP4 videos from HTML, CSS, media, and seekable animations using HeyGen's HyperFrames framework. Use when someone asks to "render HTML to video", "make a video with HyperFrames", "create a programmatic video", "turn an animation into MP4", "build a launch/product video from HTML", "render GSAP/Lottie/Three.js to video", or set up an agent-driven video pipeline. Covers init/preview/render/add/lint/inspect commands, data-* timing attributes, animation adapters, and the component catalog.

TerminalSkills/skills

When the user wants to perform load testing, stress testing, or performance testing of APIs and websites using k6. Also use when the user mentions "k6," "load test," "performance test," "stress test," "spike test," "soak test," "thresholds," "virtual users," or "VUs." For browser-based testing, see selenium.

相关技能