> ## Documentation Index
> Fetch the complete documentation index at: https://docs.leverine.com/llms.txt
> Use this file to discover all available pages before exploring further.

# API reference

> The complete BunnyBridge API: Tunnel 1 and Tunnel 2 endpoints, request and response shapes, limits, and every error.

One listener, two surfaces. Tunnel 1 is served at the phone's tailnet address; Tunnel 2 is served under `/door2/` at the recorded public address (and on the same listener, for the front door to forward).

## The two surfaces

| | Tunnel 1 — private | Tunnel 2 — chatbot |
| - | - | - |
| **Base** | `http://<phone-tailnet-ip>:8765` | `https://<public-address>` |
| **Reach** | Same tailnet only | Public https, via Mode 2 relay or your own front door |
| **Auth** | `X-Token` header, Tunnel 1 token | `X-Token` header or Bearer, Tunnel 2 token |
| **Default state** | On when the bridge runs | Off until switched on in the app |
| **Limits** | Max 4 concurrent runs; no per-minute cap | 30 authenticated calls/min per token; max 2 concurrent runs |

Conventions: request and response bodies are JSON unless noted (the log endpoint is plain text). A token is sent on every authenticated call. Tokens are tunnel-scoped — presenting a token on the wrong tunnel is a `403`, exactly like a wrong token. Examples use placeholder values throughout.

## Tunnel 1 endpoints

### `GET /health` — liveness and diagnosis

**Auth:** none for the basic form; a Tunnel 1 token for the full form.

