Discussions
API Create Video Python Still Not Working For Me
5 months ago by null
The sample "Try Me" code still doesn't work on the API reference site. I was told it will work in Python (VC). But I can't get it (code from Heygen AI bot) working there either. When I run this it says:
Video created successfully: {'error': None, 'data': {'video_id': 'ee81024bc5494ff88e008395e3ccab6c'}}
In my projects page I see the attempt "API Video Processing" but it has an "Error" in pink in the lower left.
import requests
import json
def load_api_key(file_path: str) -> str:
with open(file_path, "r") as file:
return file.read().strip()
api_key = load_api_key("apikey.txt")
voice_id = 'd7bbcdd6964c47bdaae26decade4a933'
input_text = "With HeyGen, it is very easy to create talking photo videos."
avatar_id = "Brent_sitting_office_front"
#voice_id = "ff2ecc8fbdef4273a28bed7b5e35bb57"
url = '<https://api.heygen.com/v2/video/generate'>
headers = {
'X-Api-Key': api_key,
'Content-Type': 'application/json'
}
data = {
"video_inputs": [
{
"character": {
"type": "avatar",
"avatar_id": avatar_id,
"avatar_style": "normal"
},
"voice": {
"type": "text",
"input_text": input_text,
"voice_id": voice_id
},
"background": {
"type": "color",
"value": "#FAFAFA"
}
}
]
}
response = requests.post(url, headers=headers, data=json.dumps(data))
if response.status_code == 200:
print("Video created successfully:", response.json())
else:
print("Failed to create video:", response.status_code, response.text)