KosmoKrator

rendering

APITemplate.io Lua API for KosmoKrator Agents

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

Lua Namespace

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

Inline Lua call
kosmo integrations:lua --eval 'dump(app.integrations.apitemplateio.create_pdf({template_id = "example_template_id", data = "example_data", export_type = "example_export_type", output_format = "example_output_format", output_html = true, expiration = 1, expire = 1, filename = "example_filename"}))' --json
Read Lua docs headlessly
kosmo integrations:lua --eval 'print(docs.read("apitemplateio"))' --json
kosmo integrations:lua --eval 'print(docs.read("apitemplateio.create_pdf"))' --json

Workflow file

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

workflow.lua
local apitemplateio = app.integrations.apitemplateio
local result = apitemplateio.create_pdf({template_id = "example_template_id", data = "example_data", export_type = "example_export_type", output_format = "example_output_format", output_html = true, expiration = 1, expire = 1, filename = "example_filename"})

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

MCP-only Lua

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

APITemplate.io Lua Reference

APITemplate.io generates PDFs and images through the REST API v2. The integration uses the X-API-KEY header and defaults to https://rest.apitemplate.io; regional hosts such as https://rest-us.apitemplate.io can be configured per account.

Generation tools usually return APITemplate.io response fields such as status, download_url, download_url_png, template_id, and transaction_ref. When async = true, the API returns quickly and you should track the returned transaction_ref or receive the configured webhook callback.

create_pdf

Generate a PDF from a saved template.

local result = app.integrations.apitemplateio.create_pdf({
  template_id = "tpl_invoice",
  data = {
    invoice_number = "INV-001",
    company_name = "Example Corp",
    amount = "$500.00"
  },
  filename = "invoice-INV-001.pdf",
  expiration = 1440
})

Common query options: export_type, output_format, output_html, expiration, filename, async, webhook_url, webhook_method, and meta.

create_image

Generate images from a visual image template. Prefer overrides; data is accepted as a backward-compatible full payload.

local result = app.integrations.apitemplateio.create_image({
  template_id = "tpl_social",
  output_image_type = "pngOnly",
  overrides = {
    { name = "title", text = "Launch Week" },
    { name = "hero", src = "https://example.test/hero.png" }
  }
})

output_image_type accepts all, jpegOnly, or pngOnly.

create_pdf_from_html

Generate a PDF without creating a saved template first.

local result = app.integrations.apitemplateio.create_pdf_from_html({
  body = "<h1>Hello {{name}}</h1>",
  css = "<style>h1 { color: #2563eb; }</style>",
  data = { name = "World" },
  settings = {
    paper_size = "A4",
    orientation = "1",
    margin_top = "40",
    margin_right = "10",
    margin_bottom = "40",
    margin_left = "10"
  }
})

create_pdf_from_url

Render a public web page into a PDF.

local result = app.integrations.apitemplateio.create_pdf_from_url({
  url = "https://example.test/report",
  settings = {
    paper_size = "A4",
    print_background = "1"
  }
})

create_pdf_from_markdown

Render Markdown into a PDF.

local result = app.integrations.apitemplateio.create_pdf_from_markdown({
  body = "# {{title}}\n\nGenerated report body.",
  data = { title = "Monthly Report" },
  css = "<style>body { font-family: sans-serif; }</style>"
})

merge_pdfs

Merge normal PDF URLs or PDF data URLs into a single PDF.

local result = app.integrations.apitemplateio.merge_pdfs({
  urls = {
    "https://example.test/a.pdf",
    "https://example.test/b.pdf"
  },
  export_type = "json",
  expiration = 1440
})

list_objects

List generated PDFs and images.

local result = app.integrations.apitemplateio.list_objects({
  limit = 50,
  transaction_type = "PDF",
  template_id = "tpl_invoice"
})

Filters include limit, offset, template_id, transaction_type, and transaction_ref.

delete_object

Delete a generated object from APITemplate.io CDN storage.

local result = app.integrations.apitemplateio.delete_object({
  transaction_ref = "txn_123"
})

get_current_user

Get account information for the configured API key. The tool keeps the historical name but maps to the current /v2/account-information endpoint.

local account = app.integrations.apitemplateio.get_current_user({})

list_templates

List saved templates.

local templates = app.integrations.apitemplateio.list_templates({
  limit = 100,
  format = "PDF",
  group_name = "invoices"
})

Filters include limit, offset, format, template_id, group_name, and with_layer_info.

get_template

Get a saved PDF template by ID. APITemplate.io marks this endpoint experimental.

