---
title: API Getting Started Guide
description: Learn how to use Runway Dev for AI video generation. Follow our step-by-step guide to integrate models from Runway and other leading labs, including ByteDance, Kling, OpenAI and Alibaba, into your apps.
---

Before starting, you will need to create a [Runway Dev account](/guides/setup).

## Talking to the API

You can use the <a href="https://dev.runway.com/playground" target="_blank">Playground</a> to test your code, or follow the examples below to get started.

<PillTabs>
<PillTabItem label="Generating Video">

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.

<Tabs>
  <TabItem label="Node">
    First, you'll want to install the Runway SDK. You can do this with npm:

````
```sh
npm install --save @runwayml/sdk
```

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

<Code code={codeSample`
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);
  }
}

`.trim()} lang="ts" />
````

  </TabItem>
  <TabItem label="Python">
    First, you'll want to install the Runway SDK. You can do this with pip:

````
```sh
pip install runwayml
```

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

<Code code={codeSample`
from runwayml import RunwayML, TaskFailedError

client = RunwayML()

# Create a new image-to-video task using the "seedance2_5" model
try:
  task = client.image_to_video.create(
    model='seedance2_5',
    # Point this at your own image file
    prompt_image='https://upload.wikimedia.org/wikipedia/commons/8/85/Tour_Eiffel_Wikimedia_Commons_(cropped).jpg',
    prompt_text='A timelapse on a sunny day with clouds flying by',
    ratio='1280:720',
    duration=5,
  ).wait_for_task_output()

  print('Task complete:', task)
except TaskFailedError as e:
  print('The video failed to generate.')
  print(e.task_details)

`.trim()} lang="python" />
````

  </TabItem>
  <TabItem label="Just testing">
    If you're not ready to start writing code, you can test the API with cURL.

````
```sh
# Replace the example URL below with your own image URL
curl -X POST https://api.dev.runwayml.com/v1/image_to_video \
  -d '{
    "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",
    "model": "seedance2_5",
    "ratio": "1280:720",
    "duration": 5
  }' \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $RUNWAYML_API_SECRET" \
  -H "X-Runway-Version: 2024-11-06"
```

This command will start an image-to-video task using the "seedance2_5" model. You'll
see a JSON response with the task ID printed in your terminal, which you can use to
fetch the task status.
````

  </TabItem>
</Tabs>

### 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](/assets/inputs) page.

<Tabs>
  <TabItem label="Node">
    <Code code={codeSample`
    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);
  }
}

`.trim()} lang="ts" />
```

  </TabItem>
  <TabItem label="Python">
    <Code code={codeSample`
    import base64
    from runwayml import RunwayML, TaskFailedError

```
client = RunwayML()

image = './example.png'

# Encode image to a data URI
with open(image, "rb") as f:
    # Read the file as a base64 encoded string
    base64_image = base64.b64encode(f.read()).decode("utf-8")
    # Format it as a data URI
    # We're using \`image/png\` here because the input is a PNG.
    data_uri = f"data:image/png;base64,{base64_image}"

# Create a new image-to-video task using the "seedance2_5" model
try:
  task = client.image_to_video.create(
    model='seedance2_5',
    # Point this at your own image file
    prompt_image=data_uri,
    prompt_text='A timelapse on a sunny day with clouds flying by',
    ratio='1280:720',
    duration=5,
  ).wait_for_task_output()

  print('Task complete:', task)
except TaskFailedError as e:
  print('The video failed to generate.')
  print(e.task_details)

`.trim()} lang="python" />
```

  </TabItem>
</Tabs>

### Text-to-video (without an input image)

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`.

<Tabs>
  <TabItem label="Node">
    <Code code={codeSample`
    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);
  }
}

`.trim()} lang="ts" />
```

  </TabItem>
  <TabItem label="Python">
    <Code code={codeSample`
    from runwayml import RunwayML, TaskFailedError

