Skip to the guide

Video dubbing API

Send a video from your app or agent. Preview the dub while it renders, correct individual lines, and export the result as an MP4.

$1 per video

Transcript edits included
Up to 30 minutes and 1 GiB

API keys

  1. Sign in and open Account. Under Dubbing API keys, select Create API key.
  2. Copy the key when it appears. LangSwap shows the full key once. Save it in your app or agent’s secret store.
  3. To disable a key, select Revoke next to its ID in Account. Each active key can access the account’s API-created videos.

Use X-API-Key on requests to https://api.prod.langswap.app/api/v1. Keep this header on your server or agent. Signed upload, preview, and download URLs have their own credentials.

Key management endpoints

These endpoints use the signed-in browser’s Authorization: Bearer session token.

  • POST /agent/keys returns HTTP 201 with id and key.
  • GET /agent/keys returns active key IDs in items.
  • DELETE /agent/keys/{id} revokes the key and returns HTTP 204.

Run the examples in the same Bash session with cURL 7.76 or newer, jq, and a local file named lesson.mp4. Load your key into LANGSWAP_API_KEY or enter it at the hidden prompt.

Configure the shell
set -euo pipefail
ORIGIN="https://api.prod.langswap.app"
API="$ORIGIN/api/v1"
VIDEO_FILE="./lesson.mp4"

if [ -z "${LANGSWAP_API_KEY:-}" ]; then
  read -rsp 'LangSwap API key: ' LANGSWAP_API_KEY
  printf '\n'
fi

api() {
  curl --silent --show-error --fail-with-body \
    --connect-timeout 10 --max-time 60 \
    -H "X-API-Key: $LANGSWAP_API_KEY" "$@"
}

Upload a video

Start with a single-speaker MP4 and choose a different target language. Use the lowercase language name, such as english, for language_target. The example detects the source language with auto.

POST /video/create/ returns the video ID in key. Save it, then use POST /upload with direct_upload: true to get the signed upload policy.

Send a multipart POST to s3.url using every field from s3.fields. If acl is missing, use predefined_acl_name from the response. Add the file part last and wait for storage to return HTTP 201.

Create and upload
VIDEO_ID=$(api -X POST "$API/video/create/" \
  -H 'Content-Type: application/json' \
  -d '{"language_source":"auto","language_target":"english"}' | jq -er '.key')
printf 'Save this video ID: %s\n' "$VIDEO_ID"

