KosmoKrator

ai

Anthropic Lua API for KosmoKrator Agents

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

7 functions 6 read 1 write API key auth

Lua Namespace

Agents call this integration through app.integrations.anthropic.*. Use lua_read_doc("integrations.anthropic") 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.

Anthropic (Claude) — Lua API Reference

list_messages

List messages in the Anthropic conversation history.

Parameters

NameTypeRequiredDescription
modelstringnoFilter messages by model ID (e.g., “claude-sonnet-4-20250514”)
limitintegernoMax messages per page (default: 20, max: 1000)
before_idstringnoReturn messages before this message ID
after_idstringnoReturn messages after this message ID

Example

local result = app.integrations["anthropic"].list_messages({
  limit = 10
})

for _, msg in ipairs(result.data) do
  print(msg.id .. " — " .. msg.model .. " — " .. msg.role)
end

create_message

Send a prompt to Claude and receive an AI-generated response.

Parameters

NameTypeRequiredDescription
modelstringyesThe model to use (e.g., “claude-sonnet-4-20250514”)
messagesarrayyesArray of message objects with role and content
max_tokensintegernoMaximum tokens to generate (default: 4096)
systemstringnoSystem prompt to set behavior and context
temperaturenumbernoRandomness control (0.0–1.0)
top_pnumbernoNucleus sampling parameter (0.0–1.0)
stop_sequencesarraynoStrings that stop generation when encountered
streambooleannoStream response incrementally (default: false)

Message Format

The messages array contains message objects:

{
  { role = "user", content = "Your prompt here" }
}

For multi-turn conversations:

{
  { role = "user", content = "Hello!" },
  { role = "assistant", content = "Hi there!" },
  { role = "user", content = "Tell me more." }
}

Example

local result = app.integrations["anthropic"].create_message({
  model = "claude-sonnet-4-20250514",
  messages = {
    { role = "user", content = "Write a haiku about programming." }
  },
  max_tokens = 100,
  temperature = 0.7
})

for _, block in ipairs(result.content) do
  if block.type == "text" then
    print(block.text)
  end
end

print("Stop reason: " .. result.stop_reason)
print("Usage input: " .. result.usage.input_tokens .. ", output: " .. result.usage.output_tokens)

list_models

List available Anthropic AI models.

Parameters

NameTypeRequiredDescription
limitintegernoMax models per page (default: 20, max: 1000)
before_idstringnoReturn models before this ID
after_idstringnoReturn models after this ID

Example

local result = app.integrations["anthropic"].list_models({
  limit = 10
})

for _, model in ipairs(result.data) do
  print(model.id .. " — " .. model.display_name)
end

get_model

Get detailed information about a specific Anthropic model.

Parameters

NameTypeRequiredDescription
idstringyesModel identifier, e.g. "claude-sonnet-4-20250514"

Example

local result = app.integrations["anthropic"].get_model({
  id = "claude-sonnet-4-20250514"
})

print("Model: " .. result.display_name)
print("Created: " .. result.created_at)

list_workspaces

List Anthropic workspaces.

Parameters

NameTypeRequiredDescription
limitintegernoMax workspaces per page (default: 20, max: 1000)
before_idstringnoReturn workspaces before this ID
after_idstringnoReturn workspaces after this ID

Example

local result = app.integrations["anthropic"].list_workspaces({
  limit = 10
})

for _, ws in ipairs(result.data) do
  print(ws.id .. " — " .. ws.name)
end

get_workspace

Get details for a specific Anthropic workspace.

Parameters

NameTypeRequiredDescription
idstringyesThe workspace identifier

Example

local result = app.integrations["anthropic"].get_workspace({
  id = "wrksp_01ABC123"
})

print("Workspace: " .. result.name)

get_current_user

Get the authenticated user’s profile and account information.

Parameters

None.

Example

local result = app.integrations["anthropic"].get_current_user({})

print("User: " .. (result.name or "unknown"))

