Quickstart

Create your API Key

Create your API key from the Dashboard. You will use this key to securely access the Sync API.

Make your first generation

The following example shows how to make a lipsync generation using the Sync API.

1

Install Sync SDK

$pip install syncsdk
2

Make your first generation

Copy the following code into a file quickstart.py and replace YOUR_API_KEY_HERE with your generated API key.

quickstart.py
1import time
2from sync import Sync
3from sync.common import Audio, GenerationOptions, Video
4from sync.core.api_error import ApiError
5# ---------- UPDATE API KEY ----------
6# Replace with your Sync.so API key
7api_key = "YOUR_API_KEY_HERE"
8
9# ----------[OPTIONAL] UPDATE INPUT VIDEO AND AUDIO URL ----------
10# URL to your source video
11video_url = "https://assets.sync.so/docs/example-video.mp4"
12# URL to your audio file
13audio_url = "https://assets.sync.so/docs/example-audio.wav"
14# ----------------------------------------
15
16client = Sync(
17 base_url="https://api.sync.so",
18 api_key=api_key
19).generations
20
21print("Starting lip sync generation job...")
22
23try:
24 response = client.create(
25 input=[Video(url=video_url),Audio(url=audio_url)],
26 model="lipsync-2",
27 options=GenerationOptions(sync_mode="cut_off"),
28 )
29except ApiError as e:
30 print(f'create generation request failed with status code {e.status_code} and error {e.body}')
31 exit()
32
33job_id = response.id
34print(f"Generation submitted successfully, job id: {job_id}")
35
36generation = client.get(job_id)
37status = generation.status
38while status not in ['COMPLETED', 'FAILED']:
39 print('polling status for generation', job_id)
40 time.sleep(10)
41 generation = client.get(job_id)
42 status = generation.status
43
44if status == 'COMPLETED':
45 print('generation', job_id, 'completed successfully, output url:', generation.output_url)
46else:
47 print('generation', job_id, 'failed')

Run the script:

$python quickstart.py
3

Done!

It may take a few minutes for the generation to complete. You should see the generated video URL in the terminal post completion.

1

Install dependencies

$npm i @sync.so/sdk
2

Make your first generation

Copy the following code into a file quickstart.ts and replace YOUR_API_KEY_HERE with your generated API key.

quickstart.ts
1import { SyncClient, SyncError } from "@sync.so/sdk";
2
3// ---------- UPDATE API KEY ----------
4// Replace with your Sync.so API key
5const apiKey = "YOUR_API_KEY_HERE";
6
7// ----------[OPTIONAL] UPDATE INPUT VIDEO AND AUDIO URL ----------
8// URL to your source video
9const videoUrl = "https://assets.sync.so/docs/example-video.mp4";
10// URL to your audio file
11const audioUrl = "https://assets.sync.so/docs/example-audio.wav";
12// ----------------------------------------
13
14const client = new SyncClient({ apiKey });
15
16async function main() {
17 console.log("Starting lip sync generation job...");
18
19 let jobId: string;
20 try {
21 const response = await client.generations.create({
22 input: [
23 {
24 type: "video",
25 url: videoUrl,
26 },
27 {
28 type: "audio",
29 url: audioUrl,
30 },
31 ],
32 model: "lipsync-2",
33 options: {
34 sync_mode: "cut_off",
35 },
36 });
37 jobId = response.id;
38 console.log(`Generation submitted successfully, job id: ${jobId}`);
39 } catch (err) {
40 if (err instanceof SyncError) {
41 console.error(`create generation request failed with status code ${err.statusCode} and error ${JSON.stringify(err.body)}`);
42 } else {
43 console.error('An unexpected error occurred:', err);
44 }
45 return;
46 }
47
48 let generation;
49 let status;
50 while (status !== 'COMPLETED' && status !== 'FAILED') {
51 console.log(`polling status for generation ${jobId}...`);
52 try {
53 await new Promise(resolve => setTimeout(resolve, 10000));
54 generation = await client.generations.get(jobId);
55 status = generation.status;
56 } catch (err) {
57 if (err instanceof SyncError) {
58 console.error(`polling failed with status code ${err.statusCode} and error ${JSON.stringify(err.body)}`);
59 } else {
60 console.error('An unexpected error occurred during polling:', err);
61 }
62 status = 'FAILED';
63 }
64 }
65
66 if (status === 'COMPLETED') {
67 console.log(`generation ${jobId} completed successfully, output url: ${generation?.outputUrl}`);
68 } else {
69 console.log(`generation ${jobId} failed`);
70 }
71}
72
73main();

Run the script:

$npx tsx quickstart.ts -y
3

Done!

You should see the generated video URL in the terminal.

Well done! You’ve just made your first lipsync generation with sync.so!

Ready to unlock the full potential of lipsync? Dive into our interactive Studio to experiment with all available models, or explore our API Documentation to take your lip-sync generations to the next level!