KosmoKrator

productivity

Anthropic Lua API for KosmoKrator Agents

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

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.

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 Anthropic workflow without starting an interactive agent session.

Inline Lua call
kosmo integrations:lua --eval 'dump(app.integrations.anthropic.list_messages({model = "example_model", limit = 1, before_id = "example_before_id", after_id = "example_after_id"}))' --json
Read Lua docs headlessly
kosmo integrations:lua --eval 'print(docs.read("anthropic"))' --json
kosmo integrations:lua --eval 'print(docs.read("anthropic.list_messages"))' --json

Workflow file

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

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

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

MCP-only Lua

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

Anthropic (Claude) - Lua API Reference

Namespace: app.integrations["anthropic"]

This integration covers the public Anthropic Messages, token counting, models, Message Batches, and beta Files APIs. Organization, user, workspace, and API-key administration tools require the optional admin_key credential.

Messages

create_message

Create a Claude message with the same JSON payload shape as POST /v1/messages.

Required: model, messages

Common optional fields: max_tokens, system, temperature, top_p, stop_sequences, tools, tool_choice, thinking, metadata, stream.

local result = app.integrations["anthropic"].create_message({
  model = "claude-sonnet-4-20250514",
  max_tokens = 256,
  messages = {
    { role = "user", content = "Summarize prompt caching in one paragraph." }
  }
})

print(result.id)
print(result.usage.input_tokens)

count_message_tokens

Count input tokens for a Messages API payload without creating a message.

local result = app.integrations["anthropic"].count_message_tokens({
  payload = {
    model = "claude-sonnet-4-20250514",
    messages = {
      { role = "user", content = "Hello, Claude" }
    }
  }
})

print(result.input_tokens)

list_messages

Deprecated compatibility alias. Anthropic does not expose a message-history listing endpoint. This tool returns an explicit unsupported-capability error; use list_message_batches for batch job history.

Message Batches

Message Batch results are JSONL and are returned as { content_type, body }. Rows are not guaranteed to be in request order; match them by custom_id.

local batch = app.integrations["anthropic"].create_message_batch({
  payload = {
    requests = {
      {
        custom_id = "example-1",
        params = {
          model = "claude-sonnet-4-20250514",
          max_tokens = 128,
          messages = {
            { role = "user", content = "Write one sentence about CI." }
          }
        }
      }
    }
  }
})

local current = app.integrations["anthropic"].get_message_batch({
  id = batch.id
})

print(current.processing_status)

Available batch tools:

  • create_message_batch({ payload = { requests = ... } })
  • list_message_batches({ query = { limit = 20 } })
  • get_message_batch({ id = "msgbatch_..." })
  • cancel_message_batch({ id = "msgbatch_..." })
  • delete_message_batch({ id = "msgbatch_..." })
  • get_message_batch_results({ id = "msgbatch_..." })

Models

local models = app.integrations["anthropic"].list_models({
  limit = 20
})

for _, model in ipairs(models.data or {}) do
  print(model.id .. " - " .. model.display_name)
end

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

Files API

Files API operations use the required beta header internally: anthropic-beta: files-api-2025-04-14.

Uploaded files can be referenced from Messages payloads using content block sources with { type = "file", file_id = "file_..." }. Downloading is only available for files Anthropic marks as downloadable, such as code-execution outputs.

local files = app.integrations["anthropic"].list_files({
  query = { limit = 20 }
})

local file = app.integrations["anthropic"].get_file({
  id = "file_011example"
})

local content = app.integrations["anthropic"].download_file({
  id = "file_011downloadable"
})

print(content.content_type)

Available file tools:

  • list_files({ query = { limit = 20 } })
  • get_file({ id = "file_..." })
  • delete_file({ id = "file_..." })
  • download_file({ id = "file_..." })

Admin API

The following tools require admin_key, not a normal workspace API key. Admin API is unavailable for individual accounts.

local org = app.integrations["anthropic"].get_organization({})

local users = app.integrations["anthropic"].list_users({
  query = { limit = 20 }
})

local keys = app.integrations["anthropic"].list_api_keys({
  query = { limit = 20, status = "active" }
})

Available Admin API tools:

  • get_organization({})
  • list_workspaces({ limit = 20, include_archived = false })
  • get_workspace({ id = "wrkspc_..." })
  • list_users({ query = { limit = 20 } })
  • get_user({ id = "user_..." })
  • update_user({ id = "user_...", payload = { role = "developer" } })
  • remove_user({ id = "user_..." })
  • list_api_keys({ query = { limit = 20 } })
  • get_api_key({ id = "apikey_..." })

get_current_user({}) is kept as a backward-compatible alias for get_organization({}); Anthropic does not expose a /users/me endpoint.

Multi-Account Usage

app.integrations["anthropic"].create_message({...})
app.integrations["anthropic"].default.create_message({...})
app.integrations["anthropic"].work.create_message({...})

All functions are identical across accounts. Only the credentials differ.

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

