> ## Documentation Index
> Fetch the complete documentation index at: https://heygen-1fa696a7.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# API Key

> Generate your HeyGen API key in under a minute. Authenticate requests for avatar video generation, translation, and streaming.

![](https://mintcdn.com/heygen-1fa696a7/hfMXXwJzjE7vBSYZ/images/theme/research.webp?fit=max\&auto=format\&n=hfMXXwJzjE7vBSYZ\&q=85\&s=3e4c2594813dcfd56985f3d63e3ba321)

## Getting Your API Key

1. Go to the [API keys page](https://platform.heygen.com/api-keys).
2. Click to generate your API key.

## Configuring Your API Key

### Environment variable (recommended)

```bash theme={null}
export HEYGEN_API_KEY="your-api-key-here"
```

### `.env` file

If your project uses a `.env` file (common with Node.js, Python, or frameworks like Next.js):

```text theme={null}
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:

```bash theme={null}
export HEYGEN_API_KEY="your-api-key-here"
claude  # or whatever command starts your session
```

Alternatively, add it to your shell profile (`~/.bashrc`, `~/.zshrc`) so it persists across sessions:

```bash theme={null}
echo 'export HEYGEN_API_KEY="your-api-key-here"' >> ~/.zshrc
source ~/.zshrc
```

### HeyGen 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. The base URL for all endpoints is `https://api.heygen.com`. When auth fails, the API returns [`unauthorized` (401)](https://heygen-1fa696a7.mintlify.site/docs/error-codes#unauthorized).

### Quick verification

Verify your key is working by fetching your account info with [`GET /v3/users/me`](https://heygen-1fa696a7.mintlify.site/reference/get-current-user):

```bash theme={null}
curl -X GET "https://api.heygen.com/v3/users/me" \
  -H "X-Api-Key: $HEYGEN_API_KEY"
```

A `200` response with your account details confirms your key is valid. The `billing_type` and corresponding billing field (`wallet`, `subscription`, or `usage_based`) show your current balance and billing model; see [Get Current User](https://heygen-1fa696a7.mintlify.site/user-profile.md).

## Restricting Key Permissions

Use permission scopes to limit a key to only the resources and actions it needs. See [API Key Permission Scopes](https://heygen-1fa696a7.mintlify.site/docs/api-key-permissions.md) for the complete, automatically updated mapping of scopes to endpoints.

To check which scopes a key holds, call [`GET /v3/api_keys/self`](https://heygen-1fa696a7.mintlify.site/reference/get-current-api-key) with that key. It returns the key's name, `scope_mode` (`full`, `read_only`, or `custom`), `scopes`, and expiration, and works with any key regardless of its scopes.

## Security Best Practices

* **Never commit your API key to version control.** Add `.env` to 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** on the [Usage page](https://platform.heygen.com/usage).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.