Multi-Account Usage

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

-- Default account (always works)
app.integrations["anthropic"].function_name({...})

-- Explicit default (portable across setups)
app.integrations["anthropic"].default.function_name({...})

-- Named accounts
app.integrations["anthropic"].work.function_name({...})
app.integrations["anthropic"].personal.function_name({...})

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

Raw agent markdown
# Anthropic (Claude) — Lua API Reference

## list_messages

List messages in the Anthropic conversation history.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `model` | string | no | Filter messages by model ID (e.g., "claude-sonnet-4-20250514") |
| `limit` | integer | no | Max messages per page (default: 20, max: 1000) |
| `before_id` | string | no | Return messages before this message ID |
| `after_id` | string | no | Return messages after this message ID |

### Example

```lua
local result = app.integrations["anthropic"].list_messages({
  limit = 10
})

for _, msg in ipairs(result.data) do
  print(msg.id .. " — " .. msg.model .. " — " .. msg.role)
end
```

---

## create_message

Send a prompt to Claude and receive an AI-generated response.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `model` | string | yes | The model to use (e.g., "claude-sonnet-4-20250514") |
| `messages` | array | yes | Array of message objects with `role` and `content` |
| `max_tokens` | integer | no | Maximum tokens to generate (default: 4096) |
| `system` | string | no | System prompt to set behavior and context |
| `temperature` | number | no | Randomness control (0.0–1.0) |
| `top_p` | number | no | Nucleus sampling parameter (0.0–1.0) |
| `stop_sequences` | array | no | Strings that stop generation when encountered |
| `stream` | boolean | no | Stream response incrementally (default: false) |

### Message Format

The `messages` array contains message objects:

```lua
{
  { role = "user", content = "Your prompt here" }
}
```

For multi-turn conversations:

```lua
{
  { role = "user", content = "Hello!" },
  { role = "assistant", content = "Hi there!" },
  { role = "user", content = "Tell me more." }
}
```

### Example

```lua
local result = app.integrations["anthropic"].create_message({
  model = "claude-sonnet-4-20250514",
  messages = {
    { role = "user", content = "Write a haiku about programming." }
  },
  max_tokens = 100,
  temperature = 0.7
})

for _, block in ipairs(result.content) do
  if block.type == "text" then
    print(block.text)
  end
end

print("Stop reason: " .. result.stop_reason)
print("Usage input: " .. result.usage.input_tokens .. ", output: " .. result.usage.output_tokens)
```

---

## list_models

List available Anthropic AI models.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `limit` | integer | no | Max models per page (default: 20, max: 1000) |
| `before_id` | string | no | Return models before this ID |
| `after_id` | string | no | Return models after this ID |

### Example

```lua
local result = app.integrations["anthropic"].list_models({
  limit = 10
})

for _, model in ipairs(result.data) do
  print(model.id .. " — " .. model.display_name)
end
```

---

## get_model

Get detailed information about a specific Anthropic model.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `id` | string | yes | Model identifier, e.g. `"claude-sonnet-4-20250514"` |

### Example

```lua
local result = app.integrations["anthropic"].get_model({
  id = "claude-sonnet-4-20250514"
})

print("Model: " .. result.display_name)
print("Created: " .. result.created_at)
```

---

## list_workspaces

List Anthropic workspaces.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `limit` | integer | no | Max workspaces per page (default: 20, max: 1000) |
| `before_id` | string | no | Return workspaces before this ID |
| `after_id` | string | no | Return workspaces after this ID |

### Example

```lua
local result = app.integrations["anthropic"].list_workspaces({
  limit = 10
})

for _, ws in ipairs(result.data) do
  print(ws.id .. " — " .. ws.name)
end
```

---

## get_workspace

Get details for a specific Anthropic workspace.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `id` | string | yes | The workspace identifier |

### Example

```lua
local result = app.integrations["anthropic"].get_workspace({
  id = "wrksp_01ABC123"
})

print("Workspace: " .. result.name)
```