```
client = RunwayML()

# Create a new text-to-video task using the "seedance2_5" model
try:
  task = client.text_to_video.create(
    model='seedance2_5',
    # Text only: no prompt_image on POST /v1/text_to_video
    prompt_text='A serene mountain landscape at sunrise with mist rolling through the valleys',
    ratio='1280:720',
    duration=5,
  ).wait_for_task_output()

  print('Task complete:', task)
except TaskFailedError as e:
  print('The video failed to generate.')
  print(e.task_details)

`.trim()} lang="python" />
```

  </TabItem>
</Tabs>

</PillTabItem>
<PillTabItem label="Generating Images">

In this example, we'll use the `gen4_image` model to generate an image of the Eiffel Tower
rendered in the style of the painting Starry Night. To do this, we'll pass in reference images
of the Eiffel Tower and Starry Night, and use the `promptText` to specify that we want the
Eiffel Tower rendered in the style of Starry Night. Reference images can be referenced in the
text prompt using at-mention syntax referencing the `tag` of the reference image.

<Tabs>
  <TabItem label="Node">
    <Code code={codeSample`
    import RunwayML, { TaskFailedError } from '@runwayml/sdk';

```
const client = new RunwayML();

// Create a new image generation task using the "gen4_image" model
try {
  let task = await client.textToImage
    .create({
      model: 'gen4_image',
      ratio: '1920:1080',
      promptText: '@EiffelTower painted in the style of @StarryNight',
      referenceImages: [
        {
          uri: 'https://upload.wikimedia.org/wikipedia/commons/8/85/Tour_Eiffel_Wikimedia_Commons_(cropped).jpg'
          tag: 'EiffelTower',
        },
        {
          uri: 'https://upload.wikimedia.org/wikipedia/commons/thumb/e/ea/Van_Gogh_-_Starry_Night_-_Google_Art_Project.jpg/1513px-Van_Gogh_-_Starry_Night_-_Google_Art_Project.jpg',
          tag: 'StarryNight',
        },
      ],
    })
    .waitForTaskOutput();

  console.log('Task complete:', task);
  console.log('Image URL:', task.output[0]);
} catch (error) {
  if (error instanceof TaskFailedError) {
    console.error('The image failed to generate.');
    console.error(error.taskDetails);
  } else {
    console.error(error);
  }
}

`.trim()} lang="ts" />
```

  </TabItem>
  <TabItem label="Python">
    <Code code={codeSample`
    from runwayml import RunwayML, TaskFailedError

```
client = RunwayML()

try:
  task = client.text_to_image.create(
    model='gen4_image',
    ratio='1920:1080',
    prompt_text='@EiffelTower painted in the style of @StarryNight',
    reference_images=[
      {
        'uri': 'https://upload.wikimedia.org/wikipedia/commons/8/85/Tour_Eiffel_Wikimedia_Commons_(cropped).jpg',
        'tag': 'EiffelTower',
      },
      {
        'uri': 'https://upload.wikimedia.org/wikipedia/commons/thumb/e/ea/Van_Gogh_-_Starry_Night_-_Google_Art_Project.jpg/1513px-Van_Gogh_-_Starry_Night_-_Google_Art_Project.jpg',
        'tag': 'StarryNight',
      },
    ],
  ).wait_for_task_output()

  print('Task complete:', task)
  print('Image URL:', task.output[0])
except TaskFailedError as e:
  print('The image failed to generate.')
  print(e.task_details)
`.trim()} lang="python" />
```

  </TabItem>
  <TabItem label="Just testing">
    If you're not ready to start writing code, you can test the API with cURL.

````
```sh
# Replace the example URL below with your own image URL
curl -X POST https://api.dev.runwayml.com/v1/text_to_image \
  -d '{
    "promptText": "@EiffelTower painted in the style of @StarryNight",
    "model": "gen4_image",
    "ratio": "1920:1080",
    "referenceImages": [
      {
        "uri": "https://upload.wikimedia.org/wikipedia/commons/8/85/Tour_Eiffel_Wikimedia_Commons_(cropped).jpg",
        "tag": "EiffelTower"
      },
      {
        "uri": "https://upload.wikimedia.org/wikipedia/commons/thumb/e/ea/Van_Gogh_-_Starry_Night_-_Google_Art_Project.jpg/1513px-Van_Gogh_-_Starry_Night_-_Google_Art_Project.jpg",
        "tag": "StarryNight"
      }
    ]
  }' \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $RUNWAYML_API_SECRET" \
  -H "X-Runway-Version: 2024-11-06"
