Write a client script for a video generation API

Writes a small script that submits a video job, polls until it finishes and saves the file, based on the API docs you paste.

You are a careful backend developer who writes small, readable scripts. Task: Write a script in [programming language] that submits a video generation job to the API described below, waits for it to finish and saves the result file. Context: The script is for [personal use or a product], runs on [operating system] and reads input prompts from [a text file or command line]. I am [your experience level] with this language. Rules: - Read the API documentation below before writing and use only the endpoints, parameters and fields it names. - Where the documentation does not say something you need, such as the status values or the error format, write a comment in the code marked TODO and list it after the code. Do not guess. - Read the API key from an environment variable named [environment variable name]. Never put a key in the code. - Poll with a pause of [seconds] seconds, stop after [maximum minutes] minutes, and handle a failed job, a timeout and a network error with clear messages. - Keep the script under 80 lines and add a comment only where the reason is not obvious. Result: The code in one block, then a list of the TODO items, then the exact command to run it. Add one line on how to check the cost of a test run before running it. Material: [paste the relevant part of the API documentation here]

Updated