---

## get_current_user

Get the authenticated user's profile and account information.

### Parameters

None.

### Example

```lua
local result = app.integrations["anthropic"].get_current_user({})

print("User: " .. (result.name or "unknown"))
```

---

## Multi-Account Usage

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

```lua
-- Default account (always works)
app.integrations["anthropic"].function_name({...})

-- Explicit default (portable across setups)
app.integrations["anthropic"].default.function_name({...})

-- Named accounts
app.integrations["anthropic"].work.function_name({...})
app.integrations["anthropic"].personal.function_name({...})
```

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

Metadata-Derived Lua Example

local result = app.integrations.anthropic.anthropic_list_messages({
  model = "example_model",
  limit = 1,
  before_id = "example_before_id",
  after_id = "example_after_id"
})
print(result)

Functions

anthropic_list_messages

List messages in the Anthropic conversation history. Returns paginated message resources with optional filtering by model, date, and ID.

Operation
Read read
Full name
anthropic.anthropic_list_messages
ParameterTypeRequiredDescription
model string no Filter messages by model ID (e.g., "claude-sonnet-4-20250514").
limit integer no Maximum number of messages to return per page (default: 20, max: 1000).
before_id string no Message ID used for cursor-based pagination — return messages before this ID.
after_id string no Message ID used for cursor-based pagination — return messages after this ID.

anthropic_create_message

Send a prompt to Claude and receive an AI-generated response. Supports multi-turn conversations, system prompts, temperature control, and configurable output length.

Operation
Write write
Full name
anthropic.anthropic_create_message
ParameterTypeRequiredDescription
model string yes The model to use (e.g., "claude-sonnet-4-20250514", "claude-haiku-4-20250414").
messages array yes Array of message objects with "role" ("user" or "assistant") and "content" (string or array of content blocks).
max_tokens integer no Maximum number of tokens to generate in the response (default: 4096).
system string no System prompt to set the behavior and context for Claude.
temperature number no Controls randomness in generation (0.0–1.0). Lower values are more deterministic.
top_p number no Nucleus sampling parameter (0.0–1.0). Limits cumulative probability of tokens considered.
stop_sequences array no Array of strings that will cause the model to stop generating if encountered.
stream boolean no Whether to stream the response incrementally (default: false).

anthropic_list_models

List available Anthropic AI models. Returns model identifiers, creation dates, and display names.

Operation
Read read
Full name
anthropic.anthropic_list_models
ParameterTypeRequiredDescription
limit integer no Maximum number of models to return per page (default: 20, max: 1000).
before_id string no Model ID used for cursor-based pagination — return models before this ID.
after_id string no Model ID used for cursor-based pagination — return models after this ID.

anthropic_get_model

Get detailed information about a specific Anthropic model, including its display name, creation date, and capabilities.

Operation
Read read
Full name
anthropic.anthropic_get_model
ParameterTypeRequiredDescription
id string yes The model identifier (e.g., "claude-sonnet-4-20250514").

anthropic_list_workspaces

List Anthropic workspaces. Returns workspace identifiers, names, and configuration details.

Operation
Read read
Full name
anthropic.anthropic_list_workspaces
ParameterTypeRequiredDescription
limit integer no Maximum number of workspaces to return per page (default: 20, max: 1000).
before_id string no Workspace ID used for cursor-based pagination — return workspaces before this ID.
after_id string no Workspace ID used for cursor-based pagination — return workspaces after this ID.

anthropic_get_workspace

Get detailed information about a specific Anthropic workspace, including its name, configuration, and usage settings.

Operation
Read read
Full name
anthropic.anthropic_get_workspace
ParameterTypeRequiredDescription
id string yes The workspace identifier.

anthropic_get_current_user

Get the authenticated user's profile and account information.

Operation
Read read
Full name
anthropic.anthropic_get_current_user
ParameterTypeRequiredDescription
No parameters.