KosmoKrator

data

Twitch Lua API for KosmoKrator Agents

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

Lua Namespace

Agents call this integration through app.integrations.twitch.*. Use lua_read_doc("integrations.twitch") 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 Twitch workflow without starting an interactive agent session.

Inline Lua call
kosmo integrations:lua --eval 'dump(app.integrations.twitch.list_streams({game_id = "example_game_id", language = "example_language", user_id = "example_user_id", user_login = "example_user_login", first = 1, after = "example_after", before = "example_before"}))' --json
Read Lua docs headlessly
kosmo integrations:lua --eval 'print(docs.read("twitch"))' --json
kosmo integrations:lua --eval 'print(docs.read("twitch.list_streams"))' --json

Workflow file

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

workflow.lua
local twitch = app.integrations.twitch
local result = twitch.list_streams({game_id = "example_game_id", language = "example_language", user_id = "example_user_id", user_login = "example_user_login", first = 1, after = "example_after", before = "example_before"})

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.twitch, app.mcp.*, docs.*, json.*, and regex.*. Use app.integrations.twitch.default.* or app.integrations.twitch.work.* when you configured named credential accounts.

MCP-only Lua

If the script only needs configured MCP servers and does not need Twitch, 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.

Twitch — Lua API Reference

list_streams

List live streams on Twitch. Filter by game, language, or specific users.

Parameters

NameTypeRequiredDescription
game_idstringnoFilter by game/category ID (use search_categories to find the ID)
languagestringnoStream language code (e.g., "en", "es", "fr", "de")
user_idstringnoBroadcaster user ID
user_loginstringnoBroadcaster login name
firstintegernoNumber of results (max 100, default 20)
afterstringnoPagination cursor
beforestringnoBackward pagination cursor

Examples

Top Fortnite streams

local result = app.integrations.twitch.list_streams({
  game_id = "33214",
  first = 10
})

for _, stream in ipairs(result.streams) do
  print(stream.user_name .. " — " .. stream.title .. " (" .. stream.viewer_count .. " viewers)")
end

Streams in English

local result = app.integrations.twitch.list_streams({
  language = "en",
  first = 20
})

Check if a specific user is live

local result = app.integrations.twitch.list_streams({
  user_login = "ninja"
})

if result.count > 0 then
  print(result.streams[1].user_name .. " is live: " .. result.streams[1].title)
else
  print("User is not currently streaming.")
end

get_user

Get information about a Twitch user by ID or login name.

Parameters

NameTypeRequiredDescription
idstringno*User ID
loginstringno*Login name (e.g., "ninja")

*At least one of id or login is required.

Example

local result = app.integrations.twitch.get_user({
  login = "ninja"
})

if result.count > 0 then
  local user = result.users[1]
  print(user.display_name .. " — " .. user.description)
end

list_games

Get information about one or more Twitch games/categories.

Parameters

NameTypeRequiredDescription
idstringno*Game ID
namestringno*Game name (e.g., "Fortnite")

*At least one of id or name is required.

Example

local result = app.integrations.twitch.list_games({
  name = "Fortnite"
})

for _, game in ipairs(result.games) do
  print(game.name .. " (ID: " .. game.id .. ")")
end

get_game

Get information about a specific game by its Twitch ID.

Parameters

NameTypeRequiredDescription
idstringyesThe game/category ID

Example

local result = app.integrations.twitch.get_game({
  id = "21779"
})

if result.game then
  print(result.game.name .. " — IGDB: " .. (result.game.igdb_id or "N/A"))
end

list_channels

List channel information on Twitch.

Parameters

NameTypeRequiredDescription
broadcaster_idstringnoFilter by broadcaster user ID
firstintegernoNumber of results (max 100, default 20)
afterstringnoPagination cursor

Example

local result = app.integrations.twitch.list_channels({
  broadcaster_id = "123456"
})

for _, channel in ipairs(result.channels) do
  print(channel.broadcaster_name .. " — " .. channel.game_name .. " — " .. channel.title)
end

get_channel

Get information about a specific channel by broadcaster ID.

Parameters

NameTypeRequiredDescription
broadcaster_idstringyesThe broadcaster’s user ID

Example

local result = app.integrations.twitch.get_channel({
  broadcaster_id = "123456"
})

if result.channel then
  local ch = result.channel
  print(ch.broadcaster_name .. " is playing " .. ch.game_name)
  print("Title: " .. ch.title)
  print("Live: " .. tostring(ch.is_live))
end

search_categories

Search for games/categories on Twitch by name.

Parameters

NameTypeRequiredDescription
querystringyesSearch query
firstintegernoNumber of results (max 100, default 20)
afterstringnoPagination cursor

Example

local result = app.integrations.twitch.search_categories({
  query = "League",
  first = 5
})

