Documentation
v1.0.0
Advanced
Authentication

Authentication & Tokens

MekongTunnel works in two modes. You pick the one that fits your workflow — no account is required for basic use.


Two modes at a glance

Free / AnonymousWith API Token
Account neededNoYes (free account)
SubdomainRandom every timeRandom, or your reserved subdomain with --subdomain
Example URLhappy-tiger-a1b2c3d4.proxy.mekongtunnel.devmyapp.proxy.mekongtunnel.dev (with --subdomain myapp)
Shows in dashboardNoYes (v1.6.16+), even with a random URL
Tunnel lifetime24 h default, max 7 daysSame limits (7-day default with --subdomain)
npm / Python SDK✔✔
VS Code extension✔✔

Both modes are free. An API token links your tunnels to your account and lets you use a reserved subdomain (Student plan and up) with --subdomain.


Getting an API token

  1. Sign in at mekongtunnel.dev (opens in a new tab)
  2. Go to Dashboard → API Tokens
  3. Click New token, give it a name, copy the value

Keep the token safe — it is shown only once.


Option 1 — mekong login (recommended)

The easiest way. Opens your browser, you approve once, and the token is saved automatically to ~/.mekong/config.json.

mekong login
  Open this URL to log in:
  https://mekongtunnel.dev/cli-auth?session=xxxx

  Waiting for authorization.....
  ✔  Logged in as you@example.com

  Saved login is now the default auth for this machine.
  Run: mekong 3000  for a random URL, or  mekong 3000 --subdomain myapp  for a reserved one
  See: mekong subdomains  for your reserved names.

From that point on, every mekong 3000 is linked to your account and shows in your dashboard, but still gets a random URL. Add --subdomain myapp to use a reserved subdomain.

mekong whoami      # show logged-in account
mekong logout      # remove saved credentials

Option 2 — --token flag

Pass your token directly on the command line:

mekong --token mkt_xxxxxxxxxxxx 3000

Option 3 — MEKONG_TOKEN environment variable

Set the token once in your shell profile and never think about it again:

export MEKONG_TOKEN=mkt_xxxxxxxxxxxx
mekong 3000

Great for CI/CD pipelines and Docker containers.


Token resolution order

The CLI checks for a token in this order, using the first one it finds:

  1. --token flag
  2. MEKONG_TOKEN environment variable
  3. ~/.mekong/config.json (written by mekong login)
  4. (none — runs anonymously)

Either way the tunnel gets a random subdomain unless you pass --subdomain.


Reserved subdomains

A reserved subdomain is tied to your account and stays the same every time you connect.

To create one:

  1. Go to Dashboard → Subdomains
  2. Click Reserve subdomain
  3. Pick a name — e.g. myapp
  4. Your tunnel URL becomes https://myapp.proxy.mekongtunnel.dev

To use it, pass the name explicitly: mekong 3000 --subdomain myapp (or -sd myapp). This requires mekong login or a token. Without --subdomain, a logged-in tunnel keeps its random name — the token only links it to your account.


Raw SSH with a token

If you use ssh directly instead of the mekong CLI, pass the token as an environment variable via SetEnv:

ssh -o SetEnv="MEKONG_API_TOKEN=mkt_xxxxxxxxxxxx" \
    -t -R 80:localhost:3000 proxy.mekongtunnel.dev

This links the tunnel to your account. Add MEKONG_SUBDOMAIN=myapp to use a reserved subdomain, and MEKONG_EXPIRE=48h if you want a specific tunnel lifetime.


npm / Node.js SDK

const mekong = require('mekong-cli/sdk')   // or: require('mekong-cli')
 
// Uses saved login token automatically
const { url, stop } = await mekong.expose(3000)
console.log('Public:', url)
 
// Or pass a token explicitly
const { url } = await mekong.expose(3000, { token: 'mkt_xxx' })
 
// Auth helpers
await mekong.login()     // browser flow — saves ~/.mekong/config.json
mekong.logout()          // remove saved token
const info = mekong.whoami()
const tok  = mekong.getToken()   // reads from env / saved config

Python SDK

import mekong_tunnel as mekong
 
# Uses saved login token automatically
tunnel = mekong.expose(8000)
print(tunnel.url)   # https://happy-tiger-a1b2c3d4.proxy.mekongtunnel.dev
tunnel.stop()
 
# Or pass a token explicitly
tunnel = mekong.expose(8000, token='mkt_xxx')
 
# Context manager
with mekong.expose(8000) as t:
    print(t.url)    # tunnel is live inside the block
 
# Auth helpers
mekong.login()      # browser flow — saves ~/.mekong/config.json
mekong.logout()     # remove saved token
info = mekong.whoami()
tok  = mekong.get_token()

VS Code extension

The extension automatically reads your token in this order:

  1. mekong.apiToken VS Code setting
  2. MEKONG_TOKEN environment variable
  3. ~/.mekong/config.json (written by mekong login)

The simplest setup: run mekong login in your terminal once, then click Start Tunnel in VS Code — it picks up your login automatically.

To set the token in settings instead: open VS Code Settings (Ctrl+,), search for mekong, and paste your token into Mekong Tunnel → API Token.


Revoking a token

Go to Dashboard → API Tokens, find the token, and click Revoke. The token stops working immediately.