KosmoKrator

productivity

Bland AI Lua API for KosmoKrator Agents

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

Lua Namespace

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

Inline Lua call
kosmo integrations:lua --eval 'dump(app.integrations.blandai.make_call({phone_number = "example_phone_number", task = "example_task", pathway_id = "example_pathway_id", voice = "example_voice", first_sentence = "example_first_sentence", model = "example_model", language = "example_language", wait_for_greeting = true}))' --json
Read Lua docs headlessly
kosmo integrations:lua --eval 'print(docs.read("blandai"))' --json
kosmo integrations:lua --eval 'print(docs.read("blandai.make_call"))' --json

Workflow file

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

workflow.lua
local blandai = app.integrations.blandai
local result = blandai.make_call({phone_number = "example_phone_number", task = "example_task", pathway_id = "example_pathway_id", voice = "example_voice", first_sentence = "example_first_sentence", model = "example_model", language = "example_language", wait_for_greeting = true})

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

MCP-only Lua

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

Bland AI Lua Reference

This integration targets Bland AI’s documented v1 and v2 API surfaces. Configure the base URL as https://api.bland.ai unless Bland provides a regional endpoint. The service sends the API key in the authorization header.

Calls

local call = app.integrations.blandai.make_call({
  phone_number = "+12223334444",
  task = "Confirm the appointment time and summarize any requested changes.",
  voice = "maya",
  record = true,
  wait_for_greeting = true,
  request_data = {
    customer_name = "Ada"
  },
  webhook = "https://example.test/bland-webhook"
})

You can use pathway_id instead of task for conversational pathway calls.

local calls = app.integrations.blandai.list_calls({
  limit = 20,
  batch_id = "batch_123"
})

local detail = app.integrations.blandai.get_call({
  call_id = "call_123"
})

app.integrations.blandai.stop_call({ call_id = "call_123" })
app.integrations.blandai.stop_all_active_calls({})

Analysis

local result = app.integrations.blandai.analyze_call({
  call_id = "call_123",
  goal = "Understand the call outcome",
  questions = {
    { "Who answered the call?", "human or voicemail" },
    { "Did the customer confirm the appointment?", "boolean" }
  }
})

Batches

local batch = app.integrations.blandai.create_batch({
  name = "Appointment reminders",
  phone_numbers = {
    { phone_number = "+12223334444", request_data = { customer_name = "Ada" } }
  },
  call_params = {
    task = "Remind the customer about their appointment.",
    voice = "maya"
  }
})

local batches = app.integrations.blandai.list_batches({
  take = 25,
  skip = 0
})

Passing sequence turns a batch into a campaign with retries.

Voices

local voices = app.integrations.blandai.list_voices({})
local voice = app.integrations.blandai.get_voice({ voice_id = "maya" })

Knowledge Bases

local bases = app.integrations.blandai.list_knowledge_bases({
  limit = 20
})

local kb = app.integrations.blandai.create_text_knowledge_base({
  name = "Support FAQ",
  description = "Refund and shipping policy answers",
  text = "Refunds are available within 30 days..."
})

app.integrations.blandai.update_knowledge_base({
  knowledge_base_id = "kb_123",
  name = "Updated Support FAQ"
})

local answer = app.integrations.blandai.chat_knowledge_base({
  knowledge_base_id = "kb_123",
  messages = {
    { role = "user", content = "What is the refund policy?" }
  }
})

Custom Tools

local tool = app.integrations.blandai.create_tool({
  name = "lookup_order",
  description = "Look up order status",
  url = "https://example.test/orders",
  method = "GET",
  query = {
    order_id = "{{order_id}}"
  }
})

Account Check

get_current_user is retained for compatibility. Bland AI does not expose a dedicated current-user endpoint in the documented public API, so this performs a lightweight call-list check.

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

Multi-Account Usage

app.integrations.blandai.make_call({...})
app.integrations.blandai.default.make_call({...})
app.integrations.blandai.sales.make_call({...})
Raw agent markdown
# Bland AI Lua Reference

This integration targets Bland AI's documented v1 and v2 API surfaces. Configure the base URL as `https://api.bland.ai` unless Bland provides a regional endpoint. The service sends the API key in the `authorization` header.

## Calls

```lua
local call = app.integrations.blandai.make_call({
  phone_number = "+12223334444",
  task = "Confirm the appointment time and summarize any requested changes.",
  voice = "maya",
  record = true,
  wait_for_greeting = true,
  request_data = {
    customer_name = "Ada"
  },
  webhook = "https://example.test/bland-webhook"
})
```

