KosmoKrator

data

HeyGen Lua API for KosmoKrator Agents

Agent-facing Lua documentation and function reference for the HeyGen KosmoKrator integration.

Lua Namespace

Agents call this integration through app.integrations.heygen.*. Use lua_read_doc("integrations.heygen") inside KosmoKrator to discover the same reference at runtime.

Call Lua from the Headless CLI

Use kosmo integrations:lua when a shell script, CI job, cron job, or another coding CLI should run a deterministic HeyGen workflow without starting an interactive agent session.

Inline Lua call
kosmo integrations:lua --eval 'dump(app.integrations.heygen.list_videos({limit = 1, offset = 1}))' --json
Read Lua docs headlessly
kosmo integrations:lua --eval 'print(docs.read("heygen"))' --json
kosmo integrations:lua --eval 'print(docs.read("heygen.list_videos"))' --json

Workflow file

Put repeatable logic in a Lua file, then execute it with JSON output for the calling process.

workflow.lua
local heygen = app.integrations.heygen
local result = heygen.list_videos({limit = 1, offset = 1})

dump(result)
Run the workflow
kosmo integrations:lua workflow.lua --json
kosmo integrations:lua workflow.lua --force --json
Namespace note. integrations:lua exposes app.integrations.heygen, app.mcp.*, docs.*, json.*, and regex.*. Use app.integrations.heygen.default.* or app.integrations.heygen.work.* when you configured named credential accounts.

MCP-only Lua

If the script only needs configured MCP servers and does not need HeyGen, use the narrower mcp:lua command.

MCP Lua command
# Use mcp:lua for MCP-only scripts; use integrations:lua for this integration namespace.
kosmo mcp:lua --eval 'dump(mcp.servers())' --json

Agent-Facing Lua Docs

This is the rendered version of the full Lua documentation exposed to agents when they inspect the integration namespace.

HeyGen — Lua API Reference

list_videos

List generated videos with pagination.

Parameters

NameTypeRequiredDescription
limitintegernoMaximum number of videos to return (default: 10, max: 100)
offsetintegernoNumber of videos to skip for pagination (default: 0)

Examples

-- List recent videos
local result = app.integrations.heygen.list_videos({
  limit = 10,
  offset = 0
})

for _, video in ipairs(result.data.videos) do
  print(video.video_id .. ": " .. video.status)
end

get_video

Get the status and details of a specific video.

Parameters

NameTypeRequiredDescription
video_idstringyesThe unique identifier of the video

Example

local result = app.integrations.heygen.get_video({
  video_id = "abc123"
})

print("Status: " .. result.data.status)
if result.data.video_url then
  print("Download: " .. result.data.video_url)
end

create_video

Generate a new AI video with avatars and voices. Returns a video_id to track generation progress.

Parameters

NameTypeRequiredDescription
video_inputsarrayyesArray of video input objects defining scenes
dimensionobjectnoVideo dimensions, e.g. {width = 1920, height = 1080}
testbooleannoGenerate a test/preview video (default: false)

Video Input Structure

Each video input defines a scene:

{
  character = {
    avatar_id = "avatar-id-here",
    voice_id = "voice-id-here"
  },
  script = "Your script text here",
  voice_settings = {
    speed = 1.0,
    stability = 0.5
  }
}

Examples

-- Create a simple avatar video
local result = app.integrations.heygen.create_video({
  video_inputs = {
    {
      character = {
        avatar_id = "avatar-abc123",
        voice_id = "voice-xyz789"
      },
      script = "Welcome to our product demo!"
    }
  },
  test = true
})

print("Video ID: " .. result.data.video_id)
-- Create a video with custom dimensions
local result = app.integrations.heygen.create_video({
  video_inputs = {
    {
      character = {
        avatar_id = "avatar-abc123",
        voice_id = "voice-xyz789"
      },
      script = "This is a landscape video."
    }
  },
  dimension = { width = 1920, height = 1080 },
  test = false
})

list_avatars

List all available talking avatars.

Parameters

None.

Example

local result = app.integrations.heygen.list_avatars({})