Namespace: `app.integrations["anthropic"]`

This integration covers the public Anthropic Messages, token counting, models,
Message Batches, and beta Files APIs. Organization, user, workspace, and API-key
administration tools require the optional `admin_key` credential.

## Messages

### create_message

Create a Claude message with the same JSON payload shape as `POST /v1/messages`.

Required: `model`, `messages`

Common optional fields: `max_tokens`, `system`, `temperature`, `top_p`,
`stop_sequences`, `tools`, `tool_choice`, `thinking`, `metadata`, `stream`.

```lua
local result = app.integrations["anthropic"].create_message({
  model = "claude-sonnet-4-20250514",
  max_tokens = 256,
  messages = {
    { role = "user", content = "Summarize prompt caching in one paragraph." }
  }
})

print(result.id)
print(result.usage.input_tokens)
```

### count_message_tokens

Count input tokens for a Messages API payload without creating a message.

```lua
local result = app.integrations["anthropic"].count_message_tokens({
  payload = {
    model = "claude-sonnet-4-20250514",
    messages = {
      { role = "user", content = "Hello, Claude" }
    }
  }
})

print(result.input_tokens)
```

### list_messages

Deprecated compatibility alias. Anthropic does not expose a message-history
listing endpoint. This tool returns an explicit unsupported-capability error;
use `list_message_batches` for batch job history.

## Message Batches

Message Batch results are JSONL and are returned as `{ content_type, body }`.
Rows are not guaranteed to be in request order; match them by `custom_id`.

```lua
local batch = app.integrations["anthropic"].create_message_batch({
  payload = {
    requests = {
      {
        custom_id = "example-1",
        params = {
          model = "claude-sonnet-4-20250514",
          max_tokens = 128,
          messages = {
            { role = "user", content = "Write one sentence about CI." }
          }
        }
      }
    }
  }
})

local current = app.integrations["anthropic"].get_message_batch({
  id = batch.id
})

print(current.processing_status)
```

Available batch tools:

- `create_message_batch({ payload = { requests = ... } })`
- `list_message_batches({ query = { limit = 20 } })`
- `get_message_batch({ id = "msgbatch_..." })`
- `cancel_message_batch({ id = "msgbatch_..." })`
- `delete_message_batch({ id = "msgbatch_..." })`
- `get_message_batch_results({ id = "msgbatch_..." })`

## Models

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

for _, model in ipairs(models.data or {}) do
  print(model.id .. " - " .. model.display_name)
end

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

## Files API

Files API operations use the required beta header internally:
`anthropic-beta: files-api-2025-04-14`.

Uploaded files can be referenced from Messages payloads using content block
sources with `{ type = "file", file_id = "file_..." }`. Downloading is only
available for files Anthropic marks as downloadable, such as code-execution
outputs.

```lua
local files = app.integrations["anthropic"].list_files({
  query = { limit = 20 }
})

local file = app.integrations["anthropic"].get_file({
  id = "file_011example"
})

local content = app.integrations["anthropic"].download_file({
  id = "file_011downloadable"
})

print(content.content_type)
```

Available file tools:

- `list_files({ query = { limit = 20 } })`
- `get_file({ id = "file_..." })`
- `delete_file({ id = "file_..." })`
- `download_file({ id = "file_..." })`

## Admin API

The following tools require `admin_key`, not a normal workspace API key.
Admin API is unavailable for individual accounts.

```lua
local org = app.integrations["anthropic"].get_organization({})

local users = app.integrations["anthropic"].list_users({
  query = { limit = 20 }
})

local keys = app.integrations["anthropic"].list_api_keys({
  query = { limit = 20, status = "active" }
})
```

Available Admin API tools:

- `get_organization({})`
- `list_workspaces({ limit = 20, include_archived = false })`
- `get_workspace({ id = "wrkspc_..." })`
- `list_users({ query = { limit = 20 } })`
- `get_user({ id = "user_..." })`
- `update_user({ id = "user_...", payload = { role = "developer" } })`
- `remove_user({ id = "user_..." })`
- `list_api_keys({ query = { limit = 20 } })`
- `get_api_key({ id = "apikey_..." })`

`get_current_user({})` is kept as a backward-compatible alias for
`get_organization({})`; Anthropic does not expose a `/users/me` endpoint.

## Multi-Account Usage

```lua
app.integrations["anthropic"].create_message({...})
app.integrations["anthropic"].default.create_message({...})
app.integrations["anthropic"].work.create_message({...})
```

All functions are identical across accounts. Only the credentials differ.
Metadata-derived Lua example
local result = app.integrations.anthropic.list_messages({model = "example_model", limit = 1, before_id = "example_before_id", after_id = "example_after_id"})
print(result)

Functions

list_messages Read

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

Lua path
app.integrations.anthropic.list_messages
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.
create_message Write

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

Lua path
app.integrations.anthropic.create_message
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).
count_message_tokens Read