You can use `pathway_id` instead of `task` for conversational pathway calls.

```lua
local calls = app.integrations.blandai.list_calls({
  limit = 20,
  batch_id = "batch_123"
})

local detail = app.integrations.blandai.get_call({
  call_id = "call_123"
})

app.integrations.blandai.stop_call({ call_id = "call_123" })
app.integrations.blandai.stop_all_active_calls({})
```

## Analysis

```lua
local result = app.integrations.blandai.analyze_call({
  call_id = "call_123",
  goal = "Understand the call outcome",
  questions = {
    { "Who answered the call?", "human or voicemail" },
    { "Did the customer confirm the appointment?", "boolean" }
  }
})
```

## Batches

```lua
local batch = app.integrations.blandai.create_batch({
  name = "Appointment reminders",
  phone_numbers = {
    { phone_number = "+12223334444", request_data = { customer_name = "Ada" } }
  },
  call_params = {
    task = "Remind the customer about their appointment.",
    voice = "maya"
  }
})

local batches = app.integrations.blandai.list_batches({
  take = 25,
  skip = 0
})
```

Passing `sequence` turns a batch into a campaign with retries.

## Voices

```lua
local voices = app.integrations.blandai.list_voices({})
local voice = app.integrations.blandai.get_voice({ voice_id = "maya" })
```

## Knowledge Bases

```lua
local bases = app.integrations.blandai.list_knowledge_bases({
  limit = 20
})

local kb = app.integrations.blandai.create_text_knowledge_base({
  name = "Support FAQ",
  description = "Refund and shipping policy answers",
  text = "Refunds are available within 30 days..."
})

app.integrations.blandai.update_knowledge_base({
  knowledge_base_id = "kb_123",
  name = "Updated Support FAQ"
})

local answer = app.integrations.blandai.chat_knowledge_base({
  knowledge_base_id = "kb_123",
  messages = {
    { role = "user", content = "What is the refund policy?" }
  }
})
```

## Custom Tools

```lua
local tool = app.integrations.blandai.create_tool({
  name = "lookup_order",
  description = "Look up order status",
  url = "https://example.test/orders",
  method = "GET",
  query = {
    order_id = "{{order_id}}"
  }
})
```

## Account Check

`get_current_user` is retained for compatibility. Bland AI does not expose a dedicated current-user endpoint in the documented public API, so this performs a lightweight call-list check.

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

## Multi-Account Usage

```lua
app.integrations.blandai.make_call({...})
app.integrations.blandai.default.make_call({...})
app.integrations.blandai.sales.make_call({...})
```
Metadata-derived Lua example
local result = app.integrations.blandai.make_call({phone_number = "example_phone_number", task = "example_task", pathway_id = "example_pathway_id", voice = "example_voice", first_sentence = "example_first_sentence", model = "example_model", language = "example_language", wait_for_greeting = true})
print(result)

Functions

make_call Write

Initiate an AI-powered phone call via BlandAI. The AI agent will follow the provided task instructions and speak using the specified voice.

Lua path
app.integrations.blandai.make_call
Full name
blandai.blandai_make_call
ParameterTypeRequiredDescription
phone_number string yes The phone number to call in E.164 format (e.g., "+1234567890").
task string no Instructions or task description for the AI agent to follow during the call.
pathway_id string no Conversational pathway ID. Required when task is omitted.
voice string no Voice identifier to use for the call (e.g., a voice name or ID). Leave empty for the default voice.
first_sentence string no Optional first sentence the AI should say.
model string no Optional model name.
language string no Optional call language.
wait_for_greeting boolean no Whether to wait for the callee to speak first before the AI begins (default: false).
record boolean no Whether to record the call (default: true).
max_duration integer no Maximum call duration in minutes.
from string no Outbound caller ID number.
request_data object no Variables available to the call agent.
metadata object no Metadata stored with the call.
webhook string no Webhook URL for call events.
get_call Read

Retrieve details for a specific BlandAI phone call, including status, transcript, duration, and metadata.

Lua path
app.integrations.blandai.get_call
Full name
blandai.blandai_get_call
ParameterTypeRequiredDescription
call_id string yes The unique identifier of the call to retrieve.
list_calls Read

List BlandAI phone calls with optional pagination. Returns call summaries including status, duration, and phone numbers.