```
````

  </TabItem>
</Tabs>

### 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 `uri` of a `referenceImage`
object instead of a URL. For more information about file types and size limits, see the [Inputs](/assets/inputs)
page.

In this example, we'll use the `gen4_image` model to generate an image of a bunny facing the camera.
We provide a reference image of a rabbit that we use at-mention syntax to reference in the `promptText`.
We also provide an untagged reference image that the model will use to style the output image with.

<Tabs>
  <TabItem label="Node">
    <Code code={codeSample`
    import fs from 'node:fs';
    import path from 'node:path';
    import RunwayML, { TaskFailedError } from '@runwayml/sdk';

```
// Use the \`mime-types\` package to get the content type of the image file
// Install with \`npm install mime-types --save\`
import * as mime from 'mime-types';

const client = new RunwayML();

function getImageAsDataUri(imagePath: string) {
  // Read the image file
  const imageBuffer = fs.readFileSync(imagePath);

  // Convert to base64
  const base64String = imageBuffer.toString('base64');

  // Get the MIME type of the image file
  const contentType = mime.lookup(imagePath);

  return \`data:\${contentType};base64,\${base64String}\`;
}

// Create a new text-to-image task using the "gen4_image" model
try {
  const textToImage = await client.textToImage
    .create({
      model: 'gen4_image',
      promptText: '@bunny facing the camera',
      ratio: '1920:1080',
      referenceImages: [
        {
          uri: getImageAsDataUri('rabbit.png'),
          tag: 'bunny',
        },
        {
          uri: getImageAsDataUri('style.png'),
        },
      ],
    })
    .waitForTaskOutput();

  console.log('Task complete:', task);
} catch (error) {
  if (error instanceof TaskFailedError) {
    console.error('The image failed to generate.');
    console.error(error.taskDetails);
  } else {
    console.error(error);
  }
}
`.trim()} lang="ts" />
```

  </TabItem>
  <TabItem label="Python">
    <Code code={codeSample`
    import base64
    import mimetypes
    from runwayml import RunwayML, TaskFailedError

```
client = RunwayML()

def get_image_as_data_uri(image_path: str) -> str:
    with open(image_path, "rb") as f:
        base64_image = base64.b64encode(f.read()).decode("utf-8")
    content_type = mimetypes.guess_file_type(image_path)[0]
    return f"data:{content_type};base64,{base64_image}"

# Create a new text-to-image task using the "gen4_image" model
try:
  task = client.text_to_image.create(
    model='gen4_image',
    ratio='1920:1080',
    prompt_text='@bunny facing the camera',
    reference_images=[
      {
        'uri': get_image_as_data_uri('rabbit.png'),
        'tag': 'bunny',
      },
      {
        'uri': get_image_as_data_uri('style.png'),
      },
    ],
  ).wait_for_task_output()

  print('Task complete:', task)
except TaskFailedError as e:
  print('The image failed to generate.')
  print(e.task_details)

`.trim()} lang="python" />
```

  </TabItem>
</Tabs>

</PillTabItem>
</PillTabs>

## Additional Resources

* **[Runway Skills Repository](https://github.com/runwayml/skills)** - tools, code examples, and agent skills for Runway Dev
