# Access: key, hosts, ceilings and the CLI

## The key

| | |
|---|---|
| Where it comes from | Your user gives it. Keys are issued by invitation; without one, your user asks at support@capacitylab.dev. |
| API address | `https://api.capacitylab.dev` |
| Authorization | `Authorization: Bearer <key>` on every API request. The CLI reads `CAPACITYLAB_KEY` (or `--api-key`). |
| Key page | https://api.capacitylab.dev/key: balance, runs, ledger. In the terminal: `capacitylab-load me` (balance, ceilings, the host proof line, windows, baselines); as JSON: `GET /me`. |

Keep the key in an ignored local env file as `CAPACITYLAB_KEY=cl_...`. The CLI reads it from the environment, `--api-key`, or the file given with `--secrets-file`, so the key and the scenario's secrets can share one file. Never print it, commit it or paste it anywhere public.

## Hosts

Ask your user which exact host(s) they own and want to test, usually staging. Test nothing else.

A key runs only against hosts the operator wrote into it or the owner proved. To prove a host, publish the key's line `capacitylab-verify=<key_id>` (not a secret; `GET /me` shows it as `host_proof.line`) in one of two ways:

| Way | Where | Rules |
|---|---|---|
| File (preferred) | a line of `https://<host>/.well-known/capacitylab-verify.txt` | status 200 from the host itself, no redirect, the same scheme and port as `--target`; one file may hold the lines of several keys |
| DNS | TXT record `_capacitylab-verify.<host>` with the line as its value | covers every port of that name |

- Exact hostnames, no wildcards: every subdomain is its own host.
- Common traps for the file: Express's `express.static` skips dot-paths (serve it with `dotfiles: "allow"` or an explicit route); many nginx configs deny `location ~ /\.` (add an exception for `/.well-known/`); a single-page app's fallback answers 200 with `index.html`. Check that an anonymous request returns the line itself.
- The line is checked before every run, so keep it while you test. A host without it is refused with `403 host_not_allowed`, which names the file URL and TXT name to publish ([api.md](/docs/api.md#refusals)).
- A proved host takes load only over `https` with a real certificate for its name. `http://` targets and `--insecure` (self-signed certificates) work only for hosts the operator wrote into the key; with a proved host in the run they are refused with `403 host_not_allowed`.
- Internal addresses (localhost, private IPs, names without a dot) and IPv6 literals are refused for every key. The generator connects to no private address, whatever the target's name resolves to.
- A run stops itself when there is no target to measure: after 20 requests that met a wrong certificate (unknown issuer, another name) or a name that resolved to a private address, and once one virtual user got no HTTP response from a host ten times in a row (connection refused or reset, a failed TLS handshake, timeouts); each host of the run is counted on its own. It pays only for the minutes it ran. Bring the target up, or fix its certificate, DNS record or port, and smoke again. A target that collapses completely under load, or restarts during the run and refuses connections meanwhile, stops the run the same way: the stages before it are its limit. How soon depends on the rate and the number of virtual users: seconds at a high rate, minutes at a few requests a second.
- Several hosts in one scenario: one Arazzo `sourceDescription` per host and a repeatable `--target <source-name>=<origin>` ([load-format.md](/docs/load-format.md)).

## Test windows

Limit when a host may get load, e.g. production only at night on weekdays. The windows belong to the key and the host:

```bash
capacitylab-load window prod.example.com --allow "mon-fri 01:00-05:00; sat,sun 00:00-24:00" --tz Europe/Moscow
capacitylab-load window                      # every host's windows, open or closed now
capacitylab-load window prod.example.com --clear
```

- Days: `mon`…`sun`, ranges (`mon-fri`), lists (`sat,sun`) or `daily`; times `HH:MM` from `00:00` to `24:00`. `22:00-06:00` crosses midnight and belongs to the day it starts: `fri 22:00-06:00` is the night from Friday to Saturday. Up to 8 windows per host and 32 hosts per key; windows that touch join into one. The time zone is an IANA name (default `UTC`); daylight saving time is followed.
- A cloud run starts only if the whole run plus 3 minutes for the generator to start and finish fits into the windows from now. Otherwise it is refused with `403 outside_test_window` (not charged), which names the next start that fits; the CLI then exits 4 without starting, or waits for it with `--wait-for-window <d>`.
- Smoke runs (one iteration of every workflow) are not load and start any time.
- The windows bind runs of this key only; another key on the same host needs its own.

## Ceilings and price

| | |
|---|---|
| Rate and duration | the key's ceilings (`GET /me`). The rate is agreed per key: for a higher one, your user asks at support@capacitylab.dev. |
| Per run | at most 2,500 VUs and 3 hours |
| At once | one active run per key |
| Price | the generator machine's minutes: the run's length (ramp-up and duration, plus one minute for each of setup and teardown) rounded up to a minute, times the machine's rate. At least 1 credit; a plain smoke run costs 1. The price is charged when the run is accepted, and the CLI prints it. How many requests or iterations the run sends does not change it. |
| Machine | chosen from what the run declares. 1 credit a minute: up to 500 VUs, 200 iterations/s and 30 minutes. 2 credits a minute: up to 1,200 VUs and 500 iterations/s (a run over 30 minutes only up to 200 iterations/s). 4 credits a minute: anything larger. |
| Refunds | one rule: a run pays for the minutes its machine ran, counted by the service from the moment the generator took the job, at least 1 credit and never more than the price. The rest comes back automatically, however the run ended: an SLO stop, a failed setup, a generator abort, or you stopping it. A generator that never started costs nothing. A run that returned no summary is charged in full and the operator is notified. The run's `price` and `refunded` are in `GET /runs/<id>` ([results.md](/docs/results.md)) |

## The CLI

```bash
bun install -g git+https://trylle.com/oleglugov09-ship-it/capacitylab-load.git   # install or update (requires Bun)
capacitylab-load version                                                           # this CLI and the latest one
```

- Every API answer names the latest version. An older CLI prints `Update available: … Run: bun install -g …` at the end: update with the same command before the next run, and tell your user.
- A CLI below the minimum is refused with `426 cli_outdated`.
- Source: https://trylle.com/oleglugov09-ship-it/capacitylab-load