for _, avatar in ipairs(result.data.avatars) do
  print(avatar.avatar_id .. ": " .. avatar.avatar_name)
end

list_voices

List all available voices for video generation.

Parameters

None.

Example

local result = app.integrations.heygen.list_voices({})

for _, voice in ipairs(result.data.voices) do
  print(voice.voice_id .. ": " .. voice.display_name .. " (" .. voice.language .. ")")
end

get_current_user

Get the authenticated user’s account information.

Parameters

None.

Example

local result = app.integrations.heygen.get_current_user({})

print("Plan: " .. result.data.plan)
print("Remaining credits: " .. result.data.remaining_quota)

list_templates

List available video templates with pagination.

Parameters

NameTypeRequiredDescription
limitintegernoMaximum number of templates to return (default: 10, max: 100)
offsetintegernoNumber of templates to skip for pagination (default: 0)

Example

local result = app.integrations.heygen.list_templates({
  limit = 20,
  offset = 0
})

for _, template in ipairs(result.data.templates) do
  print(template.template_id .. ": " .. template.name)
end

Multi-Account Usage

If you have multiple HeyGen accounts configured, use account-specific namespaces:

-- Default account (always works)
app.integrations.heygen.function_name({...})

-- Explicit default (portable across setups)
app.integrations.heygen.default.function_name({...})

-- Named accounts
app.integrations.heygen.work.function_name({...})
app.integrations.heygen.personal.function_name({...})

All functions are identical across accounts — only the credentials differ.

Raw agent markdown
# HeyGen — Lua API Reference

## list_videos

List generated videos with pagination.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `limit` | integer | no | Maximum number of videos to return (default: 10, max: 100) |
| `offset` | integer | no | Number of videos to skip for pagination (default: 0) |

### Examples

```lua
-- List recent videos
local result = app.integrations.heygen.list_videos({
  limit = 10,
  offset = 0
})

for _, video in ipairs(result.data.videos) do
  print(video.video_id .. ": " .. video.status)
end
```

---

## get_video

Get the status and details of a specific video.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `video_id` | string | yes | The unique identifier of the video |

### Example

```lua
local result = app.integrations.heygen.get_video({
  video_id = "abc123"
})

print("Status: " .. result.data.status)
if result.data.video_url then
  print("Download: " .. result.data.video_url)
end
```

---

## create_video

Generate a new AI video with avatars and voices. Returns a `video_id` to track generation progress.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `video_inputs` | array | yes | Array of video input objects defining scenes |
| `dimension` | object | no | Video dimensions, e.g. `{width = 1920, height = 1080}` |
| `test` | boolean | no | Generate a test/preview video (default: false) |

### Video Input Structure

Each video input defines a scene:

```lua
{
  character = {
    avatar_id = "avatar-id-here",
    voice_id = "voice-id-here"
  },
  script = "Your script text here",
  voice_settings = {
    speed = 1.0,
    stability = 0.5
  }
}
```

### Examples

```lua
-- Create a simple avatar video
local result = app.integrations.heygen.create_video({
  video_inputs = {
    {
      character = {
        avatar_id = "avatar-abc123",
        voice_id = "voice-xyz789"
      },
      script = "Welcome to our product demo!"
    }
  },
  test = true
})

print("Video ID: " .. result.data.video_id)
```

```lua
-- Create a video with custom dimensions
local result = app.integrations.heygen.create_video({
  video_inputs = {
    {
      character = {
        avatar_id = "avatar-abc123",
        voice_id = "voice-xyz789"
      },
      script = "This is a landscape video."
    }
  },
  dimension = { width = 1920, height = 1080 },
  test = false
})
```

---

## list_avatars

List all available talking avatars.

### Parameters

None.

### Example

```lua
local result = app.integrations.heygen.list_avatars({})

for _, avatar in ipairs(result.data.avatars) do
  print(avatar.avatar_id .. ": " .. avatar.avatar_name)
end
```

---

## list_voices

List all available voices for video generation.

### Parameters

None.

### Example

