data
Reddit Lua API for KosmoKrator Agents
Agent-facing Lua documentation and function reference for the Reddit KosmoKrator integration.Lua Namespace
Agents call this integration through app.integrations.reddit.*.
Use lua_read_doc("integrations.reddit") 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
Reddit workflow without starting an interactive agent session.
kosmo integrations:lua --eval 'dump(app.integrations.reddit.create_comment({parent = "example_parent", text = "example_text"}))' --json kosmo integrations:lua --eval 'print(docs.read("reddit"))' --json
kosmo integrations:lua --eval 'print(docs.read("reddit.create_comment"))' --json Workflow file
Put repeatable logic in a Lua file, then execute it with JSON output for the calling process.
local reddit = app.integrations.reddit
local result = reddit.create_comment({parent = "example_parent", text = "example_text"})
dump(result) kosmo integrations:lua workflow.lua --json
kosmo integrations:lua workflow.lua --force --json integrations:lua exposes app.integrations.reddit, app.mcp.*, docs.*, json.*, and regex.*. Use app.integrations.reddit.default.* or app.integrations.reddit.work.* when you configured named credential accounts.
MCP-only Lua
If the script only needs configured MCP servers and does not need Reddit, use the narrower 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.
Reddit — Lua API Reference
list_posts
List posts from a subreddit or the Reddit front page.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
subreddit | string | no | Subreddit name (without r/ prefix). Leave empty for front page. |
sort | string | no | Sort method: hot, new, top, rising, controversial (default: hot) |
limit | integer | no | Number of posts to return (default: 25, max: 100) |
after | string | no | Fullname of a post to fetch results after (for pagination) |
before | string | no | Fullname of a post to fetch results before (for pagination) |
Examples
-- List hot posts from a subreddit
local result = app.integrations.reddit.list_posts({
subreddit = "programming",
sort = "hot",
limit = 10
})
for _, post in ipairs(result.data.children) do
print(post.data.title .. " (score: " .. post.data.score .. ")")
end
-- List new posts from the front page
local result = app.integrations.reddit.list_posts({
sort = "new",
limit = 25
})
for _, post in ipairs(result.data.children) do
print(post.data.title)
end
-- Paginate through results
local result = app.integrations.reddit.list_posts({
subreddit = "worldnews",
limit = 25
})
-- Use the last post's fullname to get the next page
local last = result.data.children[#result.data.children]
local next_page = app.integrations.reddit.list_posts({
subreddit = "worldnews",
limit = 25,
after = last.data.name
})
get_post
Get details for a specific Reddit post.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
subreddit | string | yes | Subreddit name (without r/ prefix) |
post_id | string | yes | The base36 post ID (e.g., “abc123”) |
Examples
local result = app.integrations.reddit.get_post({
subreddit = "programming",
post_id = "abc123"
})
-- result is an array with two elements: [1] = post listing, [2] = comments
local post = result[1].data.children[1].data
print(post.title)
print("Score: " .. post.score)
print("Author: u/" .. post.author)
print("Comments: " .. post.num_comments)
create_post
Submit a new post to a subreddit.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
subreddit | string | yes | Subreddit name (without r/ prefix) |
title | string | yes | Post title |
kind | string | no | Post type: self (text), link, image, or video (default: self) |
text | string | no | Post body text for self posts (supports Markdown) |
url | string | no | URL for link posts |
nsfw | boolean | no | Whether the post is NSFW (default: false) |
spoiler | boolean | no | Whether the post is a spoiler (default: false) |
Examples
-- Create a text post
local result = app.integrations.reddit.create_post({
subreddit = "test",
title = "Hello from OpenCompany!",
kind = "self",
text = "This is a test post created via the API."
})
print("Post created: " .. result.json.data.name)
-- Create a link post
local result = app.integrations.reddit.create_post({
subreddit = "programming",
title = "Interesting article about Lua",
kind = "link",
url = "https://www.lua.org/"
})
list_subreddits
List popular or new subreddits.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
sort | string | no | Sort method: popular or new (default: popular) |
limit | integer | no | Number of subreddits to return (default: 25, max: 100) |
after | string | no | Fullname of a subreddit to fetch results after (for pagination) |
before | string | no | Fullname of a subreddit to fetch results before (for pagination) |
Examples
-- List popular subreddits
local result = app.integrations.reddit.list_subreddits({
sort = "popular",
limit = 10
})
for _, sub in ipairs(result.data.children) do
print("r/" .. sub.data.display_name .. " - " .. sub.data.subscribers .. " subscribers")
end
-- List new subreddits
local result = app.integrations.reddit.list_subreddits({
sort = "new",
limit = 10
})
for _, sub in ipairs(result.data.children) do
print("r/" .. sub.data.display_name .. " - " .. sub.data.title)
end
get_subreddit
Get information about a specific subreddit.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
subreddit | string | yes | Subreddit name (without r/ prefix) |
Examples
local result = app.integrations.reddit.get_subreddit({
subreddit = "programming"
})
print("r/" .. result.data.display_name)
print("Title: " .. result.data.title)
print("Subscribers: " .. result.data.subscribers)
print("Description: " .. result.data.public_description)
print("Created: " .. os.date("!%Y-%m-%d", result.data.created_utc))
list_comments
List comments for a specific Reddit post.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
subreddit | string | yes | Subreddit name (without r/ prefix) |
post_id | string | yes | The base36 post ID (e.g., “abc123”) |
limit | integer | no | Maximum number of comments to return (default: 25, max: 100) |
sort | string | no | Comment sort order: best, top, new, controversial, old, q&a (default: best) |
depth | integer | no | Maximum comment depth (default: unlimited) |
Examples
local result = app.integrations.reddit.list_comments({
subreddit = "programming",
post_id = "abc123",
limit = 10,
sort = "top"
})
-- Comments are in the second element of the response array
for _, comment in ipairs(result[2].data.children) do
if comment.kind == "t1" then
print("u/" .. comment.data.author .. ": " .. comment.data.body:sub(1, 100))
print("Score: " .. comment.data.score)
end
end
get_current_user
Get the profile of the currently authenticated Reddit user.
Parameters
None.
Examples
local result = app.integrations.reddit.get_current_user({})
print("Logged in as: u/" .. result.name)
print("Link karma: " .. result.link_karma)
print("Comment karma: " .. result.comment_karma)
Multi-Account Usage
If you have multiple Reddit accounts configured, use account-specific namespaces:
-- Default account (always works)
app.integrations.reddit.function_name({...})
-- Explicit default (portable across setups)
app.integrations.reddit.default.function_name({...})
-- Named accounts
app.integrations.reddit.production.function_name({...})
app.integrations.reddit.staging.function_name({...})
All functions are identical across accounts — only the credentials differ.
Raw agent markdown
# Reddit — Lua API Reference
## list_posts
List posts from a subreddit or the Reddit front page.
### Parameters
| Name | Type | Required | Description |
|------|------|----------|-------------|
| `subreddit` | string | no | Subreddit name (without r/ prefix). Leave empty for front page. |
| `sort` | string | no | Sort method: hot, new, top, rising, controversial (default: hot) |
| `limit` | integer | no | Number of posts to return (default: 25, max: 100) |
| `after` | string | no | Fullname of a post to fetch results after (for pagination) |
| `before` | string | no | Fullname of a post to fetch results before (for pagination) |
### Examples
```lua
-- List hot posts from a subreddit
local result = app.integrations.reddit.list_posts({
subreddit = "programming",
sort = "hot",
limit = 10
})
for _, post in ipairs(result.data.children) do
print(post.data.title .. " (score: " .. post.data.score .. ")")
end
-- List new posts from the front page
local result = app.integrations.reddit.list_posts({
sort = "new",
limit = 25
})
for _, post in ipairs(result.data.children) do
print(post.data.title)
end
-- Paginate through results
local result = app.integrations.reddit.list_posts({
subreddit = "worldnews",
limit = 25
})
-- Use the last post's fullname to get the next page
local last = result.data.children[#result.data.children]
local next_page = app.integrations.reddit.list_posts({
subreddit = "worldnews",
limit = 25,
after = last.data.name
})
```
---
## get_post
Get details for a specific Reddit post.
### Parameters
| Name | Type | Required | Description |
|------|------|----------|-------------|
| `subreddit` | string | yes | Subreddit name (without r/ prefix) |
| `post_id` | string | yes | The base36 post ID (e.g., "abc123") |
### Examples
```lua
local result = app.integrations.reddit.get_post({
subreddit = "programming",
post_id = "abc123"
})
-- result is an array with two elements: [1] = post listing, [2] = comments
local post = result[1].data.children[1].data
print(post.title)
print("Score: " .. post.score)
print("Author: u/" .. post.author)
print("Comments: " .. post.num_comments)
```
---
## create_post
Submit a new post to a subreddit.
### Parameters
| Name | Type | Required | Description |
|------|------|----------|-------------|
| `subreddit` | string | yes | Subreddit name (without r/ prefix) |
| `title` | string | yes | Post title |
| `kind` | string | no | Post type: self (text), link, image, or video (default: self) |
| `text` | string | no | Post body text for self posts (supports Markdown) |
| `url` | string | no | URL for link posts |
| `nsfw` | boolean | no | Whether the post is NSFW (default: false) |
| `spoiler` | boolean | no | Whether the post is a spoiler (default: false) |
### Examples
```lua
-- Create a text post
local result = app.integrations.reddit.create_post({
subreddit = "test",
title = "Hello from OpenCompany!",
kind = "self",
text = "This is a test post created via the API."
})
print("Post created: " .. result.json.data.name)
-- Create a link post
local result = app.integrations.reddit.create_post({
subreddit = "programming",
title = "Interesting article about Lua",
kind = "link",
url = "https://www.lua.org/"
})
```
---
## list_subreddits
List popular or new subreddits.
### Parameters
| Name | Type | Required | Description |
|------|------|----------|-------------|
| `sort` | string | no | Sort method: popular or new (default: popular) |
| `limit` | integer | no | Number of subreddits to return (default: 25, max: 100) |
| `after` | string | no | Fullname of a subreddit to fetch results after (for pagination) |
| `before` | string | no | Fullname of a subreddit to fetch results before (for pagination) |
### Examples
```lua
-- List popular subreddits
local result = app.integrations.reddit.list_subreddits({
sort = "popular",
limit = 10
})
for _, sub in ipairs(result.data.children) do
print("r/" .. sub.data.display_name .. " - " .. sub.data.subscribers .. " subscribers")
end
-- List new subreddits
local result = app.integrations.reddit.list_subreddits({
sort = "new",
limit = 10
})
for _, sub in ipairs(result.data.children) do
print("r/" .. sub.data.display_name .. " - " .. sub.data.title)
end
```
---
## get_subreddit
Get information about a specific subreddit.
### Parameters
| Name | Type | Required | Description |
|------|------|----------|-------------|
| `subreddit` | string | yes | Subreddit name (without r/ prefix) |
### Examples
```lua
local result = app.integrations.reddit.get_subreddit({
subreddit = "programming"
})
print("r/" .. result.data.display_name)
print("Title: " .. result.data.title)
print("Subscribers: " .. result.data.subscribers)
print("Description: " .. result.data.public_description)
print("Created: " .. os.date("!%Y-%m-%d", result.data.created_utc))
```
---
## list_comments
List comments for a specific Reddit post.
### Parameters
| Name | Type | Required | Description |
|------|------|----------|-------------|
| `subreddit` | string | yes | Subreddit name (without r/ prefix) |
| `post_id` | string | yes | The base36 post ID (e.g., "abc123") |
| `limit` | integer | no | Maximum number of comments to return (default: 25, max: 100) |
| `sort` | string | no | Comment sort order: best, top, new, controversial, old, q&a (default: best) |
| `depth` | integer | no | Maximum comment depth (default: unlimited) |
### Examples
```lua
local result = app.integrations.reddit.list_comments({
subreddit = "programming",
post_id = "abc123",
limit = 10,
sort = "top"
})
-- Comments are in the second element of the response array
for _, comment in ipairs(result[2].data.children) do
if comment.kind == "t1" then
print("u/" .. comment.data.author .. ": " .. comment.data.body:sub(1, 100))
print("Score: " .. comment.data.score)
end
end
```
---
## get_current_user
Get the profile of the currently authenticated Reddit user.
### Parameters
None.
### Examples
```lua
local result = app.integrations.reddit.get_current_user({})
print("Logged in as: u/" .. result.name)
print("Link karma: " .. result.link_karma)
print("Comment karma: " .. result.comment_karma)
```
---
## Multi-Account Usage
If you have multiple Reddit accounts configured, use account-specific namespaces:
```lua
-- Default account (always works)
app.integrations.reddit.function_name({...})
-- Explicit default (portable across setups)
app.integrations.reddit.default.function_name({...})
-- Named accounts
app.integrations.reddit.production.function_name({...})
app.integrations.reddit.staging.function_name({...})
```
All functions are identical across accounts — only the credentials differ. local result = app.integrations.reddit.create_comment({parent = "example_parent", text = "example_text"})
print(result) Functions
create_comment Write
Post a comment on a Reddit post or reply to an existing comment. The comment body supports Markdown formatting. Use "t3_" prefix for post IDs or "t1_" prefix for comment IDs as the parent.
- Lua path
app.integrations.reddit.create_comment- Full name
reddit.reddit_create_comment
| Parameter | Type | Required | Description |
|---|---|---|---|
parent | string | yes | The fullname of the thing to comment on. Use "t3_{post_id}" to comment on a post, or "t1_{comment_id}" to reply to a comment. |
text | string | yes | The comment body. Supports Markdown formatting. |
create_post Write
Submit a new post to a subreddit. Supports text (self), link, image, and video post types.
- Lua path
app.integrations.reddit.create_post- Full name
reddit.reddit_create_post
| Parameter | Type | Required | Description |
|---|---|---|---|
subreddit | string | yes | Subreddit name (without r/ prefix). |
title | string | yes | Post title. |
kind | string | no | Post type: self (text), link, image, or video (default: self). |
text | string | no | Post body text (for self/text posts). Supports Markdown. |
url | string | no | URL (required for link posts). |
nsfw | boolean | no | Whether the post is NSFW (default: false). |
spoiler | boolean | no | Whether the post is a spoiler (default: false). |
get_current_user Read
Get the profile of the currently authenticated Reddit user. Useful for verifying credentials and displaying account information.
- Lua path
app.integrations.reddit.get_current_user- Full name
reddit.reddit_get_current_user
| Parameter | Type | Required | Description |
|---|---|---|---|
| No parameters. | |||
get_post Read
Get details for a specific Reddit post by subreddit and post ID. Returns the post listing and its top-level comments.
- Lua path
app.integrations.reddit.get_post- Full name
reddit.reddit_get_post
| Parameter | Type | Required | Description |
|---|---|---|---|
subreddit | string | yes | Subreddit name (without r/ prefix). |
post_id | string | yes | The base36 post ID (e.g., "abc123"). |
get Read
Get information about a specific subreddit including subscriber count, description, and settings.
- Lua path
app.integrations.reddit.get- Full name
reddit.reddit_get_subreddit
| Parameter | Type | Required | Description |
|---|---|---|---|
subreddit | string | yes | Subreddit name (without r/ prefix). |
list_comments Read
List comments for a specific Reddit post. Supports sorting (best, top, new, controversial, old, q&a) and depth limiting.
- Lua path
app.integrations.reddit.list_comments- Full name
reddit.reddit_list_comments
| Parameter | Type | Required | Description |
|---|---|---|---|
subreddit | string | yes | Subreddit name (without r/ prefix). |
post_id | string | yes | The base36 post ID (e.g., "abc123"). |
limit | integer | no | Maximum number of comments to return (default: 25, max: 100). |
sort | string | no | Comment sort order: best, top, new, controversial, old, q&a (default: best). |
depth | integer | no | Maximum comment depth (default: unlimited). |
list_posts Read
List posts from a subreddit or the Reddit front page. Supports hot, new, top, rising, and controversial sorting with pagination via after/before cursors.
- Lua path
app.integrations.reddit.list_posts- Full name
reddit.reddit_list_posts
| Parameter | Type | Required | Description |
|---|---|---|---|
subreddit | string | no | Subreddit name (without r/ prefix). Leave empty for front page. |
sort | string | no | Sort method: hot, new, top, rising, controversial (default: hot). |
limit | integer | no | Number of posts to return (default: 25, max: 100). |
after | string | no | Fullname of a post to fetch results after (for pagination). |
before | string | no | Fullname of a post to fetch results before (for pagination). |
list Read
List popular or new subreddits. Supports pagination with after/before cursors.
- Lua path
app.integrations.reddit.list- Full name
reddit.reddit_list_subreddits
| Parameter | Type | Required | Description |
|---|---|---|---|
sort | string | no | Sort method: popular or new (default: popular). |
limit | integer | no | Number of subreddits to return (default: 25, max: 100). |
after | string | no | Fullname of a subreddit to fetch results after (for pagination). |
before | string | no | Fullname of a subreddit to fetch results before (for pagination). |
search Read
Search Reddit for posts, subreddits, or users. Supports filtering by type, sorting, and time range. Use this to find relevant content across Reddit.
- Lua path
app.integrations.reddit.search- Full name
reddit.reddit_search
| Parameter | Type | Required | Description |
|---|---|---|---|
query | string | yes | The search query string. |
type | string | no | Result type: "link" (posts), "sr" (subreddits), "user", or comma-separated combinations. Default: "link". |
sort | string | no | Sort order: "relevance", "hot", "top", "new", or "comments". Default: "relevance". |
time | string | no | Time range: "hour", "day", "week", "month", "year", or "all". Default: "all". |
limit | integer | no | Maximum number of results (default: 25, max: 100). |
after | string | no | Pagination cursor — fullname of the last result from a previous response. |