cli2api

Configuration

Every environment variable.

VariableDefaultPurpose
CLI2API_PORT51222HTTP listen port
CLI2API_API_KEYS(empty)Comma-separated inbound API key allow-list; empty = no auth
CLI2API_JOBSTORE_DSN(empty = memory)libsql DSN (file:... / libsql://...?authToken=...)
CLI2API_JOB_RETENTION168hJob row retention; 0s = never expire (reaper skips sweeps)
CLI2API_REAPER_INTERVAL1hReaper sweep period; 0s = disabled
CLI2API_JOB_HARD_CAP_MULT3.0Hard-cap multiplier for in-flight jobs (force-delete past expires_at + retention × N). Range 1.0–1000.0
CLI2API_IMAGE_TIMEOUT5mMax wait for sync image/speech generation
CLI2API_POLL_INTERVAL2sInitial upstream poll cadence
CLI2API_POLL_MAX_INTERVAL10sPoll backoff ceiling
CLI2API_USAGE_DSN(empty = memory)libsql DSN for per-call usage records — see Usage endpoint.
CLI2API_USAGE_RETENTION720h (30d)Records older than this are reaped. 0s = never expire.
CLI2API_USAGE_BUFFER1024Async writer channel size.
CLI2API_LOG_LEVELinfodebug / info / warn / error
MULERUN_TOKEN(reads cache file then ~/.mulerun/)Upstream MuleRun token (muk- or JWT)
MULERUN_API_BASE_URLhttps://api.mulerun.comUpstream gateway base URL
CLI2API_TOKEN_CACHE(~/.config/mulerun/oauth_cache.json)OAuth cache path. Set to a writable file for production containers / dedicated-user systemd setups. cli2api refreshes JWTs and caches the exchanged muk- here.
CLI2API_OAUTH_TIMEOUT10sPer-call deadline for the JWT exchange + token refresh round-trips. Bounds cold-start work under k8s/PaaS readiness probes.
MULERUN_OAUTH_BASE_URLhttps://mulerun.comOAuth/platform host (cli-token + oauth2/token endpoints). Distinct from the inference gateway above.

See .env.example in the repo for a copy-paste template.

Credential discovery order

  1. MULERUN_TOKEN env var
    • muk-... → used as-is
    • eyJ... (JWT) → exchanged at startup; not cached to disk (see caveat)
  2. CLI2API_TOKEN_CACHE if set, else ~/.config/mulerun/oauth_cache.json (mulerun-cli ≥0.1.0)
    • cli2api_muk_key field → fast-path, no HTTP
    • else access_token + refresh_token → refresh if expired, exchange to muk-, persist muk- back for the next startup
  3. ~/.mulerun/{auth,credentials,token}.json (older versions)

The startup log's token_source field shows which source was used.

Env-JWT caveat: a JWT passed via MULERUN_TOKEN is re-exchanged on every restart (we don't write back to env). To benefit from disk caching, put your JWT in a file at CLI2API_TOKEN_CACHE instead.

Reaper retention semantics

  • Terminal jobs (completed / failed): deleted once expires_at passes
  • In-flight jobs (queued / in_progress): kept until expires_at + retention × CLI2API_JOB_HARD_CAP_MULT (default 3×) — gives a client time to keep polling
  • CLI2API_JOB_RETENTION=0 disables the sweep entirely — nothing is auto-deleted

On this page