local template = app.integrations.apitemplateio.get_template({
  template_id = "tpl_invoice"
})

update_template

Update a saved PDF template. APITemplate.io marks this endpoint experimental, so hosts should expect availability to depend on account/API support.

local result = app.integrations.apitemplateio.update_template({
  template_id = "tpl_invoice",
  body = "<h1>{{title}}</h1>",
  css = "<style>body { background: white; }</style>",
  settings = {
    custom_footer = "<div>Page <span class='pageNumber'></span></div>"
  }
})

Multi-Account Usage

app.integrations.apitemplateio.create_pdf({...})
app.integrations.apitemplateio.default.create_pdf({...})
app.integrations.apitemplateio.production.create_pdf({...})
Raw agent markdown
# APITemplate.io Lua Reference

APITemplate.io generates PDFs and images through the REST API v2. The integration uses the `X-API-KEY` header and defaults to `https://rest.apitemplate.io`; regional hosts such as `https://rest-us.apitemplate.io` can be configured per account.

Generation tools usually return APITemplate.io response fields such as `status`, `download_url`, `download_url_png`, `template_id`, and `transaction_ref`. When `async = true`, the API returns quickly and you should track the returned `transaction_ref` or receive the configured webhook callback.

## create_pdf

Generate a PDF from a saved template.

```lua
local result = app.integrations.apitemplateio.create_pdf({
  template_id = "tpl_invoice",
  data = {
    invoice_number = "INV-001",
    company_name = "Example Corp",
    amount = "$500.00"
  },
  filename = "invoice-INV-001.pdf",
  expiration = 1440
})
```

Common query options: `export_type`, `output_format`, `output_html`, `expiration`, `filename`, `async`, `webhook_url`, `webhook_method`, and `meta`.

## create_image

Generate images from a visual image template. Prefer `overrides`; `data` is accepted as a backward-compatible full payload.

```lua
local result = app.integrations.apitemplateio.create_image({
  template_id = "tpl_social",
  output_image_type = "pngOnly",
  overrides = {
    { name = "title", text = "Launch Week" },
    { name = "hero", src = "https://example.test/hero.png" }
  }
})
```

`output_image_type` accepts `all`, `jpegOnly`, or `pngOnly`.

## create_pdf_from_html

Generate a PDF without creating a saved template first.

```lua
local result = app.integrations.apitemplateio.create_pdf_from_html({
  body = "<h1>Hello {{name}}</h1>",
  css = "<style>h1 { color: #2563eb; }</style>",
  data = { name = "World" },
  settings = {
    paper_size = "A4",
    orientation = "1",
    margin_top = "40",
    margin_right = "10",
    margin_bottom = "40",
    margin_left = "10"
  }
})
```

## create_pdf_from_url

Render a public web page into a PDF.

```lua
local result = app.integrations.apitemplateio.create_pdf_from_url({
  url = "https://example.test/report",
  settings = {
    paper_size = "A4",
    print_background = "1"
  }
})
```

## create_pdf_from_markdown

Render Markdown into a PDF.

```lua
local result = app.integrations.apitemplateio.create_pdf_from_markdown({
  body = "# {{title}}\n\nGenerated report body.",
  data = { title = "Monthly Report" },
  css = "<style>body { font-family: sans-serif; }</style>"
})
```

## merge_pdfs

Merge normal PDF URLs or PDF data URLs into a single PDF.

```lua
local result = app.integrations.apitemplateio.merge_pdfs({
  urls = {
    "https://example.test/a.pdf",
    "https://example.test/b.pdf"
  },
  export_type = "json",
  expiration = 1440
})
```

## list_objects

List generated PDFs and images.

```lua
local result = app.integrations.apitemplateio.list_objects({
  limit = 50,
  transaction_type = "PDF",
  template_id = "tpl_invoice"
})
```

Filters include `limit`, `offset`, `template_id`, `transaction_type`, and `transaction_ref`.

## delete_object

Delete a generated object from APITemplate.io CDN storage.

```lua
local result = app.integrations.apitemplateio.delete_object({
  transaction_ref = "txn_123"
})
```

## get_current_user

Get account information for the configured API key. The tool keeps the historical name but maps to the current `/v2/account-information` endpoint.

```lua
local account = app.integrations.apitemplateio.get_current_user({})
```

## list_templates

List saved templates.

```lua
local templates = app.integrations.apitemplateio.list_templates({
  limit = 100,
  format = "PDF",
  group_name = "invoices"
})
```

