Gemini Omni 1.2
google/gemini-omni-1.2-flash makes video with sound from a prompt, frames, reference images and videos, and edits or extends a video. It is a job on POST /api/v1/videos.
Gemini Omni 1.2 Flash is Google's video model with native sound. A job takes 3 to 15 seconds at 360P to 4K, from text, one or two frames, reference images or reference videos, and a finished video can be edited, extended or continued in later turns. The rules every video job follows (submit, poll, download) are on the Video generation page.
Capabilities and limits
These values are the google/gemini-omni-1.2-flash row of the model tables on the Video generation page.
| Property | Value |
|---|---|
| Seconds | 3 to 15 (3 to 10 with a last frame) |
| Resolutions | 360P, 720P, 1080P, 4K (1080P and 4K are upscaled) |
| Ratios | 16:9, 9:16 |
| Prompt characters | Up to 4,000 |
| Text to video | Yes |
| First frame | Yes, as a PNG or JPEG: an https URL or a base64 data: image |
| First and last frame | Yes, 3 to 10 seconds |
| Reference images | Up to 6 |
| Reference videos | Up to 3 of 3 s, as uploaded files (1 for 11 to 15 s) |
| Audio input | Not supported |
generate_audio | Not accepted: sound is always generated |
| Edit and extend | An uploaded video or an earlier job |
Limits for uploaded videos
| Use | Length | File |
|---|---|---|
| Reference video | At most 3 seconds each; up to 3 for a 3 to 10 second clip, 1 for 11 to 15 seconds | MP4 or MOV |
| Source of an edit | 3 to 15 seconds; the result has the same length | MP4 or MOV, at most 32 MiB |
| Source of an extension | 3 to 27 seconds; the source plus the new seconds is at most 30 | MP4 or MOV, at most 32 MiB |
The same rule applies on both of Google's routes (Vertex AI and AI Studio), so a request that is accepted does not depend on which one serves it. The inputs of one request are at most 40 MiB before encoding on Vertex AI and fewer bytes on AI Studio until its larger bodies are proven; past the limit the answer is 400 input_too_large. Audio input is not supported. AI Hub reads an uploaded image or video for the request and keeps no second copy.
Request fields
| Field | Type | Rule |
|---|---|---|
model | string | Always google/gemini-omni-1.2-flash. |
prompt | string | Up to 4,000 characters. Describe speech in quotation marks and the sounds you want. |
duration | integer | 3 to 15 seconds (default 10); 3 to 10 with a last frame; 3 to 10 with task extend; left out with task edit. |
resolution | string | 360P, 720P (default), 1080P or 4K. With previous_job_id and no resolution, the earlier job's. |
aspect_ratio | string | 16:9 (default) or 9:16. Not with source_video or previous_job_id: the output follows the source (400 invalid_request). |
frame_images | array | A first_frame, and a last_frame beside it. Items are {type: image_url, image_url: {url}, frame_type}. |
input_references | array | One to six image_url items, or one to three video_url items (tokenhub://files/file_…). |
task | string | edit or extend. Required with source_video; optional with previous_job_id (default edit); 400 on its own. |
source_video | object | {type: video_url, video_url: {url}}, the url a tokenhub://files/file_… upload of an MP4 or MOV. |
previous_job_id | string | A completed job of the workspace to continue (job_…). |
Every new field is optional, and a request that sends one the route does not declare answers 400 unsupported_parameter naming it. Google advises describing the change in the prompt and using task only to edit or extend. A completed job from GET /api/v1/videos/{id} carries previous_job_id: the job it continues, or null.
Upload a video
Reference videos and sources are uploaded first. POST /api/v1/files answers with an upload slot, and the file's id goes into the request as tokenhub://files/<id>. A file belongs to the workspace of the key that uploaded it, is kept for 7 days, and is refused with the same answer when it is unknown, expired or another workspace's. A video is never accepted as an https URL or a data: value.
FILE=clip.mp4 BYTES=$(wc -c < "$FILE" | tr -d ' ') curl --fail-with-body -sS 'https://tokenhub-api.belive.sg/api/v1/files' \ -H "Authorization: Bearer $TOKENHUB_API_KEY" \ -H "Content-Type: application/json" \ -d "$(jq -n --argjson bytes "$BYTES" '{content_type: "video/mp4", bytes: $bytes}')" \ -o upload-slot.json # Upload the bytes to the slot, then use "tokenhub://files/$(jq -r .id upload-slot.json)".
Examples
One request for each feature, taken from runs on the AI Hub staging environment with the Vertex AI route and trimmed: the key is sk-tokenhub-…, a data: image is shortened to data:image/jpeg;base64,… and an uploaded video is tokenhub://files/file_…. Each request was a 360P clip of 3 seconds, so the amounts are the smallest the model charges; the AI Studio route ran the same cases at a similar price (first and last frame USD 0.0786 against 0.0808). Send each as in the quickstart, with an Idempotency-Key; a job answers 202 with {"id": "job_…", "generation_id": "req_…", "polling_url": …, "status": "pending"}, then poll it and download the result before content_expires_at. Replace the uploads and theprevious_job_id with yours.
Text to video
Audio is always on: the clip carries speech, sound and music the prompt describes. duration is 3 to 15 whole seconds; without one the clip is 10 seconds at 720P.
const body = { "model": "google/gemini-omni-1.2-flash", "prompt": "A calm abstract scene of slowly drifting orange and blue gradients, soft ambient tones. No people, no text, no logos.", "duration": 3, "resolution": "360P", "aspect_ratio": "16:9" }; const response = await fetch("https://tokenhub-api.belive.sg/api/v1/videos", { method: "POST", headers: { Authorization: "Bearer " + process.env.TOKENHUB_API_KEY, "Content-Type": "application/json", "Idempotency-Key": process.env.TOKENHUB_IDEMPOTENCY_KEY, }, body: JSON.stringify(body), }); if (!response.ok) throw new Error("Video submit failed: " + response.status); const job = await response.json(); console.log(job.id, job.polling_url);
curl --fail-with-body -sS 'https://tokenhub-api.belive.sg/api/v1/videos' \ -H "Authorization: Bearer $TOKENHUB_API_KEY" \ -H "Content-Type: application/json" \ -H "Idempotency-Key: $TOKENHUB_IDEMPOTENCY_KEY" \ -d '{ "model": "google/gemini-omni-1.2-flash", "prompt": "A calm abstract scene of slowly drifting orange and blue gradients, soft ambient tones. No people, no text, no logos.", "duration": 3, "resolution": "360P", "aspect_ratio": "16:9" }'
The finished job, from a poll:
{ "id": "job_ztk5byvo5m7wp1o20lg232emxx", "generation_id": "req_53jje1fu5xzqlgdovj93bgpdvd", "status": "completed", "model": "google/gemini-omni-1.2-flash", "usage": { "cost": 0.075438, "tokenhub_cost": "0.07543800", "is_byok": false } }
First and last frame
A first_frame and a last_frame; the prompt describes the change between them. Send the first_frame alone for a first frame only. Each is a PNG or JPEG: an https URL, which AI Hub fetches once (a public address, no redirect, at most 8 MiB) so Google never receives your URL, or a base64 data: image, as here. duration is 3 to 10 with a last frame; a longer one is 400 last_frame_duration. A last_frame alone is 400.
const body = { "model": "google/gemini-omni-1.2-flash", "prompt": "A smooth slow transition from the warm orange-and-blue gradient scene of the first frame to the green-and-cyan gradient scene of the last frame, soft ambient synth tones. No people, no text, no logos.", "duration": 3, "resolution": "360P", "aspect_ratio": "16:9", "frame_images": [ { "type": "image_url", "image_url": { "url": "data:image/jpeg;base64,…" }, "frame_type": "first_frame" }, { "type": "image_url", "image_url": { "url": "data:image/jpeg;base64,…" }, "frame_type": "last_frame" } ] }; const response = await fetch("https://tokenhub-api.belive.sg/api/v1/videos", { method: "POST", headers: { Authorization: "Bearer " + process.env.TOKENHUB_API_KEY, "Content-Type": "application/json", "Idempotency-Key": process.env.TOKENHUB_IDEMPOTENCY_KEY, }, body: JSON.stringify(body), }); if (!response.ok) throw new Error("Video submit failed: " + response.status); const job = await response.json(); console.log(job.id, job.polling_url);
curl --fail-with-body -sS 'https://tokenhub-api.belive.sg/api/v1/videos' \ -H "Authorization: Bearer $TOKENHUB_API_KEY" \ -H "Content-Type: application/json" \ -H "Idempotency-Key: $TOKENHUB_IDEMPOTENCY_KEY" \ -d '{ "model": "google/gemini-omni-1.2-flash", "prompt": "A smooth slow transition from the warm orange-and-blue gradient scene of the first frame to the green-and-cyan gradient scene of the last frame, soft ambient synth tones. No people, no text, no logos.", "duration": 3, "resolution": "360P", "aspect_ratio": "16:9", "frame_images": [ { "type": "image_url", "image_url": { "url": "data:image/jpeg;base64,…" }, "frame_type": "first_frame" }, { "type": "image_url", "image_url": { "url": "data:image/jpeg;base64,…" }, "frame_type": "last_frame" } ] }'
The staging case's result:
{ "job_id": "job_p6zgrlqm8ampg2yor9se2au0k5", "status": "completed", "billed_tokens": { "input": 2263, "text_output": 872, "video_output": 5793 }, "cost_usd": "0.08075850", "clip": "MP4, 640x360, 3.03 s, with sound" }
Reference images
One to six image_url items in input_references: subjects the clip keeps, up to three images of one character and two characters. Any duration. Not together with frame_images (400 mode_conflict); a seventh image is 400. This request sent six images; each data: value is shortened here.
const body = { "model": "google/gemini-omni-1.2-flash", "prompt": "Six abstract colour fields from the reference images drift together into one glowing mosaic, gentle chimes. No people, no text, no logos.", "duration": 3, "resolution": "360P", "aspect_ratio": "16:9", "input_references": [ { "type": "image_url", "image_url": { "url": "data:image/jpeg;base64,…" } }, { "type": "image_url", "image_url": { "url": "data:image/jpeg;base64,…" } }, { "type": "image_url", "image_url": { "url": "data:image/jpeg;base64,…" } }, { "type": "image_url", "image_url": { "url": "data:image/jpeg;base64,…" } }, { "type": "image_url", "image_url": { "url": "data:image/jpeg;base64,…" } }, { "type": "image_url", "image_url": { "url": "data:image/jpeg;base64,…" } } ] }; const response = await fetch("https://tokenhub-api.belive.sg/api/v1/videos", { method: "POST", headers: { Authorization: "Bearer " + process.env.TOKENHUB_API_KEY, "Content-Type": "application/json", "Idempotency-Key": process.env.TOKENHUB_IDEMPOTENCY_KEY, }, body: JSON.stringify(body), }); if (!response.ok) throw new Error("Video submit failed: " + response.status); const job = await response.json(); console.log(job.id, job.polling_url);
curl --fail-with-body -sS 'https://tokenhub-api.belive.sg/api/v1/videos' \ -H "Authorization: Bearer $TOKENHUB_API_KEY" \ -H "Content-Type: application/json" \ -H "Idempotency-Key: $TOKENHUB_IDEMPOTENCY_KEY" \ -d '{ "model": "google/gemini-omni-1.2-flash", "prompt": "Six abstract colour fields from the reference images drift together into one glowing mosaic, gentle chimes. No people, no text, no logos.", "duration": 3, "resolution": "360P", "aspect_ratio": "16:9", "input_references": [ { "type": "image_url", "image_url": { "url": "data:image/jpeg;base64,…" } }, { "type": "image_url", "image_url": { "url": "data:image/jpeg;base64,…" } }, { "type": "image_url", "image_url": { "url": "data:image/jpeg;base64,…" } }, { "type": "image_url", "image_url": { "url": "data:image/jpeg;base64,…" } }, { "type": "image_url", "image_url": { "url": "data:image/jpeg;base64,…" } }, { "type": "image_url", "image_url": { "url": "data:image/jpeg;base64,…" } } ] }'
The staging case's result:
{ "job_id": "job_7f0hr9311bcru8v1k7mpgrvflb", "status": "completed", "billed_tokens": { "input": 6645, "text_output": 849, "video_output": 5793 }, "cost_usd": "0.08712450", "clip": "MP4, 640x360, 3.03 s, with sound" }
Reference videos
One to three video_url items, each a tokenhub://files/file_… upload of an MP4 or MOV of at most 3 seconds. A clip of 3 to 10 seconds takes up to three; a clip of 11 to 15 seconds takes one. Their audio is ignored. Not together with frame_images, reference images, task or previous_job_id. The staging case sent its three clips inline; you send uploads.
const body = { "model": "google/gemini-omni-1.2-flash", "prompt": "A calm abstract montage that borrows the motion and colour of the three reference clips, soft ambient pad. No people, no text, no logos.", "duration": 3, "resolution": "360P", "aspect_ratio": "16:9", "input_references": [ { "type": "video_url", "video_url": { "url": "tokenhub://files/file_…" } }, { "type": "video_url", "video_url": { "url": "tokenhub://files/file_…" } }, { "type": "video_url", "video_url": { "url": "tokenhub://files/file_…" } } ] }; const response = await fetch("https://tokenhub-api.belive.sg/api/v1/videos", { method: "POST", headers: { Authorization: "Bearer " + process.env.TOKENHUB_API_KEY, "Content-Type": "application/json", "Idempotency-Key": process.env.TOKENHUB_IDEMPOTENCY_KEY, }, body: JSON.stringify(body), }); if (!response.ok) throw new Error("Video submit failed: " + response.status); const job = await response.json(); console.log(job.id, job.polling_url);
curl --fail-with-body -sS 'https://tokenhub-api.belive.sg/api/v1/videos' \ -H "Authorization: Bearer $TOKENHUB_API_KEY" \ -H "Content-Type: application/json" \ -H "Idempotency-Key: $TOKENHUB_IDEMPOTENCY_KEY" \ -d '{ "model": "google/gemini-omni-1.2-flash", "prompt": "A calm abstract montage that borrows the motion and colour of the three reference clips, soft ambient pad. No people, no text, no logos.", "duration": 3, "resolution": "360P", "aspect_ratio": "16:9", "input_references": [ { "type": "video_url", "video_url": { "url": "tokenhub://files/file_…" } }, { "type": "video_url", "video_url": { "url": "tokenhub://files/file_…" } }, { "type": "video_url", "video_url": { "url": "tokenhub://files/file_…" } } ] }'
The staging case's result:
{ "job_id": "job_m3ia8bklvmoq1mclaxbr6cg9pu", "status": "completed", "billed_tokens": { "input": 17425, "text_output": 852, "video_output": 5793 }, "cost_usd": "0.10332150", "clip": "MP4, 640x360, 3.03 s, with sound" }
Edit an uploaded video
task: "edit" with a source_video of 3 to 15 seconds. The clip is as long as the source and has its shape, so leave duration out (another value is 400) and aspect_ratio out (400 invalid_request). Up to 2 input_references images are allowed. resolution is optional and is honoured. The staging case sent the 3-second source inline; you send the upload.
const body = { "model": "google/gemini-omni-1.2-flash", "prompt": "Restyle the clip as a hand-painted watercolour animation, keeping its motion and its tone. No people, no text, no logos.", "task": "edit", "source_video": { "type": "video_url", "video_url": { "url": "tokenhub://files/file_…" } }, "resolution": "360P" }; const response = await fetch("https://tokenhub-api.belive.sg/api/v1/videos", { method: "POST", headers: { Authorization: "Bearer " + process.env.TOKENHUB_API_KEY, "Content-Type": "application/json", "Idempotency-Key": process.env.TOKENHUB_IDEMPOTENCY_KEY, }, body: JSON.stringify(body), }); if (!response.ok) throw new Error("Video submit failed: " + response.status); const job = await response.json(); console.log(job.id, job.polling_url);
curl --fail-with-body -sS 'https://tokenhub-api.belive.sg/api/v1/videos' \ -H "Authorization: Bearer $TOKENHUB_API_KEY" \ -H "Content-Type: application/json" \ -H "Idempotency-Key: $TOKENHUB_IDEMPOTENCY_KEY" \ -d '{ "model": "google/gemini-omni-1.2-flash", "prompt": "Restyle the clip as a hand-painted watercolour animation, keeping its motion and its tone. No people, no text, no logos.", "task": "edit", "source_video": { "type": "video_url", "video_url": { "url": "tokenhub://files/file_…" } }, "resolution": "360P" }'
The staging case's result:
{ "job_id": "job_8mszfokgd1jotl6dor8pzea5mj", "status": "completed", "billed_tokens": { "input": 5837, "text_output": 279, "video_output": 5793 }, "cost_usd": "0.08078250", "clip": "MP4, 640x360, 3.03 s, with sound" }
Extend an uploaded video
task: "extend" adds duration seconds, 3 to 10, to a source_video of 3 to 27 seconds. The result is the source followed by the continuation, and the two together are at most 30 seconds: here a 3-second source and 3 more seconds give a 6.04-second clip. aspect_ratio is 400 invalid_request, as with an edit. Google continues from the last 10 seconds of the source.
const body = { "model": "google/gemini-omni-1.2-flash", "prompt": "Continue the clip for three more seconds, the colours slowly turning from violet to green, the tone rising. No people, no text, no logos.", "task": "extend", "source_video": { "type": "video_url", "video_url": { "url": "tokenhub://files/file_…" } }, "duration": 3, "resolution": "360P" }; const response = await fetch("https://tokenhub-api.belive.sg/api/v1/videos", { method: "POST", headers: { Authorization: "Bearer " + process.env.TOKENHUB_API_KEY, "Content-Type": "application/json", "Idempotency-Key": process.env.TOKENHUB_IDEMPOTENCY_KEY, }, body: JSON.stringify(body), }); if (!response.ok) throw new Error("Video submit failed: " + response.status); const job = await response.json(); console.log(job.id, job.polling_url);
curl --fail-with-body -sS 'https://tokenhub-api.belive.sg/api/v1/videos' \ -H "Authorization: Bearer $TOKENHUB_API_KEY" \ -H "Content-Type: application/json" \ -H "Idempotency-Key: $TOKENHUB_IDEMPOTENCY_KEY" \ -d '{ "model": "google/gemini-omni-1.2-flash", "prompt": "Continue the clip for three more seconds, the colours slowly turning from violet to green, the tone rising. No people, no text, no logos.", "task": "extend", "source_video": { "type": "video_url", "video_url": { "url": "tokenhub://files/file_…" } }, "duration": 3, "resolution": "360P" }'
The staging case's result:
{ "job_id": "job_rexey5sm7lyefddpr1bfy447p7", "status": "completed", "billed_tokens": { "input": 5845, "text_output": 219, "video_output": 5793 }, "cost_usd": "0.08025450", "clip": "MP4, 640x360, 6.04 s, with sound" }
Continue an earlier job: edit
previous_job_id names a completed Gemini Omni 1.2 job of your workspace, here the text-to-video job of the first example. task is edit by default. This request sent no resolution, so the child inherited its parent's 360P and was priced at 360P. No aspect_ratio, input_references, frame_images or source_video with it.
const body = { "model": "google/gemini-omni-1.2-flash", "prompt": "Restyle the clip as a hand-painted watercolour animation. No people, no text, no logos.", "previous_job_id": "job_ztk5byvo5m7wp1o20lg232emxx" }; const response = await fetch("https://tokenhub-api.belive.sg/api/v1/videos", { method: "POST", headers: { Authorization: "Bearer " + process.env.TOKENHUB_API_KEY, "Content-Type": "application/json", "Idempotency-Key": process.env.TOKENHUB_IDEMPOTENCY_KEY, }, body: JSON.stringify(body), }); if (!response.ok) throw new Error("Video submit failed: " + response.status); const job = await response.json(); console.log(job.id, job.polling_url);
curl --fail-with-body -sS 'https://tokenhub-api.belive.sg/api/v1/videos' \ -H "Authorization: Bearer $TOKENHUB_API_KEY" \ -H "Content-Type: application/json" \ -H "Idempotency-Key: $TOKENHUB_IDEMPOTENCY_KEY" \ -d '{ "model": "google/gemini-omni-1.2-flash", "prompt": "Restyle the clip as a hand-painted watercolour animation. No people, no text, no logos.", "previous_job_id": "job_ztk5byvo5m7wp1o20lg232emxx" }'
The finished job, from a poll:
{ "id": "job_xh3w75bmawd0476id8xjl45t46", "generation_id": "req_zkfvkm5q0fnet41gekwlyskynn", "status": "completed", "model": "google/gemini-omni-1.2-flash", "previous_job_id": "job_ztk5byvo5m7wp1o20lg232emxx", "usage": { "cost": 0.0804525, "tokenhub_cost": "0.08045250", "is_byok": false } }
Continue an earlier job: extend
Send task: "extend" and a duration to continue the clip. The job's output is the earlier clip plus the new 3 seconds (6 seconds here), and it is billed for the new seconds' video tokens plus the history it carries as input (see Pricing).
const body = { "model": "google/gemini-omni-1.2-flash", "prompt": "Continue the clip for three more seconds, the colours slowly turning from violet to green.", "previous_job_id": "job_xh3w75bmawd0476id8xjl45t46", "task": "extend", "duration": 3 }; const response = await fetch("https://tokenhub-api.belive.sg/api/v1/videos", { method: "POST", headers: { Authorization: "Bearer " + process.env.TOKENHUB_API_KEY, "Content-Type": "application/json", "Idempotency-Key": process.env.TOKENHUB_IDEMPOTENCY_KEY, }, body: JSON.stringify(body), }); if (!response.ok) throw new Error("Video submit failed: " + response.status); const job = await response.json(); console.log(job.id, job.polling_url);
curl --fail-with-body -sS 'https://tokenhub-api.belive.sg/api/v1/videos' \ -H "Authorization: Bearer $TOKENHUB_API_KEY" \ -H "Content-Type: application/json" \ -H "Idempotency-Key: $TOKENHUB_IDEMPOTENCY_KEY" \ -d '{ "model": "google/gemini-omni-1.2-flash", "prompt": "Continue the clip for three more seconds, the colours slowly turning from violet to green.", "previous_job_id": "job_xh3w75bmawd0476id8xjl45t46", "task": "extend", "duration": 3 }'
The finished job, from a poll:
{ "id": "job_0wz9bnj1fb482emf96439mhi9d", "generation_id": "req_33eptndkpkoeh6dh8vk42n7r1t", "status": "completed", "model": "google/gemini-omni-1.2-flash", "previous_job_id": "job_xh3w75bmawd0476id8xjl45t46", "usage": { "cost": 0.093165, "tokenhub_cost": "0.09316500", "is_byok": false } }
Poll and download
import json import os import time import urllib.request job_id = os.environ["TOKENHUB_VIDEO_JOB_ID"] url = "https://tokenhub-api.belive.sg/api/v1/videos/" + job_id headers = {"Authorization": f"Bearer {os.environ['TOKENHUB_API_KEY']}"} for attempt in range(120): request = urllib.request.Request(url, headers=headers) with urllib.request.urlopen(request, timeout=30) as response: job = json.load(response) print(job["status"]) if job["status"] not in ("pending", "in_progress"): break time.sleep(3) else: raise TimeoutError("Job is still running; poll it again later") print(json.dumps(job, indent=2))
const jobId = process.env.TOKENHUB_VIDEO_JOB_ID; let job; for (let attempt = 0; attempt < 120; attempt++) { const response = await fetch("https://tokenhub-api.belive.sg/api/v1/videos/" + encodeURIComponent(jobId), { headers: { Authorization: "Bearer " + process.env.TOKENHUB_API_KEY }, }); if (!response.ok) throw new Error("Video poll failed: " + response.status); job = await response.json(); console.log(job.status); if (job.status !== "pending" && job.status !== "in_progress") break; if (attempt === 119) throw new Error("Job is still running; poll it again later"); await new Promise((resolve) => setTimeout(resolve, 3000)); } console.log(job);
curl --fail-with-body -sS "https://tokenhub-api.belive.sg/api/v1/videos/$TOKENHUB_VIDEO_JOB_ID" \ -H "Authorization: Bearer $TOKENHUB_API_KEY"
import os import shutil import urllib.error import urllib.request job_id = os.environ["TOKENHUB_VIDEO_JOB_ID"] request = urllib.request.Request( "https://tokenhub-api.belive.sg/api/v1/videos/" + job_id + "/content", headers={"Authorization": f"Bearer {os.environ['TOKENHUB_API_KEY']}"}, ) class NoRedirect(urllib.request.HTTPRedirectHandler): def redirect_request(self, req, fp, code, msg, headers, newurl): return None opener = urllib.request.build_opener(NoRedirect()) try: response = opener.open(request, timeout=60) except urllib.error.HTTPError as response: if response.code != 302: raise download_url = response.headers.get("Location") if not download_url: raise RuntimeError("Missing redirect Location") response.close() # This request goes to the CDN without the AI Hub Authorization header. response = urllib.request.urlopen(download_url, timeout=120) with response, open("video.mp4", "wb") as output: shutil.copyfileobj(response, output)
import { writeFile } from "node:fs/promises"; const jobId = process.env.TOKENHUB_VIDEO_JOB_ID; const response = await fetch( "https://tokenhub-api.belive.sg/api/v1/videos/" + encodeURIComponent(jobId) + "/content", { headers: { Authorization: "Bearer " + process.env.TOKENHUB_API_KEY }, redirect: "manual", }, ); let video = response; if (response.status === 302) { const location = response.headers.get("location"); if (!location) throw new Error("Missing redirect Location"); // Fetch the CDN URL without the AI Hub Authorization header. video = await fetch(location); } if (!video.ok) throw new Error("Video download failed: " + video.status); await writeFile("video.mp4", Buffer.from(await video.arrayBuffer()));
curl --fail-with-body -sS -L --proto-redir '=https' \ "https://tokenhub-api.belive.sg/api/v1/videos/$TOKENHUB_VIDEO_JOB_ID/content" \ -H "Authorization: Bearer $TOKENHUB_API_KEY" \ -o video.mp4
Edit, extend and multi-turn
- Edit or extend an uploaded video:
source_videowithtaskeditorextend, as above. Speech cannot be added to an uploaded video that already has speech. - Multi-turn:
previous_job_idcontinues a job of your workspace. The earlier job must be an Omni 1.2 job that has completed, at most 7 days old. The new job runs on the same route and, with your own Google key, the same key. Only the earlier job's history carries over. A job that sends noresolutiontakes its parent's; send one to change it. Send noaspect_ratio: the output follows the earlier video. - Voice in a longer clip: adding or continuing speech across turns works only through
previous_job_id; it does not work on an uploaded video. - Length: an extension adds 3 to 10 seconds, and the earlier video plus the new seconds is at most 30.
- Each turn's input includes the turns before it, so input tokens grow with the length of the chain and a chain has a depth limit (
409 previous_job_depth).
Region rule and content
- Google does not allow editing or extending an uploaded video for users in the European Economic Area, Switzerland and the United Kingdom. AI Hub does not know where your end user is and has no country check. Google's refusal comes back as
400 invalid_requestwithmetadata.reasonregion_restricted, nothing is priced, and you must observe the rule for your users. - Editing or extending a video the model generated (
previous_job_id) works everywhere. - Images of minors cannot be uploaded or edited in those regions.
- Google's input and output filters can refuse an input or a result, for example one that shows a recognisable person or a minor. Google's refusal comes back as a
4xxerror and is never charged. AI Hub does not moderate uploads itself; the AI Hub terms apply to what you upload.
Retention and Google's stored copy
- Uploaded files are kept 7 days. A finished video can be loaded for 7 days, and a job can be continued for 7 days after it was created.
- A job runs as a stored interaction at Google, which keeps the prompt, the inputs and the output for its retention period (up to 7 days on AI Hub's projects; with your own key, the period set on your Google project).
- Deleting an AI Hub upload or job does not remove Google's stored interaction.
Pricing
Prices follow Google's list prices for the model, per million tokens: input of text, image and video at USD 1.50; output text at USD 9.00; output video at USD 12.00. A job is priced on the tokens Google reports for it. The video it makes is a fixed number of tokens for each second at each resolution:
| Resolution | Video tokens per second | About, per second of video |
|---|---|---|
| 360P | 1,931 | USD 0.023 |
| 720P | 5,792 | USD 0.070 |
| 1080P | 8,688 | USD 0.104 |
| 4K | 17,376 | USD 0.209 |
Frames, reference images and an uploaded video are input and are priced at the input rate. An uploaded video is about 1,931 input tokens for each second at 360P, so a 3-second source adds about 5,800 input tokens. An extension's clip is the source followed by the continuation, but it is billed for the video tokens of the continuation only, plus the input tokens carried from the source or, with previous_job_id, from the earlier turns. The 3-second extension above billed 5,845 input tokens and 5,793 video tokens for a 6-second clip. A job that fails, is refused or returns a clip that does not match its request costs nothing. A running job cannot be cancelled, because Google prices the tokens generated before a cancel; a job that is still queued can. The price table of the model on GET /api/v1/videos/models is the source of the amounts. With your own Google key the tokens are priced on your Google project and the job's usage.cost is AI Hub's BYOK fee, currently 5% of the AI Hub price of the same request. A staging chain on a workspace's own AI Studio key (a text-to-video job, an edit and an extension of it) showed usage.cost 0.00371715, 0.0040368 and 0.00458745 with is_byok true, which are 5% of 0.074343, 0.080736 and 0.091749. See Bring your own key.
Errors
Limits are applied before anything is started, so each of these costs nothing and starts no job. See Errors and recovery for the envelope; the code that tells these cases apart is error.metadata.reason.
| Status | type | metadata.reason | When |
|---|---|---|---|
400 | unsupported_parameter | seed, negative_prompt, generate_audio or size, an audio_url item, or a field the route does not declare. | |
400 | invalid_request | image_url_unreachableimage_url_refused | The first-frame https URL could not be fetched, or is not a PNG or JPEG of at most 8 MiB. |
400 | invalid_request | aspect_ratio together with source_video or previous_job_id. | |
400 | invalid_request | last_frame_duration | A last_frame with a duration over 10. |
400 | invalid_request | mode_conflict | Reference images and videos together; references beside frame_images; source_video or previous_job_id beside frames or reference videos. |
400 | invalid_request | reference_video_countreference_video_lengthreference_video_type | More reference videos than the output length allows, one longer than 3 seconds, or not an MP4 or MOV. |
400 | invalid_request | source_video_lengthsource_video_typesource_video_size | A source outside 3 to 15 seconds (edit) or 3 to 27 seconds (extend), not an MP4 or MOV, or over 32 MiB. |
400 | invalid_request | total_length_exceeded | An extension whose result would pass 30 seconds. |
400 | invalid_request | input_too_large | The inputs sent together are over the size limit. Nothing is held or priced. |
400 | invalid_request | region_restricted | Google refused to edit or extend an uploaded video for the end user's region (see Region rule). |
400 | invalid_request | previous_job_provider_excluded | A provider preference leaves out the route that ran the earlier job. |
404 | not_found | job_not_found | previous_job_id is unknown or belongs to another workspace; the answers are the same. |
409 | conflict | previous_job_not_ready | The earlier job has not completed. |
409 | conflict | previous_job_expired | The earlier job is more than 7 days old, or Google no longer holds it. |
409 | conflict | previous_job_route_unavailable | The route that ran the earlier job is not available. A continuation never moves to another route. |
409 | conflict | previous_job_key_changed | The earlier job ran on a key that was replaced or removed, or on the other key source (shared or your own Google key). |
409 | conflict | previous_job_depth | The chain is at its depth limit. Start a new job from the last video. |