# Transport API

> Reference the NatUI transport contract and standard-stream host implementation.

Canonical: https://natui.dev/docs/api/transport

## Transport [#transport]

### Transport

A bidirectional NDJSON channel to a native host process, over the host's
stdin/stdout (we spawn the host and pipe both ends). This is the only
supported transport; see docs/protocol.md.

| Property | Type | Required | Description |
| --- | --- | --- | --- |
| `send` | `(msg: OutboundMessage) => void` | Yes |  |
| `onMessage` | `(cb: (msg: InboundMessage) => void) => void` | Yes |  |
| `onExit` | `(cb: (code: number \| null) => void) => void` | Yes |  |
| `close` | `() => void` | Yes |  |

```ts
interface Transport {
  send(msg: OutboundMessage): void;
  onMessage(cb: (msg: InboundMessage) => void): void;
  onExit(cb: (code: number | null) => void): void;
  close(): void;
}
```

A transport delivers typed protocol messages in both directions and reports host exit.

## HostCommand [#hostcommand]

### HostCommand


| Property | Type | Required | Description |
| --- | --- | --- | --- |
| `cmd` | `string` | Yes |  |
| `args` | `string[] \| undefined` | No |  |

```ts
interface HostCommand {
  cmd: string;
  args?: string[];
}
```

## spawnStdioTransport [#spawnstdiotransport]

```ts
function spawnStdioTransport(host: HostCommand): Transport
```

Spawns a host process and exchanges newline-delimited JSON over its standard input and output. Host standard error is inherited for diagnostics.

## defaultHostCommand [#defaulthostcommand]

Checks `NATUI_HOST` first, then searches upward from the current directory for known macOS or Windows build outputs.

The shipped host process protocol uses standard streams. `natui/inproc` provides a separate internal transport for an embedding host.