API Key
Getting Your API Key
- Go to the HeyGen API dashboard.
- Navigate to Settings → API → API token.
- Click to generate your API key.
Important: You cannot view your API key after leaving the page. When you generate it, copy and save it somewhere secure immediately. Regenerating a new key will invalidate the previous one.
Configuring Your API Key
Environment variable (recommended)
export HEYGEN_API_KEY="your-api-key-here".env file
.env fileIf your project uses a .env file (common with Node.js, Python, or frameworks like Next.js):
HEYGEN_API_KEY=your-api-key-here
Claude Code
If you're using Claude Code or any terminal-based workflow, set the key in your shell before starting:
export HEYGEN_API_KEY="your-api-key-here"
claude # or whatever command starts your sessionAlternatively, add it to your shell profile (~/.bashrc, ~/.zshrc) so it persists across sessions:
echo 'export HEYGEN_API_KEY="your-api-key-here"' >> ~/.zshrc
source ~/.zshrcHeyGen Skills (in Claude)
When using HeyGen through the Skills integration in Claude's computer environment, the API key is read from the environment. Make sure HEYGEN_API_KEY is set before the skill executes any API calls.
Using the Key in Requests
All HeyGen API requests authenticate via the X-Api-Key header:
curl -X GET "https://api.heygen.com/v2/avatars" \
-H "X-Api-Key: $HEYGEN_API_KEY"const response = await fetch("https://api.heygen.com/v2/avatars", {
headers: { "X-Api-Key": process.env.HEYGEN_API_KEY },
});import os, requests
response = requests.get(
"https://api.heygen.com/v2/avatars",
headers={"X-Api-Key": os.environ["HEYGEN_API_KEY"]}
)Security Best Practices
- Never commit your API key to version control. Add
.envto your.gitignore. - Never expose the key in client-side / browser code. Always call the API from a backend or server environment.
- Rotate your key periodically via the API dashboard.
- Monitor usage in your API dashboard
Updated about 2 hours ago