Skip to Content
InstaHost

CLI

The dependency-free command line, available to repository collaborators.

CLI

Available to repository collaborators for now. Git asks others to sign in; use the curl quick start if you do not have access.

The CLI has no dependencies and runs from a clone of the repository with Node.js 22.18 or later (23.6 or later on the 23 line), through Node's built-in TypeScript type stripping. There is nothing to install or build.

git clone 'https://github.com/theGlenn/instahost'
cd instahost
export INSTAHOST_API_URL='https://instahost.dev'
node packages/cli/bin/instahost.mjs share ./report.pdf
node packages/cli/bin/instahost.mjs share ./data.json --access private --ttl 1h --json
node packages/cli/bin/instahost.mjs publish ./dist --ttl 7d --json
node packages/cli/bin/instahost.mjs delete <id or URL> --token ihd_...

The npm package named instahost belongs to someone else and is unrelated to this project: do not install it or run it through npm or npx. This CLI is distributed only through the repository.

CLI reference

node packages/cli/bin/instahost.mjs share <file>    [--ttl 24h] [--access unlisted|public|private] [--name <filename>] [--content-type <type>]
node packages/cli/bin/instahost.mjs publish <dir>   [--ttl 24h] [--access unlisted|public] [--include-dotfiles] [--concurrency 6]
node packages/cli/bin/instahost.mjs delete <id|url> [--token <ihd_...>]

Options

OptionCommandsMeaning
--jsonallPrint exactly one JSON document on stdout, for every outcome. Nothing else is printed unless --verbose.
--api-url <url>allThe API origin; else INSTAHOST_API_URL, else the CLI's built-in default. https:// only, or http:// for localhost, 127.0.0.0/8 and [::1].
--api-key <key>allAn API key (ihk_...); else INSTAHOST_API_KEY. Longer lifetimes, --ttl never, higher limits. The CLI then also uses the key, not the delete token, for the uploads and complete of the artifacts it creates (so they count against the key's rate limits), and the key deletes the artifacts it owns.
--verboseallDiagnostics on stderr, with tokens and URL signatures masked.
--help, -hallUsage. With --json: {"ok": true, "help": "..."}.
--versionallThe CLI version. With --json: {"ok": true, "version": "..."}.
--ttl <lifetime>share, publishA number with s, m, h or d (30m, 24h, 7d), plain seconds, or never (persistent; needs an API key). Default: the service's 1 day.
--access <mode>share, publishunlisted (default), public, or private (share only; publish --access private is a usage error).
--name <filename>shareThe name to share the file under (no /); the default is the file's own name.
--content-type <type>shareDeclares the media type instead of deriving it from the extension.
--include-dotfilespublishAlso publish dot-prefixed files and directories. Credentials, VCS data and OS metadata stay excluded.
--concurrency <n>publishParallel uploads, 1 to 16 (default 6).
--token <ihd_...>deleteThe artifact's delete token.

An option given to a command it does not belong to is a usage error (exit 2). delete takes an artifact id or any of its URLs (a file URL, or a site URL in either mode). Its credential is the first of: --token, --api-key, INSTAHOST_DELETE_TOKEN, INSTAHOST_API_KEY. Flags come before the environment; the environment keeps the token out of the process list.

What share and publish refuse or skip

  • share refuses symbolic links, directories, names that look like credentials (the shared name and the real file's name), and any file whose real path goes through a credential or VCS directory (.ssh, .git, .aws, …).
  • publish refuses a directory inside such a directory, and one without a root index.html. It walks the directory without following symbolic links and skips, listing each under skipped with its reason: sensitive (credential and VCS names, always), os_metadata (.DS_Store, Thumbs.db, desktop.ini, ._*, __MACOSX/), dotfile (dot-prefixed paths except .well-known, unless --include-dotfiles), symlink and special (sockets, FIFOs, devices). A skipped directory is listed once with a trailing /.
  • Both refuse a file that changes between hashing and upload (file_changed).

Output

Without --json, the result goes to stdout (URL, access URL, expiry and the delete command) and skipped files, warnings and errors to stderr; progress is shown only when stderr is a terminal. Control and bidirectional-text characters from file names and server messages are shown as \uXXXX.

With --json, share and publish print:

{"ok": true, "id": "...", "type": "site", "access": "unlisted", "url": "https://<id>.instahost.cloud/",
 "expires_at": "2026-11-29T10:00:00Z", "delete_token": "ihd_...", "access_token": null, "access_url": null,
 "file_count": 12, "total_bytes": 482113,
 "skipped": [{"path": ".git/", "reason": "sensitive"}],
 "warnings": [{"code": "root_absolute_reference", "message": "...", "paths": ["index.html"]}]}

access_token and access_url are set for private files. warnings is a list of {code, message, paths}; the CLI emits root_absolute_reference only when the site's URL has a path (path mode). delete prints {"ok": true, "id": "...", "status": "deleted", "deleted_at": "..."} (status is blocked, with deleted_at: null, for an artifact the operator took down).

Every failure prints one document:

{"ok": false, "error": {"code": "quota_exceeded", "message": "...", "details": {"scope": "client", "resets_at": "..."}, "exit_code": 6}}

code is the API's error code, or one of the CLI's own codes below. When a failure happens after the artifact was created (during the uploads or complete), details.artifact holds {id, url, delete_token, access_url}, unmasked, because the artifact may exist and its delete token is the only way to remove it.

Exit codes

ExitMeaning
0Success.
1Internal error in the CLI (internal_error, cli_load_failed).
2Usage: unknown command or option, bad value, missing API URL or credential, unsupported Node.js version.
3Local input refused before any request: file_not_found, not_a_file, not_a_directory, unreadable_file, unreadable_directory, symlink_refused, sensitive_file, invalid_path, duplicate_path, missing_index, empty_directory, walk_too_many_files (over 10,000 files); also file_changed.
4Authentication or authorization: HTTP 401 or 403.
5Rejected by the server: 400, 413, 415, 422 and other 4xx not listed here.
6Rate limited or over quota: HTTP 429. details.retry_after_seconds carries Retry-After.
7Network or server failure: 5xx, connection errors, storage refusing an upload after retries (upload_failed), malformed answers (bad_response), or an unsafe URL from the server (unsafe_url).
8Publication failed: during uploads or complete, a 409, 410 or 422 (upload_mismatch, upload_incomplete after the retries, artifact_failed, gone, …).
9Not found: HTTP 404.

Retries and safety

  • Each file upload is retried up to 3 times (after 1, 2 and 4 s) on network errors, 429 and 5xx. 412 means already uploaded. A 403, usually an expired URL, gets a fresh URL once per file. URLs close to expiry are refreshed before use. upload_incomplete re-uploads what is missing, with at most 3 complete calls.
  • /uploads, complete and delete are retried 3 times on network errors and 502, 503 and 504, and after Retry-After (up to 60 s) on 429 rate_limited. Create is never retried, so a quota is never charged twice.
  • Credentials are sent only to the API origin. Upload URLs must be https (plain http only for a local development server), and the uploads_url and complete_url the API returns must be on its own origin. Redirects are refused.