# CLI (/docs/cli)

Every command and flag of herald-cloud, the command line of your workspace.

The CLI is the npm package `@herald-voice/cli`; its command is `herald-cloud`. It signs in to a workspace, brings the workspace's calls to a program on your machine through the tunnel, and does what the dashboard does: numbers, trunks, keys, calls.

```bash
npx @herald-voice/cli help
```

Or install it once:

```bash
npm install -g @herald-voice/cli
herald-cloud help
```

It needs Node 20 or later. `phone` runs on macOS.

## Output and errors [#output-and-errors]

Every command takes `--json`: it prints the result as JSON instead of text, and an error as `{"error": "..."}`. Use it in scripts and coding agents.

```bash
herald-cloud whoami --json
```

A flag takes its value as `--name value` or `--name=value`. An unknown flag stops the command with exit code 2; a failed request exits with 1.

## Sign-in and configuration [#sign-in-and-configuration]

`login` and `signup` save the key of the workspace in `~/.config/herald-cloud/config.json`, with the app's address and the tunnel server. Every other command reads it.

| Environment variable | Used by | |
|---|---|---|
| `HERALD_CLOUD_APP` | `login`, `signup`, `tunnel` | the address of herald cloud, instead of `--app` |
| `HERALD_CLOUD_KEY` | `tunnel` | an API key, instead of the one saved by `login` |
| `HERALD_CLOUD_TUNNEL` | `tunnel` | the tunnel server, instead of the one saved by `login` |
| `HERALD_PHONE` | `phone` | the path of the `herald-phone` binary to run |

## Account [#account]

### signup [#signup]

```bash
herald-cloud signup [--app URL] [--no-browser]
```

Opens the sign-up page in the browser. Create the workspace, approve the code the terminal shows, and the CLI is signed in to it.

| Flag | |
|---|---|
| `--app URL` | the address of herald cloud; needed the first time |
| `--no-browser` | print the link without opening the browser |

### login [#login]

```bash
herald-cloud login [--app URL] [--no-browser]
```

Prints a code and opens the approval page. Sign in, check that the page shows the same code, and approve it: the app creates an API key named `CLI, <date>` and the CLI saves it. The code expires after 10 minutes.

```bash
herald-cloud login --app <herald cloud URL>
```

```text
Open this page and approve the code BCDF-GHJK:

  <herald cloud URL>/cli?code=BCDF-GHJK

Waiting for the approval…
Signed in to Acme (w-…). Next: herald-cloud tunnel <port of your server>
```

Flags as for `signup`.

### whoami [#whoami]

```bash
herald-cloud whoami
```

The workspace, where its calls go, and its test line.

```text
Acme (w-…) on <herald cloud URL>
calls go to: https://w-….<tunnel host>/herald (the tunnel)
test line:   sip:712345678901@<herald SIP address>
```

