|
| 1 | +# qn — usage guide for agents |
| 2 | + |
| 3 | +`qn` is the Quicknode command-line interface. It manages endpoints, streams, |
| 4 | +webhooks, the KV store, usage, metrics, billing, and teams. |
| 5 | + |
| 6 | +This guide describes qn v{{VERSION}}. It prints as Markdown by default — no flag |
| 7 | +needed to read it. For a structured envelope (`{version, guide}`), pass `-o json`. |
| 8 | +Read the control-flow sections (auth, output, exit codes, confirmation, retry) |
| 9 | +before the command catalog: they decide whether you can run unattended without |
| 10 | +hanging or double-acting. |
| 11 | + |
| 12 | +## 1. Auth |
| 13 | + |
| 14 | +Resolution order for the API key: |
| 15 | + |
| 16 | +1. `--api-key <KEY>` flag (highest precedence). |
| 17 | +2. Config file: `[api] key = "..."` in `~/.config/qn/config.toml` (or the path |
| 18 | + passed to `--config-file`). |
| 19 | +3. If neither resolves, the command exits **4** (`no API key found`). |
| 20 | + |
| 21 | +There is **no environment-variable fallback** by design — a key left exported in |
| 22 | +a shell is invisible state that outlives the session. |
| 23 | + |
| 24 | +Non-interactive paths: |
| 25 | + |
| 26 | +- Pass `--api-key <KEY>` on every invocation, or |
| 27 | +- Write the key once: `qn auth login --api-key <KEY>` (saves the config file). |
| 28 | + |
| 29 | +Config file location: |
| 30 | + |
| 31 | +- Linux/macOS: `$XDG_CONFIG_HOME/qn/config.toml`, else `~/.config/qn/config.toml`. |
| 32 | +- Windows: `%USERPROFILE%\.config\qn\config.toml`. |
| 33 | + |
| 34 | +Verify the resolved key against the API: `qn auth whoami` (prints the key redacted |
| 35 | +to `****<last4>` and confirms it works). `qn auth status` does the same without the |
| 36 | +network call. |
| 37 | + |
| 38 | +## 2. Output contract |
| 39 | + |
| 40 | +- Default format is `table` on a TTY and **`toon`** when stdout is not a TTY (piped). |
| 41 | +- Data goes to **stdout**; diagnostics, prompts, and ✓ confirmations go to **stderr**. |
| 42 | +- Formats: `table`, `md`, `json`, `yaml`, `toon`. The structured forms |
| 43 | + (`json`/`yaml`/`toon`) always include every field — `--wide` is not needed and |
| 44 | + only affects `table`/`md`. |
| 45 | +- Config file can set defaults: `[output] format = "json"`, `wide = true`. |
| 46 | + |
| 47 | +## 3. Exit codes |
| 48 | + |
| 49 | +Branch on these — especially **4** and **5**. |
| 50 | + |
| 51 | +| Code | Meaning | |
| 52 | +|------|---------| |
| 53 | +| 0 | Success. | |
| 54 | +| 1 | Generic CLI error (bad arguments, I/O, unclassified failure). | |
| 55 | +| 2 | API error — the server returned a non-2xx response. | |
| 56 | +| 3 | HTTP error — network failure (connect/timeout). | |
| 57 | +| 4 | Auth/config — no API key, or a config file that can't be read or written. | |
| 58 | +| 5 | Cancelled, or confirmation required and not granted (see §4). | |
| 59 | +| 130 | Interrupted (SIGINT). | |
| 60 | + |
| 61 | +## 4. Non-interactive & confirmation behavior |
| 62 | + |
| 63 | +Destructive commands are gated. On a TTY they prompt `y/N`. To proceed without a |
| 64 | +prompt, pass `--yes` (`-y`). |
| 65 | + |
| 66 | +In a non-TTY **a gated command without `--yes` exits 5 before any request is sent** — |
| 67 | +nothing is changed. Pass `-y` to proceed, or `--no-input` to force non-interactive |
| 68 | +behavior everywhere (it fails fast instead of prompting). `--quiet` (`-q`) suppresses |
| 69 | +the ✓ state-change notes on stderr; it does not affect stdout. |
| 70 | + |
| 71 | +Gated command classes: |
| 72 | + |
| 73 | +- `endpoint archive`, `endpoint bulk pause` |
| 74 | +- `endpoint tag delete` |
| 75 | +- `endpoint security` removals (token/jwt/ip/referrer/domain-mask remove, and |
| 76 | + `set-options` toggles that disable a protection) |
| 77 | +- `endpoint rate-limit delete-override` |
| 78 | +- `stream delete`, `webhook delete`, `team delete` |
| 79 | +- `kv set delete`, `kv list delete` |
| 80 | + |
| 81 | +There is **no account-wide wipe command** — that is intentional; use the API directly |
| 82 | +if you need it. |
| 83 | + |
| 84 | +## 5. Retry & idempotency |
| 85 | + |
| 86 | +- **Read-only** commands auto-retry transient failures (HTTP 429/500/502/503/504 and |
| 87 | + connect/timeout errors) with exponential backoff and jitter. Tune with `--retries N` |
| 88 | + (default 3; `0` = a single attempt, no retries). |
| 89 | +- **Mutations never auto-retry.** A retried create/update/delete could apply twice. |
| 90 | +- When a mutation fails transiently, its outcome is unknown until verified — e.g. |
| 91 | + `qn endpoint show <id>` reflects whether it took effect. |
| 92 | +- `qn stream test-filter` evaluates a filter against historical data and changes |
| 93 | + nothing — it is read-only and safe to retry. |
| 94 | + |
| 95 | +## 6. Command catalog |
| 96 | + |
| 97 | +Top-level nouns (plurals like `endpoints`/`streams` and `ls` are accepted aliases): |
| 98 | + |
| 99 | +- `auth` — login, logout, whoami, status |
| 100 | +- `endpoint` — list, show, create, update, archive, pause, resume, urls, logs, |
| 101 | + log-details, metrics, enable-multichain, disable-multichain; nested: |
| 102 | + `tag`, `security`, `rate-limit`, `bulk` |
| 103 | +- `team` — list, create, show, delete, endpoints, set-endpoints; nested: `member` |
| 104 | +- `usage` — summary, by-endpoint, by-method, by-chain, by-tag |
| 105 | +- `metrics` — account, endpoint |
| 106 | +- `chain` — list |
| 107 | +- `billing` — invoices, payments |
| 108 | +- `stream` — list, show, create, update, delete, activate, pause, test-filter, |
| 109 | + enabled-count |
| 110 | +- `webhook` — list, show, create, update, update-template, delete, activate, pause, |
| 111 | + enabled-count |
| 112 | +- `kv` — `set` (put, get, list, delete, bulk) and `list` (list, get, create, append, |
| 113 | + contains, remove-item, update, delete) |
| 114 | + |
| 115 | +Drill into any level with `--help`: `qn endpoint --help`, `qn endpoint security --help`, |
| 116 | +`qn endpoint rate-limit --help`. Shell completions: `qn completions <bash|zsh|fish|...>`. |
| 117 | + |
| 118 | +## 7. Common workflows |
| 119 | + |
| 120 | +Capture the `id` (and any URL) from each create response and chain it into the next call. |
| 121 | +Run `show` before a state change so you act on the current state, not an assumed one. |
| 122 | + |
| 123 | +**Provision an endpoint and rate-limit it:** |
| 124 | + |
| 125 | +```sh |
| 126 | +qn endpoint create --chain ethereum --network mainnet # → id, http_url, wss_url |
| 127 | +qn endpoint show <id> # inspect before modifying |
| 128 | +qn endpoint rate-limit set <id> --rps 50 |
| 129 | +qn endpoint show <id> # verify |
| 130 | +``` |
| 131 | + |
| 132 | +**Create a stream (paused), inspect it, then activate:** |
| 133 | + |
| 134 | +```sh |
| 135 | +qn stream create --name my-stream --network ethereum-mainnet \ |
| 136 | + --dataset block --start 15301579 --end 25301589 \ |
| 137 | + --batch-size 2 --fix-block-reorgs 1 \ |
| 138 | + --notification-email you@example.com --status paused \ |
| 139 | + --webhook https://hook.example.com --region usa-east # → id |
| 140 | +qn stream show <id> # inspect while paused |
| 141 | +qn stream activate <id> |
| 142 | +``` |
| 143 | + |
| 144 | +**Create a webhook from a template:** |
| 145 | + |
| 146 | +```sh |
| 147 | +qn webhook create --name wallet-watch --network ethereum-mainnet \ |
| 148 | + --url https://hook.example.com --template evm-wallet \ |
| 149 | + --wallet 0xabc... # → id |
| 150 | +qn webhook show <id> # inspect before activating |
| 151 | +qn webhook activate <id> |
| 152 | +``` |
| 153 | + |
| 154 | +**KV put / get / list:** |
| 155 | + |
| 156 | +```sh |
| 157 | +qn kv set put my-key my-value |
| 158 | +qn kv set get my-key |
| 159 | +qn kv set list |
| 160 | +``` |
| 161 | + |
| 162 | +## 8. Gotchas & safety rails |
| 163 | + |
| 164 | +- Mutations are never retried; re-running a failed create can double-provision (§5). |
| 165 | +- No account-wide wipe command exists by design (§4). |
| 166 | +- Piped output defaults to `toon`, not `json` (§2). |
| 167 | +- `--base-url` overrides the API host; it exists for testing. |
| 168 | +- For *this* command, `-o yaml`/`-o toon`/`-o table` print Markdown (with a note on |
| 169 | + stderr); `-o json` produces the `{version, guide}` envelope. |
| 170 | + |
| 171 | +## 9. More |
| 172 | + |
| 173 | +- `qn --help`, and `--help` at every noun/verb level, document flags exhaustively. |
| 174 | +- Docs: https://www.quicknode.com/docs |
| 175 | +- This guide self-describes its version: it matches qn v{{VERSION}}. |
0 commit comments