Prerequisites
Before you begin, ensure you have:- Your HeyGen Client ID
- Your Redirect URI (This will be provided by the Partnerships team after you have submitted your Integration Intake form)
Step 1: Initiate User Authorization
To begin the OAuth process, redirect the user to HeyGen’s authorization URL. Create this URL (Replace the placeholders with your own values):- YOUR_CLIENT_ID: Client ID. (e.g.,
abc123) - RANDOM_STATE: A unique string to maintain state. (e.g.,
xyz789) - YOUR_REDIRECT_URI: Your approved redirect URI, ensure URL-encoded. (e.g.,
https://example.com/oauth/callback) - CODE_CHALLENGE Corresponding
code_challengefor a generatedcode_verifierusing the PKCE flow (e.g.E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM). See: RFC 7636 Appendix B.
Note:You can generate a code_verifier and code_challenge using online PKCE tools or standard libraries (e.g., Node.js, Python).
Step 2: Handle the Authorization Callback
After approval, you’ll be redirected to your Redirect URI with acode parameter. It’ll look like this:
AUTHORIZATION_CODE.
Step 3: Exchange Authorization Code for Access Token
Exchange the authorization code for an access token using this curl command:access_token and refresh_token to use in the next steps.
Step 4: Use the Access Token
Now you can make requests to HeyGen’s API using theAuthorization header with the Bearer scheme. Here’s an example listing your avatar groups:
- OAuth Access Tokens — Use the
Authorizationheader with the Bearer scheme. Format:Authorization: Bearer YOUR_ACCESS_TOKEN - API Keys — Use the
X-Api-Keyheader. Format:X-Api-Key: YOUR_API_KEY
Step 5: Refresh the Access Token
Access tokens expire. Keep track of token expiration and refresh as needed. When the access token expires, use the refresh token to obtain a new one:Get User’s Account Information
After successfully authenticating with HeyGen, you can retrieve account information — including remaining credits and billing details — using theGET /v3/user/me endpoint:
YOUR_ACCESS_TOKEN with the access token obtained during the OAuth process.
The billing_type field indicates which billing object is populated in the response:
| Billing Type | Field | Description |
|---|---|---|
wallet | wallet | Prepaid balance in USD (or credits for Enterprise). Includes optional auto-reload settings. |
subscription | subscription | Per-pool credit balances with plan tier and reset dates. Used with OAuth integration apps. |
usage_based | usage_based | Metered billing with current spending and optional spending cap. |
billing_type will be populated; the others will be null.
Best Practices and Security Considerations
- Always use HTTPS for all OAuth-related requests.
- Store tokens securely and never expose them client-side.
- Implement token rotation and regularly refresh access tokens. If a request fails, check if the access token has expired.
- Validate the
stateparameter to prevent CSRF attacks. - Use short-lived access tokens and long-lived refresh tokens.
- Implement proper error handling for token expiration and other OAuth-related errors.

