RunwayML Python SDK

4.12.0 · active · verified Thu Apr 16

The `runwayml` Python library provides convenient, type-safe access to the RunwayML REST API, allowing Python 3.9+ applications to integrate generative AI models. It offers both synchronous and asynchronous clients powered by `httpx`, with optional `aiohttp` support for improved concurrency. The library is actively maintained with frequent releases, incorporating new API features and bug fixes.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the RunwayML client with an API key from an environment variable and create an image-to-video generation task. It utilizes the SDK's built-in `wait_for_task_output()` method for simplified asynchronous task polling and includes basic error handling for common API failures.

import os
from runwayml import RunwayML, TaskFailedError

# Ensure RUNWAYML_API_SECRET is set in your environment or .env file
# Recommended: use python-dotenv for local development.
# Example: os.environ["RUNWAYML_API_SECRET"] = "key_YOUR_API_KEY_HERE"

client = RunwayML(
    api_key=os.environ.get("RUNWAYML_API_SECRET", "")
)

if not client.api_key:
    print("Error: RUNWAYML_API_SECRET environment variable not set.")
    print("Please set your RunwayML API key before running the quickstart.")
    exit(1)

try:
    # Example: Create an image-to-video task using Gen-4.5 model
    print("Creating image-to-video task...")
    image_to_video_task = client.image_to_video.create(
        model="gen4_turbo",
        prompt_image="https://example.com/assets/bunny.jpg",
        ratio="1280:720",
        prompt_text="The bunny is eating a carrot",
    ).wait_for_task_output() # SDK provides auto-polling

    print(f"Task completed. Generated video ID: {image_to_video_task.id}")
    # Further details like output URLs can be accessed via image_to_video_task.output

except TaskFailedError as e:
    print(f"Task failed: {e.taskDetails}")
    print("Check the error details for specific reasons like content moderation or invalid inputs.")
except Exception as e:
    print(f"An unexpected error occurred: {e}")

view raw JSON →