Filters include `limit`, `offset`, `format`, `template_id`, `group_name`, and `with_layer_info`.

## get_template

Get a saved PDF template by ID. APITemplate.io marks this endpoint experimental.

```lua
local template = app.integrations.apitemplateio.get_template({
  template_id = "tpl_invoice"
})
```

## update_template

Update a saved PDF template. APITemplate.io marks this endpoint experimental, so hosts should expect availability to depend on account/API support.

```lua
local result = app.integrations.apitemplateio.update_template({
  template_id = "tpl_invoice",
  body = "<h1>{{title}}</h1>",
  css = "<style>body { background: white; }</style>",
  settings = {
    custom_footer = "<div>Page <span class='pageNumber'></span></div>"
  }
})
```

## Multi-Account Usage

```lua
app.integrations.apitemplateio.create_pdf({...})
app.integrations.apitemplateio.default.create_pdf({...})
app.integrations.apitemplateio.production.create_pdf({...})
```
Metadata-derived Lua example
local result = app.integrations.apitemplateio.create_pdf({template_id = "example_template_id", data = "example_data", export_type = "example_export_type", output_format = "example_output_format", output_html = true, expiration = 1, expire = 1, filename = "example_filename"})
print(result)

Functions

create_pdf Write

Generate a PDF document from an API Template IO template. Provide a template ID and the data to merge into the template.

Lua path
app.integrations.apitemplateio.create_pdf
Full name
apitemplateio.apitemplateio_create_pdf
ParameterTypeRequiredDescription
template_id string yes The template ID to use for PDF generation (e.g., "tpl_abc123").
data object yes Key-value pairs to merge into the template placeholders.
export_type string no Return mode: "json" for a CDN URL or "file" for binary output. Defaults to "json".
output_format string no Output format: pdf, html, png, or jpeg. Defaults to pdf.
output_html boolean no If true, returns rendered HTML as an html_url field.
expiration integer no Minutes until the generated file URL expires. Use 0 to store permanently.
expire integer no Deprecated alias for expiration.
filename string no Optional generated filename, usually ending with .pdf.
async boolean no Generate asynchronously. Requires webhook_url when true.
webhook_url string no Webhook URL for asynchronous generation callbacks.
webhook_method string no Webhook method: GET or POST. Defaults to GET.
meta string no Optional metadata string to attach to the generation request.
create_image Write

Generate PNG and/or JPEG images from an APITemplate.io image template. Provide a template ID and override payload.

Lua path
app.integrations.apitemplateio.create_image
Full name
apitemplateio.apitemplateio_create_image
ParameterTypeRequiredDescription
template_id string yes The template ID to use for image generation (e.g., "tpl_abc123").
overrides array no Image object overrides. Each item should include a name and the properties to replace.
data object no Backward-compatible full image payload. Prefer overrides for new calls.
output_image_type string no Which image outputs to generate: all, jpegOnly, or pngOnly. Defaults to all.
output_format string no Deprecated alias: png maps to pngOnly, jpeg maps to jpegOnly.
expiration integer no Minutes until generated file URLs expire. Use 0 to store permanently.
expire integer no Deprecated alias for expiration.
meta string no Optional metadata string to attach to the generation request.
create_pdf_from_html Write

Generate a PDF from raw HTML, optional CSS, dynamic data, and rendering settings.

Lua path
app.integrations.apitemplateio.create_pdf_from_html
Full name
apitemplateio.apitemplateio_create_pdf_from_html
ParameterTypeRequiredDescription
body string yes HTML body content. Jinja2 variables can reference keys from data.
css string no Optional CSS, usually including a style tag.
data object no Values for dynamic variables in the HTML body.
settings object no PDF rendering settings such as paper_size, orientation, margins, headers, and footers.
export_type string no Return mode: json or file.
output_format string no Output format: pdf, html, png, or jpeg.
expiration integer no Minutes until generated file URLs expire.
filename string no Optional generated filename.
async boolean no Generate asynchronously. Requires webhook_url when true.
webhook_url string no Webhook URL for asynchronous callbacks.
webhook_method string no Webhook method: GET or POST.
meta string no Optional external reference ID.
create_pdf_from_url Write

Generate a PDF by rendering a public URL with optional page settings.

