{
    "schema_version": "1.0",
    "id": "example:guide/video-create-and-poll",
    "origin": "maintained",
    "verification": "not_reported",
    "variants": [
        {
            "label": "curl",
            "language": "bash",
            "code": "# Create the job; it answers 202 with the job at once\nid=$(curl -s https://api.vultrinference.com/v1/videos \\\n  -H \"Authorization: Bearer $VULTR_INFERENCE_API_KEY\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\"model\": \"minimax-h3\", \"prompt\": \"A paper boat drifting down a rain-soaked street at dusk\", \"duration\": 4}' | jq -r .id)\n\n# Read it at its polling_url; while it runs, openai-poll-after-ms says how long to wait before reading again\ncurl -i https://api.vultrinference.com/v1/videos/$id \\\n  -H \"Authorization: Bearer $VULTR_INFERENCE_API_KEY\"\n",
            "sha256": "cbe655d19aef8a4323f5512cdcb4cd802b271a8b9e0cb5e4c3eadd2d12e45bd7"
        },
        {
            "label": "Python",
            "language": "python",
            "code": "import os\n\nfrom openai import OpenAI\n\nclient = OpenAI(base_url=\"https://api.vultrinference.com/v1\", api_key=os.environ[\"VULTR_INFERENCE_API_KEY\"])\n\n# Creates the job, then polls at the pace the API asks for (openai-poll-after-ms)\nvideo = client.videos.create_and_poll(\n    model=\"minimax-h3\",\n    prompt=\"A paper boat drifting down a rain-soaked street at dusk\",\n    seconds=\"4\",\n)\nprint(video.status)  # completed, or failed with video.error\n",
            "sha256": "ffa0e724e40064759f23e0fba014224f4cea33d122b2b4c5f56088bf0da1c761"
        },
        {
            "label": "TypeScript",
            "language": "typescript",
            "code": "import OpenAI from \"openai\";\n\nconst client = new OpenAI({ baseURL: \"https://api.vultrinference.com/v1\", apiKey: process.env.VULTR_INFERENCE_API_KEY });\n\nlet video = await client.videos.create({\n  model: \"minimax-h3\",\n  prompt: \"A paper boat drifting down a rain-soaked street at dusk\",\n  seconds: \"4\",\n});\n\n// Poll at the pace the API asks for: openai-poll-after-ms, on every answer while the job runs\nfor (let wait = 5000; video.status === \"queued\" || video.status === \"in_progress\"; ) {\n  await new Promise((resolve) => setTimeout(resolve, wait));\n  const { data, response } = await client.videos.retrieve(video.id).withResponse();\n  video = data;\n  wait = Number(response.headers.get(\"openai-poll-after-ms\") ?? wait);\n}\nconsole.log(video.status); // completed, or failed with video.error\n",
            "sha256": "96ec5387c57add048de417e7327b995288599d793b607df333ca128deb0258e9"
        }
    ]
}