```lua
local result = app.integrations.heygen.list_voices({})

for _, voice in ipairs(result.data.voices) do
  print(voice.voice_id .. ": " .. voice.display_name .. " (" .. voice.language .. ")")
end
```

---

## get_current_user

Get the authenticated user's account information.

### Parameters

None.

### Example

```lua
local result = app.integrations.heygen.get_current_user({})

print("Plan: " .. result.data.plan)
print("Remaining credits: " .. result.data.remaining_quota)
```

---

## list_templates

List available video templates with pagination.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `limit` | integer | no | Maximum number of templates to return (default: 10, max: 100) |
| `offset` | integer | no | Number of templates to skip for pagination (default: 0) |

### Example

```lua
local result = app.integrations.heygen.list_templates({
  limit = 20,
  offset = 0
})

for _, template in ipairs(result.data.templates) do
  print(template.template_id .. ": " .. template.name)
end
```

---

## Multi-Account Usage

If you have multiple HeyGen accounts configured, use account-specific namespaces:

```lua
-- Default account (always works)
app.integrations.heygen.function_name({...})

-- Explicit default (portable across setups)
app.integrations.heygen.default.function_name({...})

-- Named accounts
app.integrations.heygen.work.function_name({...})
app.integrations.heygen.personal.function_name({...})
```

All functions are identical across accounts — only the credentials differ.
Metadata-derived Lua example
local result = app.integrations.heygen.list_videos({limit = 1, offset = 1})
print(result)

Functions

list_videos Read

List generated videos from HeyGen. Returns video IDs, statuses, and metadata. Use limit and offset for pagination.

Lua path
app.integrations.heygen.list_videos
Full name
heygen.heygen_list_videos
ParameterTypeRequiredDescription
limit integer no Maximum number of videos to return (default: 10, max: 100).
offset integer no Number of videos to skip for pagination (default: 0).
get_video Read

Get the status and details of a specific HeyGen video. Returns the video status (pending, processing, completed, failed), download URL when ready, and metadata.

Lua path
app.integrations.heygen.get_video
Full name
heygen.heygen_get_video
ParameterTypeRequiredDescription
video_id string yes The unique identifier of the video to retrieve.
create_video Write

Generate a new AI video on HeyGen. Provide video_inputs defining scenes (avatar, voice, script), optional dimensions, and test mode. Returns a video_id to track generation progress.

Lua path
app.integrations.heygen.create_video
Full name
heygen.heygen_create_video
ParameterTypeRequiredDescription
video_inputs array yes Array of video input objects. Each defines a scene with properties like character (avatar_id, voice_id), voice_settings, script, and background. Example: [{"character":{"avatar_id":"...","voice_id":"..."},"script":"Hello world"}]
dimension array no Video dimensions as an object with width and height. Example: {"width": 1920, "height": 1080}. Defaults to 1920x1080 if omitted.
test boolean no Set to true to generate a test (preview) video. Defaults to false.
list_avatars Read

List all available talking avatars from HeyGen. Returns avatar IDs, names, preview images, and supported styles. Use avatar IDs when creating videos.

Lua path
app.integrations.heygen.list_avatars
Full name
heygen.heygen_list_avatars
ParameterTypeRequiredDescription
No parameters.
list_voices Read

List all available voices from HeyGen. Returns voice IDs, display names, supported languages, gender, and preview audio URLs. Use voice IDs when creating videos.

Lua path
app.integrations.heygen.list_voices
Full name
heygen.heygen_list_voices
ParameterTypeRequiredDescription
No parameters.
get_current_user Read

Get the current authenticated HeyGen user's account information, including plan details, remaining credits, and usage statistics.

Lua path
app.integrations.heygen.get_current_user
Full name
heygen.heygen_get_current_user
ParameterTypeRequiredDescription
No parameters.
list_templates Read

List available video templates from HeyGen. Returns template IDs, names, thumbnails, and metadata. Use limit and offset for pagination.

Lua path
app.integrations.heygen.list_templates
Full name
heygen.heygen_list_templates
ParameterTypeRequiredDescription
limit integer no Maximum number of templates to return (default: 10, max: 100).
offset integer no Number of templates to skip for pagination (default: 0).