KosmoKrator

data

YouTube Lua API for KosmoKrator Agents

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

7 functions 7 read 0 write API key auth

Lua Namespace

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

Agent-Facing Lua Docs

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

YouTube — Lua API Reference

All YouTube tools are available under app.integrations.youtube.

search_videos

Search for videos, channels, or playlists on YouTube using keywords, filters, and sorting options.

Parameters

NameTypeRequiredDescription
querystringyesSearch query text
typestringnoResource type: video, channel, or playlist. Default: video
max_resultsintegernoMax results per page (1-50). Default: 10
page_tokenstringnoToken for the next page of results
orderstringnoSort order: date, rating, relevance, title, videoCount, viewCount
published_afterstringnoRFC 3339 date-time (e.g., "2024-01-01T00:00:00Z")
published_beforestringnoRFC 3339 date-time
region_codestringnoISO 3166-1 alpha-2 country code (e.g., "US")
channel_idstringnoLimit search to a specific channel
video_durationstringnoDuration filter: any, long, medium, short
safe_searchstringnoSafe search: moderate, none, strict

Example

local result = app.integrations.youtube.search_videos({
  query = "rust programming tutorial",
  max_results = 5,
  order = "viewCount",
  video_duration = "long"
})

if result and result.items then
  for _, item in ipairs(result.items) do
    print(item.snippet.title)
    print("  Channel: " .. item.snippet.channelTitle)
    print("  Published: " .. item.snippet.publishedAt)
  end
end

get_video_details

Get detailed information about one or more YouTube videos by ID.

Parameters

NameTypeRequiredDescription
video_idsstringyesComma-separated video IDs (max 50). E.g., "dQw4w9WgXcQ"
partstringnoComma-separated resource parts. Default: snippet,contentDetails,statistics

Example

local result = app.integrations.youtube.get_video_details({
  video_ids = "dQw4w9WgXcQ"
})

if result and result.items then
  for _, video in ipairs(result.items) do
    print(video.snippet.title)
    print("  Views: " .. (video.statistics.viewCount or "N/A"))
    print("  Likes: " .. (video.statistics.likeCount or "N/A"))
    print("  Duration: " .. (video.contentDetails.duration or "N/A"))
  end
end

list_channels

List YouTube channels by username, channel ID, or category.

Parameters

NameTypeRequiredDescription
for_usernamestringno*YouTube username
channel_idsstringno*Comma-separated channel IDs (max 50)
category_idstringno*Guide category ID
minebooleanno*Set true for authenticated user’s channel
max_resultsintegernoMax results per page (1-50). Default: 5
page_tokenstringnoToken for the next page of results
hlstringnoLanguage code for localized text (e.g., "en")

*At least one filter is required.

Example

local result = app.integrations.youtube.list_channels({
  for_username = "Google"
})

if result and result.items then
  for _, channel in ipairs(result.items) do
    print(channel.snippet.title)
    print("  Subscribers: " .. (channel.statistics.subscriberCount or "hidden"))
    print("  Videos: " .. (channel.statistics.videoCount or "N/A"))
  end
end

get_channel

Get detailed information about a specific YouTube channel by ID.

Parameters

NameTypeRequiredDescription
channel_idstringyesYouTube channel ID (e.g., "UC_x5XG1OV2P6uZZ5FSM9Ttw")
partstringnoComma-separated resource parts. Default: snippet,contentDetails,statistics,brandingSettings

Example

local result = app.integrations.youtube.get_channel({
  channel_id = "UC_x5XG1OV2P6uZZ5FSM9Ttw"
})

if result and result.items and result.items[1] then
  local ch = result.items[1]
  print(ch.snippet.title)
  print("  Description: " .. (ch.snippet.description or ""))
  print("  Subscribers: " .. (ch.statistics.subscriberCount or "hidden"))
  print("  Total views: " .. (ch.statistics.viewCount or "N/A"))
end

list_playlists

List playlists for a YouTube channel or by playlist IDs.

Parameters

NameTypeRequiredDescription
channel_idstringno*Channel ID to list playlists for
playlist_idsstringno*Comma-separated playlist IDs (max 50)
minebooleanno*Set true for authenticated user’s playlists
max_resultsintegernoMax results per page (1-50). Default: 5
page_tokenstringnoToken for the next page of results

*At least one filter is required.

Example

local result = app.integrations.youtube.list_playlists({
  channel_id = "UC_x5XG1OV2P6uZZ5FSM9Ttw",
  max_results = 10
})

if result and result.items then
  for _, pl in ipairs(result.items) do
    print(pl.snippet.title)
    print("  Item count: " .. (pl.contentDetails.itemCount or "N/A"))
  end
