Skip to content
Browse the docs
reference

CLI Reference

Complete reference for all zgrok commands, flags, and options

Every subcommand, flag, type, and default the zgrok CLI supports.

Commands

zgrok http [PORT]

Start an HTTP tunnel. PORT is optional if default_port is set in config.

FlagTypeDefaultDescription
PORTinteger (positional)default_port from configLocal port to forward
-d, --subdomain <NAME>stringrandom nameCustom tunnel name inside your project, e.g. api for api--acme-shop.zgrok.io (PRO plan)
--project <SLUG>stringthe active project from your config; with none set, a picker when there is a terminal and several projects, otherwise your organization's default projectProject to open the tunnel in, for this run only
-s, --server <ADDR>stringrelay.zgrok.io:4433Relay server address
-a, --api-key <KEY>stringresolved via API key resolutionYour zgrok API key
--header <NAME: VALUE>string, repeatablenoneInject a custom response header; repeat the flag for more than one
--allow-ip <LIST>comma-separated IPs/CIDRsnoneIP allowlist (PRO only)
--no-logboolean flagfalseDisable the terminal request log
--qrboolean flagfalsePrint a QR code for the tunnel URL
--no-inspectboolean flagfalseDisable the local request inspector
--inspect-port <PORT>integer4040 (or inspect_port from config)Port for the local inspector; conflicts with --no-inspect
--log-jsonboolean flagfalseWrite one JSON object per request to stdout
--log-file <PATH>pathnoneAppend one JSON object per request to a file
--skip-update-checkboolean flagfalseIgnore update information, so a required update does not stop the tunnel
-v, --verboseboolean flagfalsePrint diagnostic output (see Verbose output)
bash
zgrok http 8080 --subdomain myapi --header "Access-Control-Allow-Origin: *"

zgrok ai [PORT]

Tunnel a local AI model: Ollama, LM Studio, or any OpenAI-compatible server. Authenticated by default, with no first-byte timeout on long completions. See the Local AI guide.

FlagTypeDefaultDescription
PORTinteger (positional)11434 (Ollama)Local port to forward
--token <TOKEN>stringauto-generated zg_ai_…Bearer token clients must send as Authorization: Bearer <token>
-d, --subdomain <NAME>stringrandom nameCustom, stable tunnel name inside your project (PRO plan)
--project <SLUG>stringthe active project from your config; with none set, a picker when there is a terminal and several projects, otherwise your organization's default projectProject to open the tunnel in, for this run only
-s, --server <ADDR>stringrelay.zgrok.io:4433Relay server address
-a, --api-key <KEY>stringresolved via API key resolutionYour zgrok API key
--no-logboolean flagfalseDisable the terminal request log
--qrboolean flagfalsePrint a QR code for the tunnel URL
--no-inspectboolean flagfalseDisable the local request inspector
--inspect-port <PORT>integer4040 (or inspect_port from config)Port for the local inspector; conflicts with --no-inspect
--log-jsonboolean flagfalseWrite one JSON object per request to stdout
--log-file <PATH>pathnoneAppend one JSON object per request to a file
--skip-update-checkboolean flagfalseIgnore update information, so a required update does not stop the tunnel
-v, --verboseboolean flagfalsePrint diagnostic output (see Verbose output)
bash
zgrok ai 1234 --token my-long-secret-token --subdomain my-llm --qr

zgrok ai does not accept --header or --allow-ip. Every AI tunnel is already gated by its bearer token at the edge.

zgrok login

Sign this machine in through your browser. The CLI prints a code, waits for you to approve it, and saves a new API key to ~/.zgrok/config.yaml. If the file already holds a key, it is replaced, and the CLI says so.

FlagTypeDefaultDescription
--no-browserboolean flagfalsePrint the URL and code without opening a browser

The browser also stays closed over SSH and on Linux with no display. The URL and code are printed in every case, so you can approve from any device.

bash
zgrok login
zgrok login --no-browser

zgrok config add-authtoken TOKEN

Save an API key you already have to ~/.zgrok/config.yaml, for a machine where nobody can approve in a browser. Everywhere else, zgrok login is simpler.

bash
zgrok config add-authtoken zk_abc123def456

zgrok update

Download and install the latest release, replacing the running binary in place.

bash
zgrok update

You do not have to remember to check. When a tunnel connects, the server says whether a newer version exists and the CLI prints it once. A release marked as required stops the tunnel until you update.

zgrok --version / -V

Print the installed version.

zgrok --help / -h

Print help. Also available per-subcommand: zgrok http --help, zgrok ai --help, zgrok config --help.

Verbose output

-v (or --verbose) turns on diagnostic output. It works on every command, before or after the subcommand:

bash
zgrok -v http 3000
zgrok http 3000 -v

Without it, zgrok prints only the interface: the banner, the request log, and its own messages. There is no hidden log file and nothing is written anywhere else, so if something goes wrong and you want to tell us what happened, -v is what to send:

bash
zgrok http 3000 -v 2> zgrok.log

Everything zgrok prints goes to stderr, so a single 2> captures the whole session. Verbose adds the QUIC and TLS handshake detail underneath. That is enough to diagnose a connection that will not establish, and deliberately short of the level that would dump request contents.

RUST_LOG overrides -v when it is set, and is applied exactly as written.

API key resolution

zgrok looks for an API key in this order, for both http and ai:

  1. --api-key / -a CLI flag
  2. ZGROK_API_KEY environment variable
  3. api_key in ~/.zgrok/config.yaml

If none is found, the CLI exits with an error explaining all three options.

Examples

bash
# Basic tunnel
zgrok http 3000
 
# Custom tunnel name (myapi--<project>.zgrok.io) + CORS headers
zgrok http 8080 --subdomain myapi --header "Access-Control-Allow-Origin: *"
 
# Restricted access with QR code
zgrok http 3000 --allow-ip 203.0.113.0/24 --qr
 
# Quiet mode (no request logs)
zgrok http 3000 --no-log
 
# Move the inspector off the default port
zgrok http 3000 --inspect-port 4100
 
# No web UI, just a machine-readable record per request
zgrok http 3000 --no-inspect --log-json | jq --unbuffered 'select(.status >= 500)'
 
# Using environment variable
ZGROK_API_KEY=zk_abc123 zgrok http 3000
 
# Tunnel a local Ollama instance with a stable token
zgrok ai --token my-long-secret-token
 
# Sign in once, then omit --api-key from every future command
zgrok login

See also