Direct audio uploads
Request a presigned URL, upload directly to storage, then confirm the job.
Audio does not pass through the API server. Your trusted server uses the SDK to create a one-time upload grant, the browser uploads directly to object storage, and the trusted server confirms the upload to enqueue the dubbing job.
Complete upload flow
import {
createDub,
createDubUpload,
} from "@ai-dubbing/sdk";
// Run steps 1 and 3 on your server, where AI_DUBBING_API_KEY is available.
const file = uploadedFile;
const contentType = file.type || "audio/mpeg";
// 1. Ask the API for a short-lived direct-upload URL.
const { data: upload } = await createDubUpload({
body: {
fileName: file.name,
contentType,
contentLength: file.size,
audioLanguage: "hi",
targetLanguage: "en",
},
throwOnError: true,
});
// 2. Give only upload.uploadUrl and upload.contentType to the browser.
// The browser uploads directly to the presigned URL.
const put = await fetch(upload.uploadUrl, {
method: "PUT",
headers: { "Content-Type": upload.contentType },
body: file,
});
if (!put.ok) throw new Error(`Storage upload failed (${put.status})`);
// 3. Back on your server, verify the object and enqueue the dub.
const { data: job } = await createDub({
body: { uploadId: upload.uploadId },
throwOnError: true,
});
console.log(job.id);Requirements
- Supported file extensions:
mp3,m4a,flac,ogg,wav, andwebm. - The content type must start with
audio/and match the content type submitted in step 1. - Maximum upload size is 100 MB.
- The upload grant expires after 10 minutes and can only be confirmed once.
The API downloads and probes the completed object during confirmation to calculate the real audio duration and reserve the correct number of credits. Do not trust client-provided duration for billing.
Browser CORS
For browser uploads, configure the storage bucket CORS policy to allow your frontend origin to send PUT requests with the Content-Type header. The API CORS configuration does not apply to the object-storage request.
Never send an API key to the presigned URL. It is an object-storage URL and only needs the exact Content-Type used when the URL was created.