Skip to main content
This recipe chains two APIs: image generation creates a still, and video generation animates it. You end up with a short .mp4, with a soundtrack if the video model supports audio. The trick that connects them: the image API returns the image as base64, and the video API accepts a base64 data: URI in input_reference. No upload step, no hosting.

The plan

1

Generate a still

POST /v1/images/generations returns the image in data[0].b64_json.
2

Create a video job from it

POST /v1/videos with input_reference set to a data: URI built from that base64. The prompt now describes the motion, not the scene.
3

Poll and download

Poll GET /v1/videos/{id} until completed, then download videos[0].url.

Full script

Notes

  • Write the video prompt for motion. The still already defines the scene. Describe what moves, and how the camera behaves.
  • Match the aspect ratios. The still above is 1280x720 (16:9) to match the video’s resolution: "720p". A mismatched reference gets cropped or padded by the model.
  • Pick a video model that supports image-to-video. Only models whose card on the video models page lists image-to-video accept input_reference. veo3.1-fast also generates audio; grok-imagine-video is a cheaper option that also carries built-in sound.
  • Cost: the image response reports its exact cost inline. The video is billed per second on completion; see video pricing.

Next steps

Image generation

All image parameters, models, and pricing.

Video generation

All video parameters, models, and pricing.