Dynamic Video Ad Creation for Instagram/Tiktok
Create dynamic video ads for social media using Veo 3.1 and Seedream 4.0.
1import requests
2import time
3import json
4
5api_key = "YOUR_API_KEY"
6url = "https://api.segmind.com/workflows/690c99890a5320df261fdccc-v8"
7
8data = {
9 "Product_Image": "https://segmind-inference-inputs.s3.amazonaws.com/241022b7-02f3-4ea3-b915-918e6ea7ab7c-Slice_2_WEB_copy copy.png",
10 "Brand_reference_for_background": "https://segmind-inference-inputs.s3.amazonaws.com/5e7b0ed9-9a7a-4ecf-b8f5-e7a36119196e-00161c19-d941-4b04-9d1c-167d856e732f.png",
11 "Concept": "A modern, vibrant, angular design theme that feels bold and energetically forward-driven.",
12 "Theme_and_feature": "Theme=Cinematic;\nPrimary Feature=100 hours of playback on a single charge;"
13}
14
15def poll_for_result(poll_url):
16 """Poll the API until the generation is complete"""
17 while True:
18 response = requests.get(
19 poll_url,
20 headers={'Authorization': f'Bearer {api_key}'}
21 )
22 result = response.json()
23
24 if result['status'] == 'COMPLETED':
25 # Parse the output (it's a JSON string)
26 outputs = json.loads(result['output'])
27 return outputs
28 elif result['status'] == 'FAILED':
29 raise Exception(result.get('error', 'Generation failed'))
30
31 # Wait 7 seconds before polling again
32 time.sleep(7)
33
34# Make the initial request
35response = requests.post(
36 url,
37 json=data,
38 headers={
39 'Authorization': f'Bearer {api_key}',
40 'Content-Type': 'application/json'
41 }
42)
43
44if response.status_code == 200:
45 result = response.json()
46 print('Request queued:', result)
47
48 # Start polling for results
49 outputs = poll_for_result(result['poll_url'])
50 print('Generation complete:', outputs)
51else:
52 print(f"Error: {response.status_code}")
53 print(response.text) 1import requests
2import time
3import json
4
5api_key = "YOUR_API_KEY"
6url = "https://api.segmind.com/workflows/690c99890a5320df261fdccc-v8"
7
8data = {
9 "Product_Image": "https://segmind-inference-inputs.s3.amazonaws.com/241022b7-02f3-4ea3-b915-918e6ea7ab7c-Slice_2_WEB_copy copy.png",
10 "Brand_reference_for_background": "https://segmind-inference-inputs.s3.amazonaws.com/5e7b0ed9-9a7a-4ecf-b8f5-e7a36119196e-00161c19-d941-4b04-9d1c-167d856e732f.png",
11 "Concept": "A modern, vibrant, angular design theme that feels bold and energetically forward-driven.",
12 "Theme_and_feature": "Theme=Cinematic;\nPrimary Feature=100 hours of playback on a single charge;"
13}
14
15def poll_for_result(poll_url):
16 """Poll the API until the generation is complete"""
17 while True:
18 response = requests.get(
19 poll_url,
20 headers={'Authorization': f'Bearer {api_key}'}
21 )
22 result = response.json()
23
24 if result['status'] == 'COMPLETED':
25 # Parse the output (it's a JSON string)
26 outputs = json.loads(result['output'])
27 return outputs
28 elif result['status'] == 'FAILED':
29 raise Exception(result.get('error', 'Generation failed'))
30
31 # Wait 7 seconds before polling again
32 time.sleep(7)
33
34# Make the initial request
35response = requests.post(
36 url,
37 json=data,
38 headers={
39 'Authorization': f'Bearer {api_key}',
40 'Content-Type': 'application/json'
41 }
42)
43
44if response.status_code == 200:
45 result = response.json()
46 print('Request queued:', result)
47
48 # Start polling for results
49 outputs = poll_for_result(result['poll_url'])
50 print('Generation complete:', outputs)
51else:
52 print(f"Error: {response.status_code}")
53 print(response.text)API Endpoint
https://api.segmind.com/workflows/690c99890a5320df261fdccc-v8Parameters
Product_Imageoptionalstring (uri)Product Image
"https://segmind-inference-inputs.s3.amazonaws.com/241022b7-02f3-4ea3-b915-918e6ea7ab7c-Slice_2_WEB_copy copy.png"Brand_reference_for_backgroundoptionalstring (uri)Brand Reference For Background
"https://segmind-inference-inputs.s3.amazonaws.com/5e7b0ed9-9a7a-4ecf-b8f5-e7a36119196e-00161c19-d941-4b04-9d1c-167d856e732f.png"ConceptoptionalstringConcept
"A modern, vibrant, angular design theme that feels bold and energetically forward-driven."Theme_and_featureoptionalstringTheme And Feature
"Theme=Cinematic;\nPrimary Feature=100 hours of playback on a single charge;"Response Format
Returns: Polling-based asynchronous response
Initial request returns a poll_url. Poll every 7 seconds until status is COMPLETED.
Common Error Codes
The API returns standard HTTP status codes. Detailed error messages are provided in the response body.
Bad Request
Invalid parameters or request format
Unauthorized
Missing or invalid API key
Forbidden
Insufficient permissions
Not Found
Workflow not found
Insufficient Credits
Not enough credits to process request
Rate Limited
Too many requests
Server Error
Internal server error
Bad Gateway
Service temporarily unavailable
Timeout
Request timed out