# Connect to the Remote API

Source: https://docs.lightair.app/developers/control/connect

> Reach Lightair's local server on port 4455 over JSON-RPC, MCP, obs-websocket or the command line, send the password, and make a first call.

In short:
- Lightair answers on port 4455 of this computer: obs-websocket at `/`, JSON-RPC 2.0 at `/rpc`, MCP at `/mcp`.
- Send the password from **Settings › Remote API** as `Authorization: Bearer <password>`, or call `auth.login` first.
- Only this computer can connect until you turn on **Other devices on your network**; then the password is always asked.
- Events come as `{"method": "event", "params": {"name", "data"}}`. `events.subscribe` picks which.

In the app: Lightair › Settings… › Remote API

Lightair runs one local server that other apps, scripts and AI agents use to control it. Every change they make to the workspace is an ordinary change: it can be undone, and **Undo** names who made it.

## Check that it's on

1. Open **Lightair › Settings…** and pick **Remote API**.
2. Make sure **Let other apps control Lightair** is on. It is by default.
3. Note the **Port**. It's 4455 unless you changed it.

The status line under the switch says who may connect ("On, for this Mac only") and how many clients are connected. If another app already uses the port, it says "Port 4455 is in use (OBS or another app?). Choose another port." Use **−** and **+** beside **Port** to pick another one.

To see that the server answers, ask it for its address list. This request needs no password:

```sh
curl http://127.0.0.1:4455/
```

```json
{"name":"Lightair","version":"…","ways_in":{"obs-websocket v5":"ws://this-address/","JSON-RPC 2.0":"ws://this-address/rpc","MCP (Streamable HTTP)":"http://this-address/mcp"}}
```

## The ways in

| Way in | Address | For |
|---|---|---|
| JSON-RPC 2.0 over WebSocket | `ws://127.0.0.1:4455/rpc` | Scripts and apps written for Lightair. Every method and event. |
| MCP, Streamable HTTP | `http://127.0.0.1:4455/mcp` | AI agents that connect over HTTP. See [MCP server](/developers/control/mcp). |
| MCP over stdio | `lightair mcp` | AI agents that start their tools as programs. See [Command line](/developers/control/command-line). |
| Command line | `lightair call <method> [params]` | One call from a shell script, answered as JSON. |
| obs-websocket 5 | `ws://127.0.0.1:4455/` | Tools made for OBS: Stream Deck, Touch Portal, bots. See [obs-websocket](/developers/control/obs-websocket). |

All of them reach the same methods. The method reference is under [Remote API methods](/developers/remote-api/app.version).

Lightair Live and Lightair Editor don't use this port. They pair with the desktop and connect over an encrypted port of their own; see [Pair a phone](/mobile/get-started/pairing).

## Let other devices connect

By default the server listens on this computer only (`127.0.0.1`). To reach it from a phone, a tablet or another computer:

1. In **Settings › Remote API**, turn on **Other devices on your network**.
2. Connect to this computer's address on your network instead of `127.0.0.1`. The **Connect** section at the bottom of the page shows the addresses with it filled in, each with a copy button.

While other devices may connect, the password is always asked.

## The password

Lightair makes a password of 24 letters and digits the first time it's needed and keeps it in the system's credential store: the Keychain on a Mac, Windows Credential Manager on Windows. **Settings › Remote API › Password** shows it (the eye button), copies it, and makes a new one (**New**). Clients using the old one must connect again with the new one.

**Ask for the password** is on by default. You can turn it off only while **Other devices on your network** is off; then apps on this computer connect without one.

Send it in one of these ways:

| Way in | How to send it |
|---|---|
| JSON-RPC (`/rpc`) | An `Authorization: Bearer <password>` header on the WebSocket request, or `auth.login` with `{"password": "…"}` as the first call. Browsers can't set the header, so a web page uses `auth.login`. |
| MCP over HTTP (`/mcp`) | `Authorization: Bearer <password>` on every request. |
| obs-websocket (`/`) | obs-websocket's own challenge and salt, as every OBS tool does. |
| `lightair call`, `lightair mcp` | Nothing: they read it from the credential store themselves. |

Until a JSON-RPC client has sent the right password, every call except `auth.login` is refused with code `-32001` and no events are sent to it. See [Errors](/developers/control/errors).

## The Host check