Basic form (no token, or an unrecognised one is treated as no token for this endpoint's public half):

```
{"ok": true, "version": "0.4.10", "uptime_s": 823,
 "listening": true, "tailnet_address": "<phone-tailnet-ip>",
 "active_runs": 0}
```

Full form (valid Tunnel 1 token) adds the self-diagnosis — the same content the Status screen shows:

> [accordion] Full /health response (with diagnosis)
>
> ```
> { ...basic fields...,
>  "ready": false,
>  "token_name": "agent-1",
>  "permissions_missing": [
>    {"item": "battery_optimization", "fix": "user",
>     "instruction": "Exempt BunnyBridge from battery optimization so the phone does not stop the bridge."}
>  ],
>  "software_missing": [],
>  "state_missing": [
>    {"item": "no_hosts", "fix": "user", "instruction": "..."}
>  ],
>  "door2": {"enabled": false, "mode": "RELAY", "...": "..."}
> }
> ```
>
> * `ready` — true when no *blocking* diagnosis item is open. Informational items never hold it false.
> * Each diagnosis item carries an `item` id, a `fix` of `"agent"` (resolvable through the API, or the app self-heals) or `"user"`, and an `instruction` written for the human when the fix is theirs.
> * The `door2` block summarises the chatbot tunnel's state (enabled, the selected `mode` — the surface answers only in front-door mode — whether a public address is recorded, its own readiness) without exposing any Tunnel 2 secret.

### `GET /status` — bridge status

**Auth:** Tunnel 1 token required.

```
{"version": "0.4.10", "uptime_s": 823,
 "tailnet_address": "<phone-tailnet-ip>",
 "token_name": "agent-1",
 "tokens": ["first-token", "agent-1"],
 "hosts": []}
```

* `token_name` — the name of the token you authenticated with.
* `tokens` — the names of all tokens on the phone. Names only, never values.
* `hosts` — the names of configured SSH hosts. Host management arrives with the jump-host phase; until then this list is empty.

### `POST /run` — run a command

**Auth:** Tunnel 1 token required.

Request:

```
{"cmd": "echo hello; date",
 "timeout": 60,
 "host": "optional-host-name"}
```

| Field | Required | Meaning |
| - | - | - |
| `cmd` | Yes | The shell command to run on the phone, inside the app sandbox. |
| `timeout` | No | Per-command timeout, in seconds. |
| `host` | No | Run on a configured SSH host instead of the phone. Reserved for the jump-host phase: in the current version a command naming a host completes with a clear refusal, because no hosts can be configured yet. |

Response:

```
{"stdout": "hello\nSat Dec  5 17:01:39 EST 2026\n",
 "stderr": "", "code": 0, "id": "run-1",
 "duration_ms": 214, "truncated": false}
```

* `code` — the command's exit code. A non-zero code is a completed run, not an API error; read `stderr`.
* `id` — this run's id, matching the Activity record.
* `truncated` — true when the output was cut to the bridge's output cap; the run still completed.

At most **4 commands** run at once on Tunnel 1; further calls wait or fail with `429` rather than piling up.

### `GET /log` — the event log (Tunnel 1 only)

**Auth:** Tunnel 1 token required. A Tunnel 2 token gets `403`.

Returns the app's event log as **plain text**, one event per line: ISO-8601 UTC timestamp, level, category, message. Recorded: app starts (with app and Android versions), screen opens, diagnosis runs with the facts that decided them, permission checks and answers, token operations by name, bridge bind/unbind, Tunnel 2 toggles, relay queue/approve/dismiss, run completions, rejected-token refusals (tunnel and address, never the value), updater steps, and exceptions with stack traces. Token values are registered as secrets and scrubbed before anything is stored — a log line never contains one.

| Query | Effect |
| - | - |
| `?tail=N` | Only the last N entries. |
| `?session=current` | Only the entries since the user's last "Start test session" marker in the Log screen — the first slice to request when something misbehaved. |

## Tunnel 2 endpoints

All Tunnel 2 paths sit under `/door2/`. While the app is in Mode 1 — the Tunnel 2 surface switched off — the **whole surface answers `403` with "door 2 is off"** — including for valid tokens. Tunnel 2 accepts the token as the `X-Token` header or as an `Authorization: Bearer` token, to fit how different chatbot connectors authenticate.

### `GET /door2/health`

**Auth:** none for basic liveness; a Tunnel 2 token for the full form. The basic form is the same shape as Tunnel 1's. The full form returns the complete diagnosis (a chatbot helper may need to relay a user fix) — but never anything from Tunnel 1's private data.

### `GET /door2/status`

**Auth:** Tunnel 2 token required. Deliberately reduced:

```
{"version": "0.4.10", "uptime_s": 823,
 "token_name": "chatbot-1", "door": "door2",
 "door2_active_runs": 0}
```

No token list, no tailnet address, no host names — nothing about the private side crosses this tunnel.

### `POST /door2/run`

**Auth:** Tunnel 2 token required. Request and response shapes are identical to Tunnel 1's `POST /run` (including the `host` reservation). Tunnel 2's limits apply: 30 authenticated calls per minute for this token, at most 2 commands running at once. Every run is flagged in the app's Activity as public-tunnel origin.

### `GET /door2/openapi.json`

The OpenAPI actions schema for this phone, generated by the app with the recorded public address already in `servers[0].url` (always a full https address). It describes the Tunnel 2 endpoints for import into a custom GPT or another actions-based chatbot, and it contains **no token** — authentication is configured separately in the chatbot, as an API key sent in the `X-Token` header. The same schema can be copied from the app's Tunnel 2 panel.

### `POST /door2/mcp` — remote MCP endpoint

**Auth:** Tunnel 2 token required. A stateless JSON-RPC endpoint (no sessions, no server-initiated messages) exposing one tool:

```
run_command
  arguments: { "cmd": "echo ok", "timeout": 60 }
  result:    { "stdout": "ok\n", "stderr": "", "code": 0,
               "id": "run-2", "duration_ms": 96, "truncated": false }
```

`timeout` is in seconds and optional. Standard MCP discovery (`tools/list`) returns the single tool; calls count against the same Tunnel 2 rate limits as the REST surface.

### Not on Tunnel 2

* `/door2/log` — does not exist (`404`). Logs never cross the public tunnel.
* Token management — there is no way to create, read, rotate, or revoke a token over HTTP on either tunnel. Tokens are managed only in the app.

## Errors, all surfaces

| Status | Meaning | What to do |
| - | - | - |
| `400` | Malformed request (bad JSON, missing `cmd`). | Fix the request body; don't retry it unchanged. |
| `403` "bad token" | Token missing, wrong, revoked, rotated past grace, or presented on the wrong tunnel. | Check the tunnel and the token; if it persists, ask the owner for a fresh connect block. |
| `403` "door 2 is off" | The app is in Mode 1 (relay); the whole Tunnel 2 surface is off. | Only the owner can change it (Chatbot Access → Your own front door). Do not ask for a Tunnel 1 token instead — it would not work on this surface. |
| `404` | Unknown path — including `/door2/log`, and anything a front door refuses to forward. | Check the path against this reference. |
| `429` | Rate or concurrency limit (Tunnel 2: 30 calls/min/token or 2 runs at once; Tunnel 1: 4 runs at once). | Wait — the reply may carry `retry_after_s` — then continue. Repeated 429s mean you are looping: stop. |
| No response at all | Nothing is listening: bridge stopped, Tailscale down (Tunnel 1), or the front door / relay connection is down (Tunnel 2). | Not an auth problem. Ask the owner to open the app; the Status screen names the cause. Don't retry in a tight loop. |

Error bodies are small JSON objects, e.g. `{"error": "bad token"}`. The distinction between *no response* (nothing listening) and *403* (listening, refusing your token) is deliberate and load-bearing — it is how you tell a stopped bridge from a revoked token without guessing.

## Relay-mode blocks (no HTTP)

For chatbots with no tool ability, the protocol is two fenced text blocks, carried by the user (full flow in the [Tunnel 2 guide](https://docs.leverine.com/bunnybridge/tunnel-2.md)):

````
```bunnybridge
{"cmd": "...", "host": "optional-host-name"}
```
````

````
```bunnybridge-result
{"cmd": "...", "exit_code": 0, "stdout": "...",
 "stderr": "...", "duration_ms": 0}
```
````

One command per block. A block pasted into the Agent Inbox is queued, never auto-run; the owner approves it with a tap. A `bunnybridge-result` block is output, and the app refuses to accept one as a command.

***

*Source: Leverine/Leverine-BunnyBridge\@902c77c — `docs/site/BunnyBridge/api-reference.html`.*


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.