Jobs, polling, and downloads
Poll a dub job to completion and retrieve its presigned MP3 URL.
Creating or confirming an upload returns a job. A job moves through queued, separation, transcription, translation, synthesis, mixing, and upload stages before becoming completed or failed.
Poll a job
There is no SSE endpoint. Poll getDub while a job is active, then stop as soon as it reaches a terminal state.
import { getDub } from "@ai-dubbing/sdk";
const terminal = new Set(["completed", "failed"]);
async function waitForJob(id: string) {
for (;;) {
const { data: job } = await getDub({
path: { id },
throwOnError: true,
});
if (terminal.has(job.status)) return job;
await new Promise((resolve) => setTimeout(resolve, 2_500));
}
}Polling every 2.5 seconds is the same interval used by the dashboard. Do not poll completed or failed jobs.
TanStack Query through your application server
Do not expose an API key in React. If a browser needs progress, expose a narrowly scoped endpoint in your application server and let TanStack Query poll that endpoint:
import { useQuery } from "@tanstack/react-query";
const terminal = new Set(["completed", "failed"]);
export function useDubJob(id: string | null) {
return useQuery({
queryKey: ["dub-job", id],
enabled: Boolean(id),
queryFn: async () => {
const response = await fetch(`/api/dubs/${id}`);
if (!response.ok) throw new Error("Could not load dub job");
return response.json();
},
refetchInterval: (query) =>
query.state.data && !terminal.has(query.state.data.status)
? 2_500
: false,
});
}Get the dubbed MP3
Once the job is completed, request a fresh presigned output URL. It expires after 15 minutes, so request another URL when a user starts a later download.
import { getDubOutput } from "@ai-dubbing/sdk";
const { data: output } = await getDubOutput({
path: { id: completedJob.id },
throwOnError: true,
});
audioElement.src = output.url;Do not proxy the MP3 through your API unless you have a specific authorization or transformation requirement. The API already verifies job ownership before it returns the URL.