While **Other devices on your network** is off, Lightair refuses any request whose `Host` header isn't a local name (`localhost`, a name ending in `.localhost`, `127.0.0.1` or `::1`) with HTTP 403 "Forbidden host". This stops a web page from reaching the server through a domain name it points at your computer. A page can still open `ws://127.0.0.1:4455/rpc` directly, so keep **Ask for the password** on if you browse while Lightair runs.

## Make a first call

These examples connect to `/rpc`, sign in, read the version, switch to a scene named "Main", and print the events that follow. Put your own password and scene name in.

**JavaScript**

Runs in a browser or in Node.js 22 and later, which have `WebSocket` built in.

```js
const PASSWORD = "your-password";
const ws = new WebSocket("ws://127.0.0.1:4455/rpc");

let nextId = 0;
const pending = new Map();

function call(method, params = {}) {
  const id = ++nextId;
  ws.send(JSON.stringify({ jsonrpc: "2.0", id, method, params }));
  return new Promise((resolve, reject) => pending.set(id, { resolve, reject }));
}

ws.addEventListener("message", (e) => {
  const msg = JSON.parse(e.data);
  if (msg.method === "event") {
    console.log("event", msg.params.name, msg.params.data);
    return;
  }
  const waiting = pending.get(msg.id);
  if (!waiting) return;
  pending.delete(msg.id);
  if (msg.error) waiting.reject(new Error(`${msg.error.code}: ${msg.error.message}`));
  else waiting.resolve(msg.result);
});

ws.addEventListener("open", async () => {
  await call("auth.login", { password: PASSWORD });
  console.log(await call("app.version"));
  await call("events.subscribe", { events: ["scene.program", "stream.state", "record.state"] });
  await call("scene.switch", { scene: "Main" });
});
```

**Python**

Uses the [websockets](https://pypi.org/project/websockets/) package, version 14 or later (`pip install websockets`). The password goes in the `Authorization` header.

```python

from websockets.asyncio.client import connect

PASSWORD = "your-password"

async def main():
    headers = {"Authorization": f"Bearer {PASSWORD}"}
    async with connect("ws://127.0.0.1:4455/rpc", additional_headers=headers) as ws:
        next_id = 0

        async def call(method, params=None):
            nonlocal next_id
            next_id += 1
            await ws.send(json.dumps(
                {"jsonrpc": "2.0", "id": next_id, "method": method, "params": params or {}}
            ))
            while True:
                msg = json.loads(await ws.recv())
                if msg.get("id") == next_id:
                    if "error" in msg:
                        raise RuntimeError(f"{msg['error']['code']}: {msg['error']['message']}")
                    return msg["result"]
                # an event that came in meanwhile: skipped in this example

        print(await call("app.version"))
        await call("events.subscribe", {"events": ["scene.program", "stream.state", "record.state"]})
        await call("scene.switch", {"scene": "Main"})

        async for raw in ws:
            msg = json.loads(raw)
            if msg.get("method") == "event":
                print("event", msg["params"]["name"], msg["params"]["data"])

asyncio.run(main())
```

Scenes, objects, sources and tracks can be named by id or by name in every method. Positions and sizes are canvas pixels.

## Requests and answers

Requests are JSON-RPC 2.0 text messages. Lightair answers each request that has an `id`, with `result` or `error`; a request without an `id` is a notification and gets no answer. An array of requests is a batch and is answered with an array. Binary messages close the connection.

```json
{"jsonrpc": "2.0", "id": 7, "method": "scene.switch", "params": {"scene": "Main"}}
```

```json
{"jsonrpc": "2.0", "id": 7, "result": {}}
```

A method that the window answers has 20 seconds to do it; after that the call fails with "Lightair didn't answer in time".

## Get events

Once signed in, a client gets every event as a notification:

```json
{"jsonrpc": "2.0", "method": "event", "params": {"name": "scene.program", "data": {"id": "…", "name": "Main"}}}
```

To get only some, call `events.subscribe` with their names. It answers with the list it kept:

```json
{"jsonrpc": "2.0", "id": 3, "method": "events.subscribe", "params": {"events": ["scene.program", "stream.state"]}}
```

Call it with no `events` to get every event again. `audio.levels`, the meters, comes many times a second and is sent only to a client that names it.

Each client has a queue of 1,000 events. If a client falls behind and events it can't do without are dropped, it gets `session.resync` once there's room again: read [state.get](/developers/remote-api/state.get) again then. A client that subscribes to a list gets it only if the list names it. Every event and its data are in [Events](/developers/control/events).

## Related

- [Events](/developers/control/events)
- [Errors](/developers/control/errors)
- [MCP server](/developers/control/mcp)