end

get_playlist

Get details about a specific YouTube playlist and its items.

Parameters

NameTypeRequiredDescription
playlist_idstringyesYouTube playlist ID
max_resultsintegernoMax playlist items to return (1-50). Default: 10
page_tokenstringnoToken for the next page of items

Example

local result = app.integrations.youtube.get_playlist({
  playlist_id = "PLrAXtmErZgOeiKm4sgNOknGvNjby9efdf",
  max_results = 5
})

if result and result.items and result.items.items then
  print("Playlist: " .. (result.items.items[1].snippet.title or "Unknown"))
  for _, item in ipairs(result.items.items or {}) do
    print("  " .. item.snippet.title)
  end
end

get_current_user

Get the authenticated user’s YouTube channel information.

Parameters

None.

Example

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

if result and result.items and result.items[1] then
  local ch = result.items[1]
  print("Channel: " .. ch.snippet.title)
  print("Subscribers: " .. (ch.statistics.subscriberCount or "hidden"))
  print("Total views: " .. (ch.statistics.viewCount or "N/A"))
  print("Videos: " .. (ch.statistics.videoCount or "N/A"))
end

Common Patterns

Search videos and get full details

local search = app.integrations.youtube.search_videos({
  query = "machine learning intro",
  max_results = 3,
  order = "relevance"
})

if search and search.items then
  local ids = {}
  for _, item in ipairs(search.items) do
    table.insert(ids, item.id.videoId)
  end

  local details = app.integrations.youtube.get_video_details({
    video_ids = table.concat(ids, ",")
  })

  if details and details.items then
    for _, video in ipairs(details.items) do
      print(video.snippet.title)
      print("  Views: " .. (video.statistics.viewCount or "0"))
      print("  Duration: " .. (video.contentDetails.duration or "N/A"))
    end
  end
end

Paginate through search results

local page = nil
local all_items = {}

for i = 1, 3 do
  local params = {
    query = "web development 2024",
    max_results = 10
  }
  if page then
    params.page_token = page
  end

  local result = app.integrations.youtube.search_videos(params)

  if not result or not result.items then break end

  for _, item in ipairs(result.items) do
    table.insert(all_items, item.snippet.title)
  end

  page = result.nextPageToken
  if not page then break end
end