for _, cat in ipairs(result.categories) do
  print(cat.name .. " (ID: " .. cat.id .. ")")
end

Workflow: search then list streams

-- Step 1: Find the game
local search = app.integrations.twitch.search_categories({
  query = "Just Chatting"
})

if search.count > 0 then
  local game_id = search.categories[1].id

  -- Step 2: Get top streams for that game
  local streams = app.integrations.twitch.list_streams({
    game_id = game_id,
    first = 5
  })

  for _, stream in ipairs(streams.streams) do
    print(stream.user_name .. " — " .. stream.viewer_count .. " viewers")
  end
end

get_current_user

Get information about the authenticated Twitch user. No parameters required.

Example

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

local user = result.user
print("Logged in as: " .. user.display_name)
print("Broadcaster type: " .. (user.broadcaster_type or "none"))
print("Bio: " .. (user.description or ""))

Multi-Account Usage

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

-- Default account (always works)
app.integrations.twitch.list_streams({game_id = "33214"})

-- Explicit default (portable across setups)
app.integrations.twitch.default.list_streams({game_id = "33214"})

-- Named accounts
app.integrations.twitch.work.list_streams({game_id = "33214"})
app.integrations.twitch.personal.list_streams({game_id = "33214"})

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

Raw agent markdown
# Twitch — Lua API Reference

## list_streams

List live streams on Twitch. Filter by game, language, or specific users.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `game_id` | string | no | Filter by game/category ID (use search_categories to find the ID) |
| `language` | string | no | Stream language code (e.g., `"en"`, `"es"`, `"fr"`, `"de"`) |
| `user_id` | string | no | Broadcaster user ID |
| `user_login` | string | no | Broadcaster login name |
| `first` | integer | no | Number of results (max 100, default 20) |
| `after` | string | no | Pagination cursor |
| `before` | string | no | Backward pagination cursor |

### Examples

#### Top Fortnite streams

```lua
local result = app.integrations.twitch.list_streams({
  game_id = "33214",
  first = 10
})

for _, stream in ipairs(result.streams) do
  print(stream.user_name .. " — " .. stream.title .. " (" .. stream.viewer_count .. " viewers)")
end
```

#### Streams in English

```lua
local result = app.integrations.twitch.list_streams({
  language = "en",
  first = 20
})
```

#### Check if a specific user is live

```lua
local result = app.integrations.twitch.list_streams({
  user_login = "ninja"
})

if result.count > 0 then
  print(result.streams[1].user_name .. " is live: " .. result.streams[1].title)
else
  print("User is not currently streaming.")
end
```

---

## get_user

Get information about a Twitch user by ID or login name.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `id` | string | no* | User ID |
| `login` | string | no* | Login name (e.g., `"ninja"`) |

*At least one of `id` or `login` is required.

### Example

```lua
local result = app.integrations.twitch.get_user({
  login = "ninja"
})

if result.count > 0 then
  local user = result.users[1]
  print(user.display_name .. " — " .. user.description)
end
```

---

## list_games

Get information about one or more Twitch games/categories.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `id` | string | no* | Game ID |
| `name` | string | no* | Game name (e.g., `"Fortnite"`) |

*At least one of `id` or `name` is required.

### Example

```lua
local result = app.integrations.twitch.list_games({
  name = "Fortnite"
})

for _, game in ipairs(result.games) do
  print(game.name .. " (ID: " .. game.id .. ")")
end
```

---

## get_game

Get information about a specific game by its Twitch ID.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `id` | string | yes | The game/category ID |

### Example

```lua
local result = app.integrations.twitch.get_game({
  id = "21779"
})

if result.game then
  print(result.game.name .. " — IGDB: " .. (result.game.igdb_id or "N/A"))
end
```

---

## list_channels

List channel information on Twitch.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `broadcaster_id` | string | no | Filter by broadcaster user ID |
| `first` | integer | no | Number of results (max 100, default 20) |
| `after` | string | no | Pagination cursor |

### Example

```lua
local result = app.integrations.twitch.list_channels({
  broadcaster_id = "123456"
})

for _, channel in ipairs(result.channels) do
  print(channel.broadcaster_name .. " — " .. channel.game_name .. " — " .. channel.title)
end
```

---

## get_channel

Get information about a specific channel by broadcaster ID.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `broadcaster_id` | string | yes | The broadcaster's user ID |

### Example

```lua
local result = app.integrations.twitch.get_channel({
  broadcaster_id = "123456"
})

if result.channel then
  local ch = result.channel
  print(ch.broadcaster_name .. " is playing " .. ch.game_name)
  print("Title: " .. ch.title)
  print("Live: " .. tostring(ch.is_live))
end
```

---

## search_categories

Search for games/categories on Twitch by name.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `query` | string | yes | Search query |
| `first` | integer | no | Number of results (max 100, default 20) |
| `after` | string | no | Pagination cursor |