Lua path
app.integrations.apitemplateio.create_pdf_from_url
Full name
apitemplateio.apitemplateio_create_pdf_from_url
ParameterTypeRequiredDescription
url string yes Public URL to render into a PDF.
settings object no PDF rendering settings such as paper_size, orientation, margins, headers, and footers.
export_type string no Return mode: json or file.
output_format string no Output format: pdf, html, png, or jpeg.
expiration integer no Minutes until generated file URLs expire.
filename string no Optional generated filename.
async boolean no Generate asynchronously. Requires webhook_url when true.
webhook_url string no Webhook URL for asynchronous callbacks.
webhook_method string no Webhook method: GET or POST.
meta string no Optional external reference ID.
create_pdf_from_markdown Write

Generate a PDF from Markdown, optional CSS, dynamic data, and rendering settings.

Lua path
app.integrations.apitemplateio.create_pdf_from_markdown
Full name
apitemplateio.apitemplateio_create_pdf_from_markdown
ParameterTypeRequiredDescription
body string yes Markdown content. Jinja2 variables can reference keys from data.
css string no Optional CSS, usually including a style tag.
data object no Values for dynamic variables in the Markdown body.
settings object no PDF rendering settings such as paper_size, orientation, margins, headers, and footers.
export_type string no Return mode: json or file.
output_format string no Output format: pdf, html, png, or jpeg.
expiration integer no Minutes until generated file URLs expire.
filename string no Optional generated filename.
async boolean no Generate asynchronously. Requires webhook_url when true.
webhook_url string no Webhook URL for asynchronous callbacks.
webhook_method string no Webhook method: GET or POST.
meta string no Optional external reference ID.
merge_pdfs Write

Merge multiple PDF URLs or PDF data URLs into a single PDF.

Lua path
app.integrations.apitemplateio.merge_pdfs
Full name
apitemplateio.apitemplateio_merge_pdfs
ParameterTypeRequiredDescription
urls array yes PDF URLs or data URLs to merge in order.
export_type string no Return mode: json or file.
expiration integer no Minutes until the generated merged PDF URL expires.
cloud_storage integer no Upload output to APITemplate.io CDN. 1 by default, 0 when BYOS handles storage.
meta string no Optional external reference ID.
postaction_enabled string no Enable post actions: 1 or 0.
postaction_s3_filekey string no Override post-action object key without file extension.
postaction_s3_bucket string no Override post-action bucket or container.
list_generated_objects Read

List generated PDFs and images, optionally filtered by template ID, transaction type, or transaction reference.

Lua path
app.integrations.apitemplateio.list_generated_objects
Full name
apitemplateio.apitemplateio_list_objects
ParameterTypeRequiredDescription
limit integer no Number of records to return. Defaults to 300 upstream.
offset integer no Number of records to skip. Defaults to 0 upstream.
template_id string no Filter generated objects by template ID.
transaction_type string no Filter by transaction type: PDF, JPEG, or MERGE.
transaction_ref string no Filter by a specific generated object transaction reference.
delete_generated_object Write

Delete a generated PDF or image by transaction reference.

Lua path
app.integrations.apitemplateio.delete_generated_object
Full name
apitemplateio.apitemplateio_delete_object
ParameterTypeRequiredDescription
transaction_ref string yes Generated object transaction reference to delete.
get_account_information Read

Get APITemplate.io account information for the configured API key, including plan and usage fields returned by the API.

Lua path
app.integrations.apitemplateio.get_account_information
Full name
apitemplateio.apitemplateio_get_current_user
ParameterTypeRequiredDescription
No parameters.
list Read

List available templates in API Template IO. Returns a paginated list of template IDs, names, and metadata.

Lua path
app.integrations.apitemplateio.list
Full name
apitemplateio.apitemplateio_list_templates
ParameterTypeRequiredDescription
limit integer no Number of templates to return. Defaults to 300 upstream.
offset integer no Offset for pagination. Defaults to 0 upstream.
format string no Filter by template format: PDF or JPEG.
template_id string no Filter to a specific template ID.
group_name string no Filter templates by group name.
with_layer_info boolean no Include image-template layer information when true.
get Read

Get details for a specific API Template IO template by ID. Returns the template definition, schema, and configuration.

Lua path
app.integrations.apitemplateio.get
Full name
apitemplateio.apitemplateio_get_template
ParameterTypeRequiredDescription
template_id string yes The template ID to retrieve (e.g., "tpl_abc123").
update Write

Update a PDF template body, CSS, or settings. This uses APITemplate.io experimental template-management API.

Lua path
app.integrations.apitemplateio.update
Full name
apitemplateio.apitemplateio_update_template
ParameterTypeRequiredDescription
template_id string yes Template ID to update.
body string no Replacement HTML body.
css string no Replacement CSS.
settings object no Template settings such as custom_header or custom_footer.