Lua path
app.integrations.blandai.list_calls
Full name
blandai.blandai_list_calls
ParameterTypeRequiredDescription
limit integer no Maximum number of calls to return (default: 50).
after string no Cursor value from the previous response.
from_number string no Filter by dispatching phone number.
to_number string no Filter by called phone number.
batch_id string no Filter by batch ID.
start_date string no Start date/time filter.
end_date string no End date/time filter.
stop_call Write

Stop an active Bland AI call by call ID.

Lua path
app.integrations.blandai.stop_call
Full name
blandai.blandai_stop_call
ParameterTypeRequiredDescription
call_id string yes Call ID to stop.
stop_all_active_calls Write

Stop all currently active Bland AI calls on the account.

Lua path
app.integrations.blandai.stop_all_active_calls
Full name
blandai.blandai_stop_all_active_calls
ParameterTypeRequiredDescription
No parameters.
analyze_call Read

Analyze a BlandAI call transcript with a custom prompt. Extract insights, summarize the conversation, or evaluate call outcomes.

Lua path
app.integrations.blandai.analyze_call
Full name
blandai.blandai_analyze_call
ParameterTypeRequiredDescription
call_id string yes The unique identifier of the call to analyze.
goal string no Overall purpose of the analysis.
questions array no Array of [question, expected_type] pairs.
prompt string no Backward-compatible alias for goal when questions are omitted.
create_batch Write

Create a Bland AI batch or campaign with phone numbers, shared call params, and optional sequence.

Lua path
app.integrations.blandai.create_batch
Full name
blandai.blandai_create_batch
ParameterTypeRequiredDescription
name string yes Batch/campaign name.
phone_numbers array yes Array of phone number objects.
call_params object no Shared Send Call parameters applied to each call.
sequence object no Optional campaign retry sequence.
list_batches Read

List Bland AI batches and campaigns.

Lua path
app.integrations.blandai.list_batches
Full name
blandai.blandai_list_batches
ParameterTypeRequiredDescription
take integer no Number of batches to return.
skip integer no Number of batches to skip.
list_voices Read

List Bland AI voices available for calls.

Lua path
app.integrations.blandai.list_voices
Full name
blandai.blandai_list_voices
ParameterTypeRequiredDescription
No parameters.
get_voice Read

Get details for a Bland AI voice by name or ID.

Lua path
app.integrations.blandai.get_voice
Full name
blandai.blandai_get_voice
ParameterTypeRequiredDescription
voice_id string yes Voice name or ID.
list_knowledge_bases Read

List Bland AI knowledge bases for the authenticated organization.

Lua path
app.integrations.blandai.list_knowledge_bases
Full name
blandai.blandai_list_knowledge_bases
ParameterTypeRequiredDescription
limit integer no Optional page size.
offset integer no Optional offset.
status string no Optional status filter.
create_text_knowledge_base Write

Create a Bland AI text knowledge base from plain text.

Lua path
app.integrations.blandai.create_text_knowledge_base
Full name
blandai.blandai_create_text_knowledge_base
ParameterTypeRequiredDescription
name string yes Knowledge base name.
text string yes Knowledge base text content.
description string no Optional description.
update_knowledge_base Write

Update a Bland AI knowledge base name and/or description.

Lua path
app.integrations.blandai.update_knowledge_base
Full name
blandai.blandai_update_knowledge_base
ParameterTypeRequiredDescription
knowledge_base_id string yes Knowledge base ID.
name string no New knowledge base name.
description string no New description.
chat_knowledge_base Write

Ask a question or continue a chat against a Bland AI knowledge base.

Lua path
app.integrations.blandai.chat_knowledge_base
Full name
blandai.blandai_chat_knowledge_base
ParameterTypeRequiredDescription
knowledge_base_id string yes Knowledge base ID.
messages array yes Chat messages with role and content.
create_tool Write

Create a Bland AI custom tool for call agents.

Lua path
app.integrations.blandai.create_tool
Full name
blandai.blandai_create_tool
ParameterTypeRequiredDescription
name string yes Tool name.
description string no Tool description.
url string yes External API URL.
method string yes HTTP method, usually GET or POST.
headers object no Optional request headers.
body object no Optional request body schema/defaults.
query object no Optional query schema/defaults.
get_current_user Read

Get the authenticated BlandAI user's account information. Useful for verifying credentials and checking account details.

Lua path
app.integrations.blandai.get_current_user
Full name
blandai.blandai_get_current_user
ParameterTypeRequiredDescription
No parameters.