### Example

```lua
local result = app.integrations.twitch.search_categories({
  query = "League",
  first = 5
})

for _, cat in ipairs(result.categories) do
  print(cat.name .. " (ID: " .. cat.id .. ")")
end
```

### Workflow: search then list streams

```lua
-- Step 1: Find the game
local search = app.integrations.twitch.search_categories({
  query = "Just Chatting"
})

if search.count > 0 then
  local game_id = search.categories[1].id

  -- Step 2: Get top streams for that game
  local streams = app.integrations.twitch.list_streams({
    game_id = game_id,
    first = 5
  })

  for _, stream in ipairs(streams.streams) do
    print(stream.user_name .. " — " .. stream.viewer_count .. " viewers")
  end
end
```

---

## get_current_user

Get information about the authenticated Twitch user. No parameters required.

### Example

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

local user = result.user
print("Logged in as: " .. user.display_name)
print("Broadcaster type: " .. (user.broadcaster_type or "none"))
print("Bio: " .. (user.description or ""))
```

---

## Multi-Account Usage

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

```lua
-- Default account (always works)
app.integrations.twitch.list_streams({game_id = "33214"})

-- Explicit default (portable across setups)
app.integrations.twitch.default.list_streams({game_id = "33214"})

-- Named accounts
app.integrations.twitch.work.list_streams({game_id = "33214"})
app.integrations.twitch.personal.list_streams({game_id = "33214"})
```

All functions are identical across accounts — only the credentials differ.
Metadata-derived Lua example
local result = app.integrations.twitch.list_streams({game_id = "example_game_id", language = "example_language", user_id = "example_user_id", user_login = "example_user_login", first = 1, after = "example_after", before = "example_before"})
print(result)

Functions

list_streams Read

List live streams on Twitch. Filter by game, language, or specific users. Returns stream title, viewer count, and broadcaster info.

Lua path
app.integrations.twitch.list_streams
Full name
twitch.twitch_list_streams
ParameterTypeRequiredDescription
game_id string no Filter by game/category ID. Use search_categories to find the ID.
language string no Filter by stream language (e.g., "en", "es", "fr", "de", "pt", "ko", "ja").
user_id string no Filter by broadcaster user ID.
user_login string no Filter by broadcaster login name.
first integer no Number of results to return (max 100, default 20).
after string no Cursor for pagination — pass the value from a previous response to get the next page.
before string no Cursor for backward pagination.
get_user Read

Get information about a Twitch user by user ID or login name. Returns display name, bio, profile image, and account details.

Lua path
app.integrations.twitch.get_user
Full name
twitch.twitch_get_user
ParameterTypeRequiredDescription
id string no The user ID to look up.
login string no The login name to look up (e.g., "ninja").
list_games Read

Get information about Twitch games/categories by ID or name. Returns game name, box art URL, and IGDB ID.

Lua path
app.integrations.twitch.list_games
Full name
twitch.twitch_list_games
ParameterTypeRequiredDescription
id string no Game ID to look up.
name string no Game name to look up (e.g., "Fortnite").
get_game Read

Get information about a specific Twitch game/category by its ID. Returns game name, box art URL, and IGDB ID.

Lua path
app.integrations.twitch.get_game
Full name
twitch.twitch_get_game
ParameterTypeRequiredDescription
id string yes The game/category ID (e.g., "21779" for League of Legends).
list_channels Read

List channel information on Twitch. Filter by broadcaster ID. Returns channel description, game, and broadcast settings.

Lua path
app.integrations.twitch.list_channels
Full name
twitch.twitch_list_channels
ParameterTypeRequiredDescription
broadcaster_id string no Filter by broadcaster user ID.
first integer no Number of results to return (max 100, default 20).
after string no Cursor for pagination — pass the value from a previous response to get the next page.
get_channel Read

Get information about a specific Twitch channel by broadcaster ID. Returns channel title, game, description, and broadcast settings.

Lua path
app.integrations.twitch.get_channel
Full name
twitch.twitch_get_channel
ParameterTypeRequiredDescription
broadcaster_id string yes The broadcaster's user ID.
search_categories Read

Search for games/categories on Twitch by name. Returns matching categories with IDs you can use to filter streams.

Lua path
app.integrations.twitch.search_categories
Full name
twitch.twitch_search_categories
ParameterTypeRequiredDescription
query string yes Search query (e.g., "League of Legends", "Just Chatting").
first integer no Number of results to return (max 100, default 20).
after string no Cursor for pagination — pass the value from a previous response to get the next page.
get_current_user Read

Get information about the currently authenticated Twitch user. Returns display name, bio, profile image, and account type.

Lua path
app.integrations.twitch.get_current_user
Full name
twitch.twitch_get_current_user
ParameterTypeRequiredDescription
No parameters.