Complete guide for integrating with HeyGen Video Creator
In OpenAI Agent Builder, configure your agent with these settings:
Add this function schema to your OpenAI Agent:
{
"name": "create_news_video",
"description": "Creates a professional news video using HeyGen API",
"parameters": {
"type": "object",
"properties": {
"title": {
"type": "string",
"description": "Video title/headline"
},
"script": {
"type": "string",
"description": "Video script (what the avatar will say)"
},
"avatar_id": {
"type": "string",
"description": "HeyGen avatar ID",
"default": "Brandon_Business_Sitting_Front_public"
},
"voice_id": {
"type": "string",
"description": "HeyGen voice ID",
"default": "73c0b6a2e29d4d38aca41454bf58c955"
},
"background_color": {
"type": "string",
"description": "Background color hex code",
"default": "#1e3a8a"
}
},
"required": ["title", "script"]
}
}
When the agent calls create_news_video, make this HTTP request:
http://localhost:4005/api/heygen/generate
Request Headers:
Content-Type: application/json
Request Body:
{
"video_inputs": [
{
"character": {
"type": "avatar",
"avatar_id": "{{avatar_id}}",
"avatar_style": "normal"
},
"voice": {
"type": "text",
"input_text": "{{script}}",
"voice_id": "{{voice_id}}"
},
"background": {
"type": "color",
"value": "{{background_color}}"
}
}
],
"dimension": {
"width": 1280,
"height": 720
}
}
The generate endpoint returns a video_id. Poll for completion:
http://localhost:4005/api/heygen/status/{{video_id}}
Poll every 10-15 seconds until status is "completed":
{
"code": 100,
"data": {
"status": "completed",
"id": "video_id_here"
}
}
Once completed, get the video download URL:
http://localhost:4005/api/heygen/download/{{video_id}}
Returns:
{
"data": {
"url": "https://api.heygen.com/v1/video.download?video_id=..."
}
}
| Method | Endpoint | Description | Response |
|---|---|---|---|
| GET | /api/heygen/avatars |
List available avatars | { data: { avatars: [...] } } |
| GET | /api/heygen/voices |
List available voices | { data: { voices: [...] } } |
| Method | Endpoint | Description | Response |
|---|---|---|---|
| POST | /api/heygen/generate |
Create new video | { data: { video_id: "..." } } |
| GET | /api/heygen/status/:videoId |
Check video status | { data: { status: "processing|completed|failed" } } |
| GET | /api/heygen/download/:videoId |
Get download URL | { data: { url: "https://..." } } |
| Method | Endpoint | Description | Purpose |
|---|---|---|---|
| GET | /api/videos |
List all videos | Get video history and status |
| POST | /api/videos |
Create video record | Track video metadata locally |
| PATCH | /api/videos/:id |
Update video record | Update status, add download URL |
| DELETE | /api/videos/:id |
Delete video record | Clean up archives |
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/test/socoa |
Create test video with "Welcome to SOCOA" message |
| GET | /api/debug/env |
Check environment configuration |
The server accepts the correct HeyGen v2 format with nested objects:
{
"video_inputs": [
{
"character": {
"type": "avatar",
"avatar_id": "Brandon_Business_Sitting_Front_public",
"avatar_style": "normal"
},
"voice": {
"type": "text",
"input_text": "Your script text here...",
"voice_id": "73c0b6a2e29d4d38aca41454bf58c955"
},
"background": {
"type": "color",
"value": "#1e3a8a"
}
}
],
"dimension": {
"width": 1280,
"height": 720
}
}
Popular avatar options (get full list from /api/heygen/avatars):
Brandon_Business_Sitting_Front_public - Professional male presenter4d98770a53804619aad8679df1dcff0d - Alternative male avatarAbigail_sitting_sofa_side - Female presenterPopular voice options (get full list from /api/heygen/voices):
73c0b6a2e29d4d38aca41454bf58c955 - English Male (Professional)f10deb5a34c9499d9b21351704f2e79b - English Male (Friendly)d92994ae0de34b2e8659b456a2f388b8 - English FemaleYour OpenAI Agent can be triggered by:
Agent should extract and process:
{
"headline": "Breaking: Major Tech Company Announces AI Breakthrough",
"summary": "Company XYZ revealed their new AI system...",
"key_points": [
"Revolutionary AI technology announced",
"Expected to impact multiple industries",
"Available to public in Q2 2024"
],
"source": "TechNews Today",
"publish_date": "2024-01-15"
}
Transform news content into video script:
Good morning, I'm bringing you the latest tech news.
[Headline]: Company XYZ has just announced a revolutionary AI breakthrough that could transform multiple industries.
[Key Points]: The new system promises unprecedented capabilities and will be available to the public in Q2 2024.
[Closing]: This is a developing story, and we'll continue to monitor these exciting developments.
Thank you for watching, and stay tuned for more updates.
Agent makes API call with processed content:
POST /api/videos
{
"title": "Tech News: AI Breakthrough Announcement",
"status": "queued",
"payload": {
"source": "TechNews Today",
"headline": "Breaking: Major Tech Company Announces AI Breakthrough",
"script": "Good morning, I'm bringing you the latest tech news..."
}
}
POST /api/heygen/generate
{
"video_inputs": [
{
"character": {
"type": "avatar",
"avatar_id": "Brandon_Business_Sitting_Front_public",
"avatar_style": "normal"
},
"voice": {
"type": "text",
"input_text": "Good morning, I'm bringing you the latest tech news...",
"voice_id": "73c0b6a2e29d4d38aca41454bf58c955"
},
"background": {
"type": "color",
"value": "#1e3a8a"
}
}
],
"dimension": {
"width": 1280,
"height": 720
}
}
Agent polls for completion and handles the result:
1. Poll /api/heygen/status/{video_id} every 15 seconds
2. When status = "completed", get download URL
3. Update local record with download URL
4. Optionally: Upload to social media, send notifications, etc.
HEYGEN_API_KEY in .env fileavatar_id and voice_id are validinput_text is not empty
GET /api/debug/env - Check environment configurationPOST /api/test/socoa - Test video generation/api/videos to track video creation attempts/processing.htmlTest your setup with these curl commands:
curl http://localhost:4005/api/heygen/avatars
curl http://localhost:4005/api/heygen/voices
curl -X POST http://localhost:4005/api/test/socoa
curl http://localhost:4005/api/debug/env