# Check your setup with apidly doctor

`apidly doctor` checks the CLI setup on your computer and your account in a few seconds. Each check prints `ok`, `warning` or `problem` with one sentence, and when something is off, the exact command or console page that fixes it on a `Fix:` line. Run it first whenever a command does not work.

```bash
apidly doctor
```

It only reads. It writes no file, changes nothing on your account and contacts only the API address you set. It never opens a private SSH key: it reads the `.pub` files in `~/.ssh` and checks that the private key file exists next to them. It also works without an API key.

The last line counts the result, for example `1 problem, 2 warnings.` or `Everything looks good.`. The command ends with exit code 1 when there is at least one problem, and 0 otherwise, so a script can stop on it.

## What each check means

| Check | What it looks at | Warning or problem, and the fix |
| --- | --- | --- |
| CLI version | Your version against the latest published one. | Warning: a newer version is out. The fix line downloads it and installs it with npm; check the file against `SHA256SUMS` as the [Command-line tool](/docs/cli) page shows. Also a warning when the latest version could not be read. |
| Config file | The saved settings file: found, readable, valid JSON, private to you. | Warning: no file and no `APIDLY_API_KEY`, so no key is saved (fix: `apidly init`), or other users of the computer can open it (fix: `chmod 600 FILE`). Problem: it cannot be read (fix: `chmod 600 FILE`) or is not valid JSON, so the saved key and address are ignored (fix: `apidly logout && apidly init`). |
| API address | The address from `--api-url`, `APIDLY_API_URL` or the saved settings. | Problem: it is not an `http://` or `https://` address, so it is not used. Fix: `apidly config set api-url https://apidly.com`. |
| API connection | Whether the API answers, and whether your computer's clock agrees with it (within 2 minutes). | Problem: no answer (internet, proxy or firewall) or the host is not the API. Warning: your clock is off, so scheduled times and expiry dates look wrong; the fix line resyncs the clock for your system. |
| API key | The key from `APIDLY_API_KEY` or the saved settings: accepted, its scope, its creator's role, its expiry. | Problem: no key (fix: `apidly init`), the API refuses it because it was deleted, expired or mistyped (fix: `apidly init`), or the check failed (fix: `apidly whoami --debug`). Warning: it expires within 7 days, or it is a server token that reaches only one server. A read-only key is `ok` with a note that it can only look. |
| Balance | Your balance and how long it lasts at the current hourly spend. | Problem: below the $1.00 a new server needs before it starts. Warning: it lasts less than an hour (fix: `apidly topup 20 --accept-terms`), or the account is in a low-balance state. |
| SSH key | An SSH key on your account whose private key is on this computer, in `~/.ssh` or the ssh-agent. | Problem: the account has no SSH key, or none of its keys has its private key here, so SSH from this computer is refused. Warning: no key pair at all. The fix line adds your key (`apidly ssh-keys add ~/.ssh/KEY.pub --name NAME`) or creates one first with `ssh-keygen`. |
| ssh program | Whether `ssh` is installed and on your PATH. | Problem: it is missing, so `apidly ssh` cannot connect. The fix line installs the OpenSSH client for your system. |
| Servers | Servers in `error`, `suspended` or `interrupted`, launches waiting for approval, and launches that failed in the last 24 hours. | Problem for a server in error or suspended (fix: `apidly servers events ID`). Warning for an interrupted server (fix: `apidly start ID`), a launch waiting for an owner or admin, or a recent failed launch (fix: `apidly deployments again ID`). |
| ssh-config block | The block that `apidly ssh-config --write` keeps in `~/.ssh/config`, if you use it. | Warning: it has no end marker, or it does not match your running servers any more (fix: `apidly ssh-config --write`). Not using it is `ok`. |
| Shell completion | Whether tab completion for `apidly` is installed. | Always `ok`; when it is missing, an `Optional:` line gives the command for bash, zsh or fish. |

A check the API did not answer is listed at the end as `Could not run: ...`.

## Offline mode

```bash
apidly doctor --offline
```

Skips every check that needs the network: version, API connection, key check, balance, account SSH keys and servers. The local checks still run: the config file, whether a key is set, the SSH key pairs on this computer, the `ssh` program, the ssh-config block and completion. Use it on a plane, behind a proxy you have not set up yet, or to check a new computer before you add a key.

## JSON output

```bash
apidly doctor --json
```

Prints one list with an object per check: `check` (a stable name such as `key` or `ssh-keys`), `title`, `status` (`ok`, `warning` or `problem`), `message` and, when there is one, `fix`. The exit code is the same as without `--json`, so a CI job can run it before anything else:

```bash
apidly doctor --json | jq -r '.[] | select(.status != "ok") | "\(.status): \(.message)"'
```

## Next

- [Command-line tool](/docs/cli)
- [Use the CLI and API from scratch](/docs/tutorial-cli-and-api)
- [Troubleshooting](/docs/troubleshooting)