policy=$(api -X POST "$API/upload" \
  -H 'Content-Type: application/json' \
  -d "$(jq -nc --arg key "$VIDEO_ID" --arg name "${VIDEO_FILE##*/}" \
    '{key:$key,filename:$name,direct_upload:true}')")

upload_url=$(jq -er '.s3.url' <<<"$policy")
fields=$(jq -ec '
  .s3.fields + {acl:(.s3.fields.acl // .predefined_acl_name)}
  | select(.success_action_status == "201" and (.acl | type == "string"))
  ' <<<"$policy")
form=()
while IFS= read -r field; do
  name=$(jq -er '.key' <<<"$field")
  value=$(jq -er '.value' <<<"$field")
  form+=(--form-string "$name=$value")
done < <(jq -c 'to_entries[]' <<<"$fields")

status=$(curl --silent --show-error --fail --connect-timeout 10 \
  --max-time 1800 --output /dev/null --write-out '%{http_code}' \
  "${form[@]}" --form "file=@\"$VIDEO_FILE\"" "$upload_url")
if [ "$status" != 201 ]; then
  printf 'Storage returned HTTP %s\n' "$status" >&2
  exit 1
fi

Start dubbing

POST /send_to_serverless/{key} queues the uploaded video. HTTP 202 means LangSwap saved the request. LangSwap debits $1 from your available balance when it accepts a new job and credits it back if the render fails.

If the start response is lost, retry with the original video ID. LangSwap reuses that reservation. Account shows your available balance and whether top-ups are available.

Start the uploaded video
api -X POST "$API/send_to_serverless/$VIDEO_ID"

Preview and download

Poll GET /video/{key}/ every few seconds. send_to_serverless means work is queued or running. Stop when you see serverless_complete or serverless_failed.

While it renders, call GET /video/{key}/preview/ for the HLS playlist. manifest_url is null until a preview is ready. The URL is relative to the API host. Request a fresh preview if its link returns HTTP 404 or 410.

Check status and get the preview
api "$API/video/$VIDEO_ID/" | jq '.status'

preview=$(api "$API/video/$VIDEO_ID/preview/")
manifest=$(jq -r '.manifest_url // empty' <<<"$preview")
if [ -n "$manifest" ]; then
  printf '%s%s\n' "$ORIGIN" "$manifest"  # Open this URL in an HLS player.
fi

After serverless_complete, GET /video/{key}/download/ returns a fresh signed MP4 URL in s3_result_video_url. Treat signed media links as private.

Download the finished MP4
url=$(api "$API/video/$VIDEO_ID/download/" | jq -er '.s3_result_video_url')
curl --silent --show-error --fail --connect-timeout 10 \
  --max-time 1800 --output dubbed.mp4 "$url"

Edit a dub

Once the original dub is complete, get its transcript from GET /video/{key}/transcript/. Each segment has an ID, start and end times, source_text, and translated_text.

Send only the changed lines to POST /video/{key}/edits/. Supply translated_text, source_text, or both. The response returns HTTP 202 with a revision id. Edits use the original order and are subject to a per-video limit.

Set a new Idempotency-Key for each edit. Use 8–128 letters, digits, underscores, or hyphens. Keep the same key and body if you retry. To build on a completed edit, include its ID as base_revision_id and read its transcript with ?revision={id}.

Read the transcript and edit a line
api "$API/video/$VIDEO_ID/transcript/" | jq '.segments'

# Use the segment ID from the transcript and save a key for this edit.
EDIT_KEY=lesson-wording-01
revision=$(api -X POST "$API/video/$VIDEO_ID/edits/" \
  -H "Idempotency-Key: $EDIT_KEY" \
  -H 'Content-Type: application/json' \
  -d '{"segments":[{"id":"1","translated_text":"Welcome to the first lesson."}]}')
REVISION_ID=$(jq -er '.id' <<<"$revision")
printf 'Save this revision ID: %s\n' "$REVISION_ID"

Poll GET /video/{key}/edits/{id}/ for queued, processing, complete, or failed. Use GET /video/{key}/edits/ to recover a revision ID. The original remains available while the revision renders.

Check the edit and get its preview
api "$API/video/$VIDEO_ID/edits/$REVISION_ID/" | jq '{status,error}'

revision_preview=$(api "$API/video/$VIDEO_ID/preview/?revision=$REVISION_ID")
manifest=$(jq -r '.manifest_url // empty' <<<"$revision_preview")
if [ -n "$manifest" ]; then
  printf '%s%s\n' "$ORIGIN" "$manifest"  # Open this URL in an HLS player.
fi

Once the edit is complete, get its signed download_url from GET /video/{key}/preview/?revision={id}.

Download the revised MP4
url=$(api "$API/video/$VIDEO_ID/preview/?revision=$REVISION_ID" \
  | jq -er '.download_url')
curl --silent --show-error --fail --connect-timeout 10 \
  --max-time 1800 --output dubbed-revised.mp4 "$url"

Handle errors

Read the response’s detail field when a request fails. If storage rejects an upload policy, request a fresh policy for the same video ID and send the file again.

400 / 413
The upload is empty or exceeds 1 GiB. Check the source file before requesting another upload policy.
401 / 403
Check that the key is active and sent to the API host. Manage keys with a signed-in browser session.
402
The available balance is below $1. After adding credit, retry the start request with the same video ID.
404
The video or revision is unavailable to the key, or the source upload has yet to finish. Check the response detail.
409
The job is in a different state, an edit is pending, or the same edit key was used with a different body. Check status before retrying.
422
The API rejected a parameter, such as an unsupported language or malformed edit. Correct the request before retrying.
423
Spending on the account is on hold. Contact support before retrying.
429
An account upload, active key, or per-video edit limit was reached. Use the response detail to decide when to retry.
502 / 503
The service or storage is temporarily unavailable. Retry with backoff and keep the original video ID and edit key.