print("Found " .. #all_items .. " results")
Raw agent markdown
# YouTube — Lua API Reference

All YouTube tools are available under `app.integrations.youtube`.

## search_videos

Search for videos, channels, or playlists on YouTube using keywords, filters, and sorting options.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `query` | string | yes | Search query text |
| `type` | string | no | Resource type: `video`, `channel`, or `playlist`. Default: `video` |
| `max_results` | integer | no | Max results per page (1-50). Default: 10 |
| `page_token` | string | no | Token for the next page of results |
| `order` | string | no | Sort order: `date`, `rating`, `relevance`, `title`, `videoCount`, `viewCount` |
| `published_after` | string | no | RFC 3339 date-time (e.g., `"2024-01-01T00:00:00Z"`) |
| `published_before` | string | no | RFC 3339 date-time |
| `region_code` | string | no | ISO 3166-1 alpha-2 country code (e.g., `"US"`) |
| `channel_id` | string | no | Limit search to a specific channel |
| `video_duration` | string | no | Duration filter: `any`, `long`, `medium`, `short` |
| `safe_search` | string | no | Safe search: `moderate`, `none`, `strict` |

### Example

```lua
local result = app.integrations.youtube.search_videos({
  query = "rust programming tutorial",
  max_results = 5,
  order = "viewCount",
  video_duration = "long"
})

if result and result.items then
  for _, item in ipairs(result.items) do
    print(item.snippet.title)
    print("  Channel: " .. item.snippet.channelTitle)
    print("  Published: " .. item.snippet.publishedAt)
  end
end
```

---

## get_video_details

Get detailed information about one or more YouTube videos by ID.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `video_ids` | string | yes | Comma-separated video IDs (max 50). E.g., `"dQw4w9WgXcQ"` |
| `part` | string | no | Comma-separated resource parts. Default: `snippet,contentDetails,statistics` |

### Example

```lua
local result = app.integrations.youtube.get_video_details({
  video_ids = "dQw4w9WgXcQ"
})

if result and result.items then
  for _, video in ipairs(result.items) do
    print(video.snippet.title)
    print("  Views: " .. (video.statistics.viewCount or "N/A"))
    print("  Likes: " .. (video.statistics.likeCount or "N/A"))
    print("  Duration: " .. (video.contentDetails.duration or "N/A"))
  end
end
```

---

## list_channels

List YouTube channels by username, channel ID, or category.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `for_username` | string | no* | YouTube username |
| `channel_ids` | string | no* | Comma-separated channel IDs (max 50) |
| `category_id` | string | no* | Guide category ID |
| `mine` | boolean | no* | Set `true` for authenticated user's channel |
| `max_results` | integer | no | Max results per page (1-50). Default: 5 |
| `page_token` | string | no | Token for the next page of results |
| `hl` | string | no | Language code for localized text (e.g., `"en"`) |

*At least one filter is required.

### Example

```lua
local result = app.integrations.youtube.list_channels({
  for_username = "Google"
})

if result and result.items then
  for _, channel in ipairs(result.items) do
    print(channel.snippet.title)
    print("  Subscribers: " .. (channel.statistics.subscriberCount or "hidden"))
    print("  Videos: " .. (channel.statistics.videoCount or "N/A"))
  end
end
```

---

## get_channel

Get detailed information about a specific YouTube channel by ID.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `channel_id` | string | yes | YouTube channel ID (e.g., `"UC_x5XG1OV2P6uZZ5FSM9Ttw"`) |
| `part` | string | no | Comma-separated resource parts. Default: `snippet,contentDetails,statistics,brandingSettings` |

### Example

```lua
local result = app.integrations.youtube.get_channel({
  channel_id = "UC_x5XG1OV2P6uZZ5FSM9Ttw"
})

if result and result.items and result.items[1] then
  local ch = result.items[1]
  print(ch.snippet.title)
  print("  Description: " .. (ch.snippet.description or ""))
  print("  Subscribers: " .. (ch.statistics.subscriberCount or "hidden"))
  print("  Total views: " .. (ch.statistics.viewCount or "N/A"))
end
```

---

## list_playlists

List playlists for a YouTube channel or by playlist IDs.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `channel_id` | string | no* | Channel ID to list playlists for |
| `playlist_ids` | string | no* | Comma-separated playlist IDs (max 50) |
| `mine` | boolean | no* | Set `true` for authenticated user's playlists |
| `max_results` | integer | no | Max results per page (1-50). Default: 5 |
| `page_token` | string | no | Token for the next page of results |

*At least one filter is required.

### Example

```lua
local result = app.integrations.youtube.list_playlists({
  channel_id = "UC_x5XG1OV2P6uZZ5FSM9Ttw",
  max_results = 10
})

if result and result.items then
  for _, pl in ipairs(result.items) do
    print(pl.snippet.title)
    print("  Item count: " .. (pl.contentDetails.itemCount or "N/A"))
  end
end
```

---

## get_playlist

Get details about a specific YouTube playlist and its items.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `playlist_id` | string | yes | YouTube playlist ID |
| `max_results` | integer | no | Max playlist items to return (1-50). Default: 10 |
| `page_token` | string | no | Token for the next page of items |

### Example

```lua
local result = app.integrations.youtube.get_playlist({
  playlist_id = "PLrAXtmErZgOeiKm4sgNOknGvNjby9efdf",
  max_results = 5
})

if result and result.items and result.items.items then
  print("Playlist: " .. (result.items.items[1].snippet.title or "Unknown"))
  for _, item in ipairs(result.items.items or {}) do
    print("  " .. item.snippet.title)
  end
end
```

---

## get_current_user

Get the authenticated user's YouTube channel information.

### Parameters

None.

### Example

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

if result and result.items and result.items[1] then
  local ch = result.items[1]
  print("Channel: " .. ch.snippet.title)
  print("Subscribers: " .. (ch.statistics.subscriberCount or "hidden"))
  print("Total views: " .. (ch.statistics.viewCount or "N/A"))
  print("Videos: " .. (ch.statistics.videoCount or "N/A"))
end
```

---

## Common Patterns

### Search videos and get full details

```lua
local search = app.integrations.youtube.search_videos({
  query = "machine learning intro",
  max_results = 3,
  order = "relevance"
})

if search and search.items then
  local ids = {}
  for _, item in ipairs(search.items) do
    table.insert(ids, item.id.videoId)
  end

  local details = app.integrations.youtube.get_video_details({
    video_ids = table.concat(ids, ",")
  })

  if details and details.items then
    for _, video in ipairs(details.items) do
      print(video.snippet.title)
      print("  Views: " .. (video.statistics.viewCount or "0"))
      print("  Duration: " .. (video.contentDetails.duration or "N/A"))
    end
  end
end
```

### Paginate through search results

```lua
local page = nil
local all_items = {}

for i = 1, 3 do
  local params = {
    query = "web development 2024",
    max_results = 10
  }
  if page then
    params.page_token = page
  end

  local result = app.integrations.youtube.search_videos(params)

  if not result or not result.items then break end

  for _, item in ipairs(result.items) do
    table.insert(all_items, item.snippet.title)
  end

  page = result.nextPageToken
  if not page then break end
end

print("Found " .. #all_items .. " results")
```

Metadata-Derived Lua Example

local result = app.integrations.youtube.youtube_search_videos({
  query = "example_query",
  type = "example_type",
  max_results = 1,
  page_token = "example_page_token",
  order = "example_order",
  published_after = "example_published_after",
  published_before = "example_published_before",
  region_code = "example_region_code"
})
print(result)

Functions

youtube_search_videos

Search for videos, channels, or playlists on YouTube using keywords, filters, and sorting options. Returns matching results with snippet metadata.

Operation
Read read
Full name
youtube.youtube_search_videos
ParameterTypeRequiredDescription
query string yes Search query text.
type string no Resource type to search for: video, channel, or playlist. Default: video.
max_results integer no Maximum number of results per page (1-50). Default: 10.
page_token string no Token for the next page of results.
order string no Sort order: date, rating, relevance, title, videoCount, viewCount. Default: relevance.
published_after string no RFC 3339 formatted date-time (e.g., "2024-01-01T00:00:00Z"). Only resources created after this date.
published_before string no RFC 3339 formatted date-time. Only resources created before this date.
region_code string no ISO 3166-1 alpha-2 country code (e.g., "US").
channel_id string no Limit search to a specific channel.
video_duration string no Video duration filter: any, long (>20min), medium (4-20min), short (<4min).
safe_search string no Safe search level: moderate, none, strict. Default: moderate.

youtube_get_video_details

Get detailed information about one or more YouTube videos by ID, including title, description, thumbnails, duration, view count, likes, and channel info.

Operation
Read read
Full name
youtube.youtube_get_video_details
ParameterTypeRequiredDescription
video_ids string yes Comma-separated YouTube video IDs (e.g., "dQw4w9WgXcQ") or a single video ID. Max 50 IDs.
part string no Comma-separated resource parts to include. Default: snippet,contentDetails,statistics. Options: snippet, contentDetails, statistics, status, topicDetails, recordingDetails, fileDetails, processingDetails, suggestions, liveStreamingDetails, localizations.

youtube_list_channels

List YouTube channels by username, channel ID, or category. Returns channel snippets, statistics, and content details.

Operation
Read read
Full name
youtube.youtube_list_channels
ParameterTypeRequiredDescription
for_username string no YouTube username to look up channels for.
channel_ids string no Comma-separated channel IDs (max 50).
category_id string no Guide category ID to filter channels.
mine boolean no Set to true to list the authenticated user's channel.
max_results integer no Maximum results per page (1-50). Default: 5.
page_token string no Token for the next page of results.
hl string no Language code for localized text (e.g., "en", "es").

youtube_get_channel

Get detailed information about a specific YouTube channel by ID, including snippet, statistics (subscribers, views, videos), content details, and branding settings.

Operation
Read read
Full name
youtube.youtube_get_channel
ParameterTypeRequiredDescription
channel_id string yes The YouTube channel ID (e.g., "UC_x5XG1OV2P6uZZ5FSM9Ttw").
part string no Comma-separated resource parts. Default: snippet,contentDetails,statistics,brandingSettings.

youtube_list_playlists

List playlists for a YouTube channel or by playlist IDs. Returns playlist snippets and content details.

Operation
Read read
Full name
youtube.youtube_list_playlists
ParameterTypeRequiredDescription
channel_id string no YouTube channel ID to list playlists for.
playlist_ids string no Comma-separated playlist IDs to look up (max 50).
mine boolean no Set to true to list the authenticated user's playlists.
max_results integer no Maximum results per page (1-50). Default: 5.
page_token string no Token for the next page of results.

youtube_get_playlist

Get details about a specific YouTube playlist by ID, including its metadata and up to 50 playlist items (videos).

Operation
Read read
Full name
youtube.youtube_get_playlist
ParameterTypeRequiredDescription
playlist_id string yes The YouTube playlist ID (e.g., "PLrAXtmErZgOeiKm4sgNOknGvNjby9efdf").
max_results integer no Maximum playlist items to return (1-50). Default: 10.
page_token string no Token for the next page of playlist items.

youtube_get_current_user

Get the authenticated user's YouTube channel information, including channel title, description, subscriber count, total views, and video count.

Operation
Read read
Full name
youtube.youtube_get_current_user
ParameterTypeRequiredDescription
No parameters.