data
Stability AI Lua API for KosmoKrator Agents
Agent-facing Lua documentation and function reference for the Stability AI KosmoKrator integration.Lua Namespace
Agents call this integration through app.integrations.stability.*.
Use lua_read_doc("integrations.stability") 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
Stability AI workflow without starting an interactive agent session.
kosmo integrations:lua --eval 'dump(app.integrations.stability.get_account({}))' --json kosmo integrations:lua --eval 'print(docs.read("stability"))' --json
kosmo integrations:lua --eval 'print(docs.read("stability.get_account"))' --json Workflow file
Put repeatable logic in a Lua file, then execute it with JSON output for the calling process.
local stability = app.integrations.stability
local result = stability.get_account({})
dump(result) kosmo integrations:lua workflow.lua --json
kosmo integrations:lua workflow.lua --force --json integrations:lua exposes app.integrations.stability, app.mcp.*, docs.*, json.*, and regex.*. Use app.integrations.stability.default.* or app.integrations.stability.work.* when you configured named credential accounts.
MCP-only Lua
If the script only needs configured MCP servers and does not need Stability AI, use the narrower 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.
Stability AI Lua API Reference
Namespace: app.integrations.stability
Use this integration for Stability AI account checks plus image generation, image editing, upscaling, control, and image-to-video jobs. Binary image or video responses are normalized as:
{
content_type = "image/png",
body_base64 = "...",
finish_reason = "SUCCESS",
seed = "123"
}
Account
get_account({})reads the API key account.get_balance({})reads available credits.
Image Generation
local image = app.integrations.stability.generate_core({
prompt = "product photo of a matte black desk lamp",
aspect_ratio = "1:1",
output_format = "png"
})
Available generation tools:
generate_coregenerate_ultragenerate_sd3
generate_sd3 also accepts model, such as sd3.5-large or sd3.5-medium.
Image Editing And Control
File inputs may be local paths or raw image bytes. Common tools:
inpaint({ image, prompt, mask, negative_prompt, seed, output_format })erase({ image, mask, output_format })remove_background({ image, output_format })control_structure({ image, prompt, control_strength, negative_prompt, seed, output_format })
local result = app.integrations.stability.remove_background({
image = "/tmp/product.png",
output_format = "png"
})
Upscaling
local fast = app.integrations.stability.upscale_fast({
image = "/tmp/small.png",
output_format = "png"
})
Use upscale_creative when the model should add detail from a prompt.
Image To Video
local job = app.integrations.stability.image_to_video({
image = "/tmp/hero.png",
motion_bucket_id = 127
})
local video = app.integrations.stability.get_video_result({
id = job.id
})
The result endpoint may return an in-progress JSON status or final video bytes, depending on the Stability API response.
Raw agent markdown
# Stability AI Lua API Reference
Namespace: `app.integrations.stability`
Use this integration for Stability AI account checks plus image generation, image editing, upscaling, control, and image-to-video jobs. Binary image or video responses are normalized as:
```lua
{
content_type = "image/png",
body_base64 = "...",
finish_reason = "SUCCESS",
seed = "123"
}
```
## Account
- `get_account({})` reads the API key account.
- `get_balance({})` reads available credits.
## Image Generation
```lua
local image = app.integrations.stability.generate_core({
prompt = "product photo of a matte black desk lamp",
aspect_ratio = "1:1",
output_format = "png"
})
```
Available generation tools:
- `generate_core`
- `generate_ultra`
- `generate_sd3`
`generate_sd3` also accepts `model`, such as `sd3.5-large` or `sd3.5-medium`.
## Image Editing And Control
File inputs may be local paths or raw image bytes. Common tools:
- `inpaint({ image, prompt, mask, negative_prompt, seed, output_format })`
- `erase({ image, mask, output_format })`
- `remove_background({ image, output_format })`
- `control_structure({ image, prompt, control_strength, negative_prompt, seed, output_format })`
```lua
local result = app.integrations.stability.remove_background({
image = "/tmp/product.png",
output_format = "png"
})
```
## Upscaling
```lua
local fast = app.integrations.stability.upscale_fast({
image = "/tmp/small.png",
output_format = "png"
})
```
Use `upscale_creative` when the model should add detail from a prompt.
## Image To Video
```lua
local job = app.integrations.stability.image_to_video({
image = "/tmp/hero.png",
motion_bucket_id = 127
})
local video = app.integrations.stability.get_video_result({
id = job.id
})
```
The result endpoint may return an in-progress JSON status or final video bytes, depending on the Stability API response. local result = app.integrations.stability.get_account({})
print(result) Functions
get_account Read
Get the account associated with the Stability AI API key.
- Lua path
app.integrations.stability.get_account- Full name
stability.stability_get_account
| Parameter | Type | Required | Description |
|---|---|---|---|
| No parameters. | |||
get_balance Read
Get credit balance for the Stability AI API key.
- Lua path
app.integrations.stability.get_balance- Full name
stability.stability_get_balance
| Parameter | Type | Required | Description |
|---|---|---|---|
| No parameters. | |||
generate_core_image Write
Generate an image with Stable Image Core.
- Lua path
app.integrations.stability.generate_core_image- Full name
stability.stability_generate_core
| Parameter | Type | Required | Description |
|---|---|---|---|
| No parameters. | |||
generate_ultra_image Write
Generate a high-quality image with Stable Image Ultra.
- Lua path
app.integrations.stability.generate_ultra_image- Full name
stability.stability_generate_ultra
| Parameter | Type | Required | Description |
|---|---|---|---|
| No parameters. | |||
generate_sd3_image Write
Generate an image with Stable Diffusion 3 or 3.5 models.
- Lua path
app.integrations.stability.generate_sd3_image- Full name
stability.stability_generate_sd3
| Parameter | Type | Required | Description |
|---|---|---|---|
| No parameters. | |||
inpaint_image Write
Fill or replace masked areas of an image.
- Lua path
app.integrations.stability.inpaint_image- Full name
stability.stability_inpaint
| Parameter | Type | Required | Description |
|---|---|---|---|
| No parameters. | |||
erase_image_area Write
Remove masked areas from an image.
- Lua path
app.integrations.stability.erase_image_area- Full name
stability.stability_erase
| Parameter | Type | Required | Description |
|---|---|---|---|
| No parameters. | |||
remove_background Write
Remove an image background.
- Lua path
app.integrations.stability.remove_background- Full name
stability.stability_remove_background
| Parameter | Type | Required | Description |
|---|---|---|---|
| No parameters. | |||
control_structure Write
Generate an image guided by the structure of an input image.
- Lua path
app.integrations.stability.control_structure- Full name
stability.stability_control_structure
| Parameter | Type | Required | Description |
|---|---|---|---|
| No parameters. | |||
fast_upscale Write
Quickly upscale an image.
- Lua path
app.integrations.stability.fast_upscale- Full name
stability.stability_upscale_fast
| Parameter | Type | Required | Description |
|---|---|---|---|
| No parameters. | |||
creative_upscale Write
Upscale an image with creative enhancement.
- Lua path
app.integrations.stability.creative_upscale- Full name
stability.stability_upscale_creative
| Parameter | Type | Required | Description |
|---|---|---|---|
| No parameters. | |||
image_video Write
Start an image-to-video generation job.
- Lua path
app.integrations.stability.image_video- Full name
stability.stability_image_to_video
| Parameter | Type | Required | Description |
|---|---|---|---|
| No parameters. | |||
get_video_result Read
Fetch the result of an image-to-video generation job.
- Lua path
app.integrations.stability.get_video_result- Full name
stability.stability_get_video_result
| Parameter | Type | Required | Description |
|---|---|---|---|
| No parameters. | |||