Quick Start

πŸ“˜

If you are interested in using Instant Avatars to generate videos, please check this tutorial

Welcome to HeyGen API! πŸ™Œ

HeyGen API expands what you can do with HeyGen, allowing you to create amazing avatar videos programmatically and integrate HeyGen's powerful AI capabilities into your product. Unleash the potential of HeyGen's AI capabilities! Welcome to the future of video creation – happy AI video making! πŸ€–πŸš€

Prerequisite

Create a HeyGen account

Create a HeyGen account. After you create a HeyGen account, you are able to make professional avatar videos by leveraging HeyGen's powerful AI capabilities.

Create an API key

After you have registered the HeyGen account, proceed to the account settings and scroll down to the API Keys section and activate your API key.

πŸ“˜

Note:

The HeyGen API is exclusively available for the Enterprise plan users. To use the HeyGen API, you must be on the Enterprise plan. For trial purposes, you can enable the Trial Token through your account page.

(Optional) Configure Webhooks

You can configure webhook endpoints to listen to events from HeyGen. Simply visit your account page to set up your webhook.

For advanced webhook configuration, explore our webhook API guide.

Create Your First Video

See detailed API reference
We'll create the first video in test mode. Test videos are free and do not count towards your quota. However, they will be watermarked.

curl -X POST 'https://api.heygen.com/v1/video.generate' \
-H 'X-Api-Key: <your-api-key>' \
-H 'Content-Type: application/json' \
-d '{
  "background": "#ffffff",
  "clips": [
    {
      "avatar_id": "Daisy-inskirt-20220818",
      "avatar_style": "normal",
      "input_text": "Welcome to HeyGen API",
      "offset": {
        "x": 0,
        "y": 0
      },
      "scale": 1,
      "voice_id": "1bd001e7e50f421d891986aad5158bc8"
    }
  ],
  "ratio": "16:9",
  "test": true,
  "version": "v1alpha"
}'
{
  "code": 100,
  "data": {
    "video_id": "<video_id>"
  },
  "message": "Success"
}

You will receive a response with the ID of the newly created video. You can also use the input_audio attribute to pass a public audio URL instead of using the input_text attribute.

Also you can create videos from templates as well. Check here to see how.

Wait for the Video

See detailed API reference
After creating your video, you can check its status. When the video is ready, the status will change to completed.

curl -X GET 'https://api.heygen.com/v1/video_status.get?video_id=<video_id>' \
-H 'X-Api-Key: <your-api-key>'
{
  "code": 100,
  "data": {
    "callback_id": null,
    "caption_url": "<caption_url>",
    "duration": 1.234,
    "error": null,
    "gif_url": "<gif_url>",
    "id": "<id>",
    "status": "completed",
    "thumbnail_url": "<thumbnail_url>",
    "video_url": "<video_url>",
    "video_url_caption": null
  },
  "message": "Success"
}
{
  "code": 100,
  "data": {
    "callback_id": null,
    "caption_url": null,
    "duration": null,
    "error": null,
    "gif_url": null,
    "id": "<id>",
    "status": "processing",
    "thumbnail_url": null,
    "video_url": null,
    "video_url_caption": null
  },
  "message": "Success"
}
{
  "code": 100,
  "data": {
    "callback_id": null,
    "caption_url": null,
    "duration": null,
    "error": null,
    "gif_url": null,
    "id": "<id>",
    "status": "pending",
    "thumbnail_url": null,
    "video_url": null,
    "video_url_caption": null
  },
  "message": "Success"
}
{
  "code": 100,
  "data": {
    "callback_id": null,
    "caption_url": null,
    "duration": null,
    "error": {
      "code": 40119,
      "detail": "Video is too long (> 3600.0s). Please upgrade your plan to generate longer videos",
      "message": "Video is too long"
    },
    "gif_url": null,
    "id": "<id>",
    "status": "failed",
    "thumbnail_url": null,
    "video_url": null,
    "video_url_caption": null
  },
  "message": "Success"
}

πŸ“˜

The video file URL you get will expire in 7 days. πŸ“†

You can observe this expiration in the URL parameters. Every time you call the video status endpoint, the Expires and other queries are regenerated accordingly.

Download the video

Once your video is ready, you can find a link in the response for you to download the video.

curl <video_url> --output first_video.mp4

Conclusion

For a comprehensive understanding of HeyGen APIs and their capabilities, please review our detailed API reference.

In conclusion, the HeyGen API empowers you to tap into the remarkable AI capabilities of HeyGen for programmatically generating compelling avatar videos. By creating a HeyGen account, obtaining an API key, and optionally configuring webhooks, you can embark on your video-making journey. Explore the vast potential of HeyGen APIs to infuse creativity into your projects, whether for educational, entertainment, or marketing purposes.