--- name: hyperbox-credentials description: Find and connect to a user's Hyperboxes, or create and delete Macs through the Hyperbox API when the user requests fleet changes. --- # Hyperbox credentials Use the Hyperbox API to identify the requested machine and retrieve current login, SSH, Screen Sharing, or RustDesk credentials. When the user requests a new Mac or deletion, use the purchase and deletion endpoints below. ## Authentication - Read `HYPERBOX_API_KEY` from the environment or the user's secret manager. If it is missing, ask the user to create a key at https://hyperbox.sh/api-keys and configure it as a secret. Do not ask them to paste it into chat. - Base URL: `https://hyperbox.sh/api/v1/hyperboxes`. Send `Authorization: Bearer ` over HTTPS. Every valid account key, including existing keys, can purchase Macs, delete Hyperboxes, and retrieve credentials for the owner's account. A purchase charges the authorized default card and starts monthly recurring billing. - Keep the API key, passwords, and connection URLs out of chat, logs, screenshots, committed files, and shell history. Pass credentials directly to the connection tool or hold them in memory for the authorized task. ## Choose a machine 1. `GET /api/v1/hyperboxes` lists `hyperboxes` with `id`, `name`, `product`, `status`, and `createdAt`, without passwords. List metadata first. 2. List endpoints accept `limit` (1–100, default 100) and `cursor`. Follow `pagination.nextCursor` until it is `null`, including when a page is empty. URL-encode the cursor. Retired Hyperboxes are excluded. 3. Match the user's requested ID or name. Names can repeat or change; use the stable `id` for subsequent calls. If multiple machines match and the task does not disambiguate them, ask which one. Do not assume the first machine is the target. 4. `GET /api/v1/hyperboxes/{id}/credentials` returns `{ "hyperbox": { ...metadata, "credentials": ..., "unavailableReason": null } }` for a running, assigned machine. 5. For an explicitly requested fleet operation, `GET /api/v1/hyperboxes/credentials` returns paginated metadata and credentials together. Entries that are not ready have `credentials: null` and `unavailableReason`. Skip those entries and report their IDs/status without secrets. ## Use the response `credentials` contains: - `login`: macOS/Linux `username` and `password`. - `ssh`: `{ host, port, username, password }` or `null`. Use only this endpoint for SSH. SSH-enabled physical Macs return their verified customer SSH relay endpoint. Other Macs return `ssh: null`; never use the Screen Sharing relay port for SSH. - `screenSharing`: `{ host, port, username, password, url }` or `null`. The `vnc://` URL includes credentials and can open a Screen Sharing client. - `rustdesk`: `{ id, password, url, server }` or `null`. `server`, when configured, contains `hbbsHost`, `hbbsPort`, `hbbrHost`, `hbbrPort`, and `publicKey`; `url` is a RustDesk deep link with credentials. Unavailable connection methods are `null`; do not invent hosts, ports, passwords, or SSH access. Fetch credentials again when reconnecting after a reset or reassignment. Retrieval does not authorize unrelated changes to the remote machine. ## Create or delete a Mac Only purchase or delete when the user requests it. A request to connect to an existing machine does not authorize buying a replacement. 1. The owner first adds or authorizes a default card at https://hyperbox.sh/billing. Adding a card is free; it authorizes website/API purchases and monthly renewals. 2. `GET /api/v1/hyperboxes/offers` returns the current catalog, available `macSku` values, and monthly USD prices in cents. 3. `POST /api/v1/hyperboxes` creates one Mac. Send JSON with `name`, an offered `macSku` (omit for the generic catalog), optional `maxMonthlyPriceCents`, and optional `reservationId` for an owned older manual reservation. Send a unique `Idempotency-Key` header for each intended purchase. The API request confirms the charge. 4. On a timeout or temporary error, retry exactly the same key and body. Never generate a new key to retry an uncertain request. `202` returns `purchase.id`, `statusUrl`, and the recurring price. Poll the status URL with the same bearer token every few seconds, within the shared rate limit. 5. `succeeded` includes `hyperboxId` and `credentialsUrl`. `requires_action` includes an `authenticationUrl`; ask the owner to open it and authenticate their card, then poll the same purchase. Unfinished payments expire after 30 minutes. `failed` includes `errorCode`; a new intended attempt needs a new key. Sold-out requests do not charge. Paid allocation failures cancel the subscription, refund cash, and restore account credits. 6. `DELETE /api/v1/hyperboxes/{id}` returns `202`. Cancellation is asynchronous and safe to repeat. Metadata shows `terminating` until Stripe confirms cancellation, then the machine disappears from the list. This ends future monthly charges and preserves canceled billing history; it does not refund the current paid period. ## Reserve for automatic purchase 1. Only reserve when the user authorizes an automatic charge at the offered monthly price when stock is available. The owner needs an authorized default card in Billing. 2. `POST /api/v1/hyperboxes/reservations` takes `name`, the offered `macSku` (omit for the generic catalog), and the exact `monthlyPriceCents` from the offers endpoint. Send a separate `Idempotency-Key` for each Mac and reuse that key and body on retry. If the price changed, confirm the new price with the user before submitting. 3. `202` returns `reservation.id` and `statusUrl`. A `queued` reservation waits for matching stock. `processing` means stock is held and the automatic payment has started. `requires_action` includes `purchase.authenticationUrl`; the owner can authenticate in Billing within 22 hours from allocation. `fulfilled` includes `hyperboxId`. A `failed` reservation ends the attempt. 4. Poll the reservation's status URL and use `DELETE /api/v1/hyperboxes/reservations/{id}` to cancel while queued or dismiss a failed reservation. A legacy reservation can also be canceled before activation. A fulfilled Mac has its own monthly subscription. Hyperbox sends a reservation receipt and a separate Mac-ready email to the verified account address. ## Errors and retries Errors are JSON: `{ "error": { "code": "...", "message": "..." } }`. - `400`: fix request parameters; for `invalid_cursor`, restart pagination. - `401`: the key is missing, invalid, expired, or revoked. Stop and ask the user to configure a valid key; do not retry the same key. - `402`: the owner must save or authorize a valid default card in Billing. - `404`: the Hyperbox is missing or inaccessible. Refresh the metadata list; do not probe other accounts. - `409`: credentials are unavailable (`not_ready` or `no_longer_assigned`), inventory is sold out (`out_of_stock`), the price exceeds the cap (`price_changed`), or the same purchase key was used with a different body (`idempotency_conflict`). Inspect the code and fix the cause; do not blindly retry or raise the price cap. - `429`: wait for `Retry-After` seconds. The limit is 60 requests/minute/key. - `503`: retry with backoff. Use a request timeout and at most three attempts for temporary failures, then report the issue without secrets. Full reference and examples: https://hyperbox.sh/docs