Skip to content
Kling 4.0 is on Runway Dev 20% off Through November 30 Get started

Before starting, you will need to create a Runway Dev account.

You can use the Playground to test your code, or follow the examples below to get started.

In this example, we’ll use the seedance2_5 model to generate a video from an image using the text prompt “A timelapse on a sunny day with clouds flying by”. When building this into your app, you’ll want to replace the promptImage with a URL of an image and a promptText with your own text prompt.

First, you’ll want to install the Runway SDK. You can do this with npm:

Terminal window
npm install --save @runwayml/sdk

In your code, you can now import the SDK and start making requests:

import RunwayML, { TaskFailedError } from '@runwayml/sdk';
const client = new RunwayML();
// Create a new image-to-video task using the "seedance2_5" model
try {
const task = await client.imageToVideo
.create({
model: 'seedance2_5',
// Point this at your own image file
promptImage: 'https://upload.wikimedia.org/wikipedia/commons/8/85/Tour_Eiffel_Wikimedia_Commons_(cropped).jpg',
promptText: 'A timelapse on a sunny day with clouds flying by',
ratio: '1280:720',
duration: 5,
})
.waitForTaskOutput();
console.log('Task complete:', task);
} catch (error) {
if (error instanceof TaskFailedError) {
console.error('The video failed to generate.');
console.error(error.taskDetails);
} else {
console.error(error);
}
}

Uploading base64 encoded images as data URIs

Section titled “Uploading base64 encoded images as data URIs”

You can also upload base64 encoded images (as a data URI) instead of pointing to an external URL. This can be useful if you’re working with a local image file and want to avoid an extra network round trip to upload the image.

To do this, simply pass the base64 encoded image string as a data URI in the promptImage field instead of a URL. For more information about file types and size limits, see the Inputs page.

import fs from 'node:fs';
import RunwayML, { TaskFailedError } from '@runwayml/sdk';
const client = new RunwayML();
// Read the image file into a Buffer. Replace `example.png` with your own image path.
const imageBuffer = fs.readFileSync('example.png');
// Convert to a data URI. We're using `image/png` here because the input is a PNG.
const dataUri = `data:image/png;base64,${imageBuffer.toString('base64')}`;
// Create a new image-to-video task using the "seedance2_5" model
try {
const task = await client.imageToVideo
.create({
model: 'seedance2_5',
// Point this at your own image file
promptImage: dataUri,
promptText: 'A timelapse on a sunny day with clouds flying by',
ratio: '1280:720',
duration: 5,
})
.waitForTaskOutput();
console.log('Task complete:', task);
} catch (error) {
if (error instanceof TaskFailedError) {
console.error('The video failed to generate.');
console.error(error.taskDetails);
} else {
console.error(error);
}
}

Seedance 2.5 also generates video from text alone, without an input image. Send text-only requests to POST /v1/text_to_video (client.textToVideo in Node, client.text_to_video in Python). POST /v1/image_to_video requires promptImage.

import RunwayML, { TaskFailedError } from '@runwayml/sdk';
const client = new RunwayML();
// Create a new text-to-video task using the "seedance2_5" model
try {
const task = await client.textToVideo
.create({
model: 'seedance2_5',
// Text only: no promptImage on POST /v1/text_to_video
promptText: 'A serene mountain landscape at sunrise with mist rolling through the valleys',
ratio: '1280:720',
duration: 5,
})
.waitForTaskOutput();
console.log('Task complete:', task);
} catch (error) {
if (error instanceof TaskFailedError) {
console.error('The video failed to generate.');
console.error(error.taskDetails);
} else {
console.error(error);
}
}

You can set custom tags via the X-Runway-Tags header to attribute a request’s credits to things like a team, environment, or project.

Terminal window
-H "X-Runway-Tags: team:growth,env:prod"

In the SDK, pass that header on the request options (headers in Node, extra_headers in Python). See Request tags for the tag rules and for reading the labels back from credit usage.