KosmoKrator

data

fal.ai Lua API for KosmoKrator Agents

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

Lua Namespace

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

Inline Lua call
kosmo integrations:lua --eval 'dump(app.integrations.fal.list_models({}))' --json
Read Lua docs headlessly
kosmo integrations:lua --eval 'print(docs.read("fal"))' --json
kosmo integrations:lua --eval 'print(docs.read("fal.list_models"))' --json

Workflow file

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

workflow.lua
local fal = app.integrations.fal
local result = fal.list_models({})

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

MCP-only Lua

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

fal.ai — Lua API Reference

list_models

List available fal.ai models.

Parameters

None.

Example

local result = app.integrations["fal"].list_models({})

for _, model in ipairs(result) do
  print(model.id .. ": " .. model.description)
end

submit_request

Submit a generation request to a fal.ai model.

Parameters

NameTypeRequiredDescription
model_idstringyesThe model identifier (e.g., "fal-ai/flux/schnell")
inputobjectyesModel input values (e.g., prompt, image_url)
webhook_urlstringnoURL to receive POST notifications on completion

Example

local result = app.integrations["fal"].submit_request({
  model_id = "fal-ai/flux/schnell",
  input = {
    prompt = "A beautiful sunset over the ocean, cinematic lighting",
    image_size = "landscape_16_9",
    num_images = 1
  }
})

print("Request ID: " .. result.request_id)

get_request_status

Get the status of a submitted fal.ai request.

Parameters

NameTypeRequiredDescription
model_idstringyesThe model identifier used when submitting
request_idstringyesThe request ID returned by submit_request

Example

local status = app.integrations["fal"].get_request_status({
  model_id = "fal-ai/flux/schnell",
  request_id = "abc123-def456"
})

print("Status: " .. status.status)
if status.queue_position then
  print("Queue position: " .. status.queue_position)
end

get_result

Get the result of a completed fal.ai request.

Parameters

NameTypeRequiredDescription
model_idstringyesThe model identifier used when submitting
request_idstringyesThe request ID returned by submit_request

Example

local result = app.integrations["fal"].get_result({
  model_id = "fal-ai/flux/schnell",
  request_id = "abc123-def456"
})

if result.images then
  for _, image in ipairs(result.images) do
    print("Image URL: " .. image.url)
  end
end

if result.video then
  print("Video URL: " .. result.video.url)
end

list_files

List files stored in fal.ai storage.

Parameters

None.

Example

local result = app.integrations["fal"].list_files({})

for _, file in ipairs(result) do
  print(file.file_name .. " — " .. file.url)
end

upload_file

Upload a file to fal.ai storage for use as model input.

Parameters

NameTypeRequiredDescription
file_pathstringyesThe local file path to upload
file_namestringnoCustom file name for the upload

Example

local result = app.integrations["fal"].upload_file({
  file_path = "/path/to/reference-image.png",
  file_name = "reference.png"
})

print("Uploaded file URL: " .. result.url)

get_current_user

Get the current fal.ai user profile and account information.

Parameters

None.

Example

local user = app.integrations["fal"].get_current_user({})

print("Name: " .. user.name)
print("Email: " .. user.email)

Multi-Account Usage

If you have multiple fal.ai accounts configured, use account-specific namespaces:

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

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

-- Named accounts
app.integrations["fal"].production.function_name({...})
app.integrations["fal"].staging.function_name({...})

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

Raw agent markdown
# fal.ai — Lua API Reference

## list_models

List available fal.ai models.

### Parameters

None.

### Example

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

for _, model in ipairs(result) do
  print(model.id .. ": " .. model.description)
end
```

---

## submit_request

Submit a generation request to a fal.ai model.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `model_id` | string | yes | The model identifier (e.g., `"fal-ai/flux/schnell"`) |
| `input` | object | yes | Model input values (e.g., prompt, image_url) |
| `webhook_url` | string | no | URL to receive POST notifications on completion |

### Example

```lua
local result = app.integrations["fal"].submit_request({
  model_id = "fal-ai/flux/schnell",
  input = {
    prompt = "A beautiful sunset over the ocean, cinematic lighting",
    image_size = "landscape_16_9",
    num_images = 1
  }
})