Count input tokens for a Messages API payload.

Lua path
app.integrations.anthropic.count_message_tokens
Full name
anthropic.anthropic_count_message_tokens
ParameterTypeRequiredDescription
No parameters.
create_message_batch Write

Create an asynchronous Message Batch.

Lua path
app.integrations.anthropic.create_message_batch
Full name
anthropic.anthropic_create_message_batch
ParameterTypeRequiredDescription
No parameters.
list_message_batches Read

List Message Batches in the API key workspace.

Lua path
app.integrations.anthropic.list_message_batches
Full name
anthropic.anthropic_list_message_batches
ParameterTypeRequiredDescription
No parameters.
get_message_batch Read

Get processing status for one Message Batch.

Lua path
app.integrations.anthropic.get_message_batch
Full name
anthropic.anthropic_get_message_batch
ParameterTypeRequiredDescription
No parameters.
cancel_message_batch Write

Cancel an in-progress Message Batch.

Lua path
app.integrations.anthropic.cancel_message_batch
Full name
anthropic.anthropic_cancel_message_batch
ParameterTypeRequiredDescription
No parameters.
delete_message_batch Write

Delete a completed Message Batch.

Lua path
app.integrations.anthropic.delete_message_batch
Full name
anthropic.anthropic_delete_message_batch
ParameterTypeRequiredDescription
No parameters.
get_message_batch_results Read

Retrieve JSONL results for a completed Message Batch.

Lua path
app.integrations.anthropic.get_message_batch_results
Full name
anthropic.anthropic_get_message_batch_results
ParameterTypeRequiredDescription
No parameters.
list_models Read

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

Lua path
app.integrations.anthropic.list_models
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.
get_model Read

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

Lua path
app.integrations.anthropic.get_model
Full name
anthropic.anthropic_get_model
ParameterTypeRequiredDescription
id string yes The model identifier (e.g., "claude-sonnet-4-20250514").
list_files Read

List files in the API key workspace.

Lua path
app.integrations.anthropic.list_files
Full name
anthropic.anthropic_list_files
ParameterTypeRequiredDescription
No parameters.
get_file Read

Get metadata for one Anthropic file.

Lua path
app.integrations.anthropic.get_file
Full name
anthropic.anthropic_get_file
ParameterTypeRequiredDescription
No parameters.
delete_file Write

Delete one Anthropic file.

Lua path
app.integrations.anthropic.delete_file
Full name
anthropic.anthropic_delete_file
ParameterTypeRequiredDescription
No parameters.
download_file Read

Download content for a downloadable code-execution file.

Lua path
app.integrations.anthropic.download_file
Full name
anthropic.anthropic_download_file
ParameterTypeRequiredDescription
No parameters.
get_organization Read

Get organization information using the Admin API.

Lua path
app.integrations.anthropic.get_organization
Full name
anthropic.anthropic_get_organization
ParameterTypeRequiredDescription
No parameters.
list_organization_workspaces Read

List Anthropic organization workspaces. Requires an Admin API key.

Lua path
app.integrations.anthropic.list_organization_workspaces
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.
include_archived boolean no Whether to include archived workspaces.
get_organization_workspace Read

Get details for a specific Anthropic organization workspace. Requires an Admin API key.

Lua path
app.integrations.anthropic.get_organization_workspace
Full name
anthropic.anthropic_get_workspace
ParameterTypeRequiredDescription
id string yes The workspace identifier.
list_users Read

List organization users using the Admin API.

Lua path
app.integrations.anthropic.list_users
Full name
anthropic.anthropic_list_users
ParameterTypeRequiredDescription
No parameters.
get_user Read

Get one organization user using the Admin API.

Lua path
app.integrations.anthropic.get_user
Full name
anthropic.anthropic_get_user
ParameterTypeRequiredDescription
No parameters.
update_user Write

Update an organization user role using the Admin API.

Lua path
app.integrations.anthropic.update_user
Full name
anthropic.anthropic_update_user
ParameterTypeRequiredDescription
No parameters.
remove_user Write

Remove an organization user using the Admin API.

Lua path
app.integrations.anthropic.remove_user
Full name
anthropic.anthropic_remove_user
ParameterTypeRequiredDescription
No parameters.
list_api_keys Read

List organization API keys using the Admin API.

Lua path
app.integrations.anthropic.list_api_keys
Full name
anthropic.anthropic_list_api_keys
ParameterTypeRequiredDescription
No parameters.
get_api_key Read

Get one organization API key metadata record using the Admin API.

Lua path
app.integrations.anthropic.get_api_key
Full name
anthropic.anthropic_get_api_key
ParameterTypeRequiredDescription
No parameters.
get_organization_alias Read

Backward-compatible alias for Anthropic organization information. Requires an Admin API key.

Lua path
app.integrations.anthropic.get_organization_alias
Full name
anthropic.anthropic_get_current_user
ParameterTypeRequiredDescription
No parameters.