Skip to main content

Installation

DeviceClientConfig

The configuration object passed to new DeviceClient().
agentId
string
required
Agent ID to connect to. Found in .lua/lua.config.yaml or the Lua dashboard.
apiKey
string
required
API key for authentication. Generate with lua auth configure.
deviceName
string
required
Unique name for this device. Lowercase with hyphens (e.g., label-printer, pico-sensor-01).
commands
DeviceCommandDefinition[]
Array of commands this device supports. Sent to the server at connect time so the agent can use them as tools. See Self-Describing Commands.
transport
'socketio' | 'mqtt'
default:"socketio"
Transport protocol. Use 'mqtt' for constrained devices or environments where MQTT is preferred.
serverUrl
string
default:"https://api.heylua.ai"
Server URL for Socket.IO transport.
mqttUrl
string
default:"wss://mqtt.heylua.ai/mqtt"
MQTT broker URL. Required when transport is 'mqtt'.
cdnUrl
string
default:"https://cdn.heylua.ai"
CDN URL for file uploads and downloads.
group
string
Optional device group name for fan-out commands (e.g., 'printers', 'sensors-floor-2').

DeviceCommandDefinition

Each entry in the commands array describes one command the device supports.
name
string
required
Command name. Used by the agent to invoke the command (e.g., read_temperature).
description
string
required
Human-readable description. Shown to the AI agent as the tool description. Write it as if explaining to a person what the command does.
inputSchema
Record<string, any>
JSON Schema for command input parameters. The agent uses this to know what arguments to pass.
timeoutMs
number
default:"30000"
Command timeout in milliseconds. If the device does not respond within this time, the command fails.
retry
{ maxAttempts: number; backoffMs: number }
Retry configuration for failed commands. The gateway retries with exponential backoff.

Connection Lifecycle

The client automatically reconnects on network failures with jittered exponential backoff (1s to 30s). Call disconnect() to stop reconnection. The client also registers SIGTERM and SIGINT handlers for graceful shutdown.

Handling Commands

Register handlers for commands the agent can send to this device:
If a handler throws an error, the error message is returned to the agent as a failed command result. The agent sees the error and can decide how to respond to the user.

Firing Triggers

Send events from the device to the agent:
See Triggers for the full guide on how to handle triggers on the agent side.

CDN Uploads

Every DeviceClient instance includes a cdn property for uploading and downloading files:
See CDN Uploads for more details.

Transport Configuration

Socket.IO is best for Node.js applications running on desktops, servers, or single-board computers with plenty of memory.

Complete Example

A device that simulates a smart thermostat with temperature reading, target temperature setting, and a high-temperature alert trigger:

Next Steps

MQTT Transport

Deep dive into MQTT configuration and topic structure

CDN Uploads

Upload and download files from your device

Triggers

Send events from your device to the agent

API Reference

Complete class and method documentation