With `--json` it prints the workspace object of [`GET /api/cli/workspace`](/docs/api#get-workspace).

### env [#env]

```bash
herald-cloud env >> .env
```

Prints `HERALD_SECRET=<signing secret>`, the secret your program verifies herald's requests with.

### open [#open]

```bash
herald-cloud open
```

Opens the dashboard in the browser.

### logout [#logout]

```bash
herald-cloud logout
```

Deletes the saved key from this machine. The key stays valid until you revoke it (`keys revoke`, or Developers → API keys).

## Calls to your program [#calls-to-your-program]

### tunnel [#tunnel]

```bash
herald-cloud tunnel <port> [--path /herald] [--route /path=port]... [--no-switch] [--key KEY] [--server URL]
```

Connects to the tunnel server and forwards herald's requests and WebSocket streams to `http://127.0.0.1:<port>`. Once connected, it switches the workspace to the tunnel and prints the test line. Leave it running; Ctrl-C stops it. When another tunnel connects with the same workspace, this one exits.

| Flag | |
|---|---|
| `<port>` | the local port of your program (required) |
| `--path P` | the path your program serves calls on, e.g. `/herald`; saved as the workspace's tunnel path |
| `--route /path=port` | send requests under `/path` to another local port; repeat it for more |
| `--no-switch` | only connect: leave the workspace's voice URL as it is |
| `--key KEY` | an API key, instead of signing in (CI, a server) |
| `--server URL` | the tunnel server, instead of the one saved by `login` |

```bash
herald-cloud tunnel 4000 --path /herald
```

```text
calls reach http://127.0.0.1:4000/herald
call your test line: sip:712345678901@<herald SIP address>
leave this running; Ctrl-C stops it
```

Without `login`:

```bash
HERALD_CLOUD_KEY=hc_… HERALD_CLOUD_TUNNEL=<tunnel server> herald-cloud tunnel 4000
```

### backend [#backend]

```bash
herald-cloud backend [--url URL | --tunnel] [--path P] [--status-webhook URL]
```

Without flags, shows where the workspace's calls go. With flags, changes it.

| Flag | |
|---|---|
| `--url URL` | send calls to a public voice URL: `https://…`, or `wss://…` for a program that takes every call as a stream |
| `--tunnel` | send calls through the tunnel |
| `--path P` | the tunnel path, e.g. `/herald` |
| `--status-webhook URL` | where herald posts `call.ended`; an empty value goes back to the voice URL |

`--url` and `--tunnel` cannot be used together.

```bash
herald-cloud backend --url https://api.example.com/herald
```

### test [#test]

```bash
herald-cloud test
```

Sends the voice URL a `call.incoming` signed with the workspace's secret, as herald would, and prints what came back: the status, the time and the verbs. The test call has an id starting with `test-` and comes from `sip:test@herald.cloud`. It exits with 1 when the program does not answer with verbs, with a hint about the cause.

```text
https://api.example.com/herald answered 200 in 41 ms with 2 verbs:
{
  "verbs": [ … ]
}
```

A WebSocket voice URL gets no test requests: call the test line instead.

### prompt [#prompt]

```bash
herald-cloud prompt [--port N] [--template agent|menu|custom] [--task TEXT]
```

Prints a prompt for a coding agent with this workspace's details: the secret, where calls go, the SDK, how to start the tunnel and call the test line.

| Flag | |
|---|---|
| `--port N` | the port the program listens on (default 4000) |
| `--template T` | `agent` (a voice agent), `menu` (a key menu) or `custom` (default) |
| `--task TEXT` | what the phone line should do; each template has a default |

```bash
herald-cloud prompt --template agent --task "Book visits for a dentist" | pbcopy
```

## Numbers and trunks [#numbers-and-trunks]

### numbers [#numbers]

```bash
herald-cloud numbers
herald-cloud numbers add <number>
herald-cloud numbers verify <number> [--wait]
herald-cloud numbers remove <number>
```

| Command | |
|---|---|
| `numbers` | list the numbers, and whether each is verified |
| `numbers add <number>` | add a number in international format, e.g. `+390212345678` (at most 10) |
| `numbers verify <number>` | herald calls the number; answer and type the code it prints |
| `numbers verify <number> --wait` | ... and wait up to 10 minutes until it is verified |
| `numbers remove <number>` | remove it |

A number takes calls once verified.

### trunks [#trunks]

```bash
herald-cloud trunks
herald-cloud trunks add --name N --registrar HOST --username U [flags]
herald-cloud trunks remove <name>
```

`trunks` lists the SIP accounts (trunks) of the workspace with their state: `registered`, `not registered`, `waiting for review` or `approved`.

`trunks add` adds one:

| Flag | |
|---|---|
| `--name N` | lowercase letters, digits and `-` (required) |
| `--registrar HOST` | the provider's `host` or `host:port` (required) |
| `--username U` | the SIP username (required) |
| `--password-stdin` | read the password from standard input |
| `--password P` | the password on the command line |
| `--transport T` | `udp` (default), `tcp` or `tls` |
| `--outbound` | place calls out through this trunk |
| `--caller-id NUM` | the number calls out show |
| `--no-register` | herald does not register: the provider sends calls from fixed addresses |
| `--sources CIDR,...` | with `--no-register`: the addresses calls come from, at most a /16 (IPv4) or /32 (IPv6) |
| `--auth-username U` | the username for authentication, when it differs from `--username` |
| `--domain D` | the SIP domain, when it differs from the registrar |
| `--contact-user U` | the user in the Contact header |

```bash
echo "$SIP_PASSWORD" | herald-cloud trunks add --name main --registrar sip.provider.example --username 0212345678 --password-stdin --outbound --caller-id +390212345678
```

A trunk with `--no-register` takes calls once it is approved in review.

### keys [#keys]

```bash
herald-cloud keys
herald-cloud keys create [--name N]
herald-cloud keys revoke <prefix>
```

| Command | |
|---|---|
| `keys` | list the API keys: name, prefix, created; the one this CLI uses is marked |
| `keys create [--name N]` | create a key; it is printed once |
| `keys revoke <prefix>` | revoke a key by its prefix (as `keys` shows it) or its name |

A key works for the tunnel, for herald's REST API and for this CLI, and sees only this workspace.

## Calls [#calls]

### calls [#calls-1]

```bash
herald-cloud calls [--live] [--limit N]
herald-cloud calls show <id>
herald-cloud calls hangup <id>
```

| Command | |
|---|---|
| `calls` | the last calls (20 by default): when, from, number, seconds, how they ended |
| `calls --limit N` | the last N calls, at most 200 |
| `calls --live` | the calls in progress: id, from, number, since, state (`ringing`, `answered`, `streaming`, `transferring`) |
| `calls show <id>` | one call, with the event herald sent for it |
| `calls hangup <id>` | end a call in progress |

### call [#call]

```bash
herald-cloud call <number> [--voice-url URL] [--trunk T] [--caller-id NUM]
```

Places a call out with herald's REST API. Once answered, the program at the voice URL takes it. It needs a trunk with `--outbound`.

| Flag | |
|---|---|
| `--voice-url URL` | the program that takes the call; default: the workspace's voice URL |
| `--trunk T` | the trunk to call through |
| `--caller-id NUM` | the number the call shows |

```text
calling +390212345678: call c-…; once answered, https://api.example.com/herald takes it
```

### phone [#phone]

```bash
herald-cloud phone [sip:USER@HOST] [--from USER] [--plain]
```

Calls the workspace's test line, or a SIP address, with this computer's microphone and speaker, and shows a phone in the terminal: the keypad, the call's time and both sides' levels. During the call `0`-`9`, `*` and `#` send DTMF, `m` mutes and `q` hangs up. Use headphones: it has no echo cancellation. The first call asks macOS for microphone access for the terminal app.

| Flag | |
|---|---|
| `sip:USER@HOST` | the address to call; default: the test line |
| `--from USER` | the user the call comes from |
| `--plain` | a line per step instead of the phone on screen |

### test-line [#test-line]

```bash
herald-cloud test-line
herald-cloud test-line rotate
```

Prints the test line as a SIP address. `rotate` gives the workspace a new one; the old one stops ringing.

### secret rotate [#secret-rotate]

```bash
herald-cloud secret rotate
```

Gives the workspace a new signing secret and prints it as `HERALD_SECRET=...`. herald signs with it at once: update your program.