print("Request ID: " .. result.request_id)
```

---

## get_request_status

Get the status of a submitted fal.ai request.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `model_id` | string | yes | The model identifier used when submitting |
| `request_id` | string | yes | The request ID returned by `submit_request` |

### Example

```lua
local status = app.integrations["fal"].get_request_status({
  model_id = "fal-ai/flux/schnell",
  request_id = "abc123-def456"
})

print("Status: " .. status.status)
if status.queue_position then
  print("Queue position: " .. status.queue_position)
end
```

---

## get_result

Get the result of a completed fal.ai request.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `model_id` | string | yes | The model identifier used when submitting |
| `request_id` | string | yes | The request ID returned by `submit_request` |

### Example

```lua
local result = app.integrations["fal"].get_result({
  model_id = "fal-ai/flux/schnell",
  request_id = "abc123-def456"
})

if result.images then
  for _, image in ipairs(result.images) do
    print("Image URL: " .. image.url)
  end
end

if result.video then
  print("Video URL: " .. result.video.url)
end
```

---

## list_files

List files stored in fal.ai storage.

### Parameters

None.

### Example

```lua
local result = app.integrations["fal"].list_files({})

for _, file in ipairs(result) do
  print(file.file_name .. " — " .. file.url)
end
```

---

## upload_file

Upload a file to fal.ai storage for use as model input.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `file_path` | string | yes | The local file path to upload |
| `file_name` | string | no | Custom file name for the upload |

### Example

```lua
local result = app.integrations["fal"].upload_file({
  file_path = "/path/to/reference-image.png",
  file_name = "reference.png"
})

print("Uploaded file URL: " .. result.url)
```

---

## get_current_user

Get the current fal.ai user profile and account information.

### Parameters

None.

### Example

```lua
local user = app.integrations["fal"].get_current_user({})

print("Name: " .. user.name)
print("Email: " .. user.email)
```

---

## Multi-Account Usage

If you have multiple fal.ai accounts configured, use account-specific namespaces:

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

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

-- Named accounts
app.integrations["fal"].production.function_name({...})
app.integrations["fal"].staging.function_name({...})
```

All functions are identical across accounts — only the credentials differ.
Metadata-derived Lua example
local result = app.integrations.fal.list_models({})
print(result)

Functions

list_models Read

List available fal.ai models. Returns model IDs, descriptions, and capabilities.

Lua path
app.integrations.fal.list_models
Full name
fal.fal_list_models
ParameterTypeRequiredDescription
No parameters.
submit_request Write

Submit a generation request to a fal.ai model. Returns the request ID for tracking. Poll get_request_status for progress.

Lua path
app.integrations.fal.submit_request
Full name
fal.fal_submit_request
ParameterTypeRequiredDescription
model_id string yes The model identifier (e.g., "fal-ai/flux/schnell").
input object yes An object of model input values (e.g., prompt, image_url, etc.).
webhook_url string no A URL to receive POST notifications when the request completes.
get_request_status Read

Get the status of a submitted fal.ai request. Returns queue position and processing state.

Lua path
app.integrations.fal.get_request_status
Full name
fal.fal_get_request_status
ParameterTypeRequiredDescription
model_id string yes The model identifier used when submitting the request.
request_id string yes The request ID returned by submit_request.
get_result Read

Get the result of a completed fal.ai request. Returns generated media URLs and metadata.

Lua path
app.integrations.fal.get_result
Full name
fal.fal_get_result
ParameterTypeRequiredDescription
model_id string yes The model identifier used when submitting the request.
request_id string yes The request ID returned by submit_request.
list_files Read

List files stored in fal.ai storage. Returns file names, URLs, and metadata.

Lua path
app.integrations.fal.list_files
Full name
fal.fal_list_files
ParameterTypeRequiredDescription
No parameters.
upload_file Write

Upload a file to fal.ai storage for use as model input. Returns the file URL.

Lua path
app.integrations.fal.upload_file
Full name
fal.fal_upload_file
ParameterTypeRequiredDescription
file_path string yes The local file path to upload.
file_name string no Custom file name for the upload. Defaults to the original file name.
get_current_user Read

Get current fal.ai user profile and account information.

Lua path
app.integrations.fal.get_current_user
Full name
fal.fal_get_current_user
ParameterTypeRequiredDescription
No parameters.