Skip to main content
To use a video generation model, you need to use the responses API. The API accepts text and image inputs, and returns generated videos as base64-encoded data.
Notice: We currently don’t offer any shared endpoints for video generation, so the examples below work with dedicated endpoints only.

Requirements

  • An API key. The code below assumes you set it in an environment variable:
  • The openai Python package. You can install it with this command:

Generate a video

To generate a video, set input to a text description of the video and set generation parameters in provider_options.image. The following example generates a video from a text prompt and saves it as output-text-to-video.mp4.
The generated video should look similar to the following:

Generate a video from an image

To generate a video from an image, set input to a user message containing:
  • An input_image block with an image URL or base64-encoded data URI.
  • An input_text block describing how to animate the image.
The following example reads a local image named input.png, encodes it as a data URI, and saves the generated video as output-image-to-video.mp4.