Quick Start
This page walks you through your first Redact-protected request from scratch: install
Secret Guard, set up one upstream Provider and one Secret to protect (zero-config in the
WebUI, or a hand-written config file), start the gateway and send a request, then point
your Agent tool’s base_url at it for daily use.
1. Install
Section titled “1. Install”The simplest path is grabbing a binary archive directly (fully static musl builds for Linux x86_64 / ARM64) — unpack and run. You can also install from the source repository (GitHub, MIT):
# Nix (flake):nix run github:luochen1990/secret-guard -- --help# Or wire up the overlay / nixosModule into your flake and use pkgs.secret-guard directly
# Cargo (builds from source, requires rustc >= 1.96):cargo install --git https://github.com/luochen1990/secret-guard# Or after cloning the repository: cargo install --path .2. Configure
Section titled “2. Configure”Two ways to get your one-upstream-Provider + one-Secret setup in place — zero-config in the WebUI (recommended for new users), or a hand-written declarative config file.
Option B (recommended for new users) — zero-config start, set up in the WebUI
Section titled “Option B (recommended for new users) — zero-config start, set up in the WebUI”secret-guard run # no config file needed — starts empty on 127.0.0.1:8787Open http://127.0.0.1:8787/ in a browser:
- Providers tab → New provider — fill in the id,
base_url, andapi_key(unsure which protocol the URL speaks? hit Detect and it is probed and filled in for you). - Secrets tab → New secret — register the value to protect.
Entries take effect immediately (no restart) and are persisted to
secret-guard.state.toml — structurally avoiding both TOML pitfalls of Option A: the
[[secrets]] vs [[secrets.entries]] nesting trap, and the
api_key-before-[[providers.endpoints]] ordering trap.
Option A — hand-written declarative config
Section titled “Option A — hand-written declarative config”Fits version-managed setups — a plain-text file you commit and review like the rest of
your infrastructure config. Create secret-guard.toml in a directory of your choice
(one upstream Provider + one Secret to protect is all it takes):
[[providers]]id = "openai-main"kind = "direct" # direct upstream (use "router" for a routing endpoint, or "pool" for plan pools)api_key = "sk-your-upstream-key" # entry-level credential shared by all endpoints — must come BEFORE [[providers.endpoints]][[providers.endpoints]]protocol = "openai"base_url = "https://api.openai.com"
[[secrets.entries]]id = "my-github-token"value = "ghp_0123456789abcdefghijklmnopqrstuvwxyz" # the secret to protect (never sent upstream)For every config section’s fields, types, and defaults, see the Configuration Reference.
3. Start and Send the First Request
Section titled “3. Start and Send the First Request”Option A — start the gateway on an explicit port and send the first request:
secret-guard run --port 18787curl http://127.0.0.1:18787/o/openai-main/v1/chat/completions \ -H 'Content-Type: application/json' \ -d '{ "model": "gpt-4o-mini", "messages": [ { "role": "user", "content": "My token is ghp_0123456789abcdefghijklmnopqrstuvwxyz, please summarize." } ] }'(Took Option B? Your gateway is already running on 127.0.0.1:8787 — the same curl
works after swapping the port, and the provider id you picked in the WebUI.)
The Secret in the request has been replaced by an equal-length realistic Mock Secret
before reaching the upstream — the per-request log line’s redactions=1 is the replacement
count, and the LLM never sees the real value.
Open http://127.0.0.1:18787/ in a browser and check the WebUI’s Records page to see
this request from the LLM’s point of view (the Secret position is highlighted as a Mock).
See the WebUI Guide for more.
4. Daily Usage via SDKs
Section titled “4. Daily Usage via SDKs”For everyday use, simply point your Agent tool’s base_url at the gateway — no curl needed:
from openai import OpenAIclient = OpenAI( base_url="http://127.0.0.1:18787/o/openai-main/v1", api_key="ignored",)from anthropic import Anthropicclient = Anthropic( base_url="http://127.0.0.1:18787/a/openai-main", api_key="ignored", # overridden by the provider config)This example doubles as a demo of cross-protocol translation — Anthropic-form ingress is translated to the OpenAI upstream (built in).
5. Point Your Agent Harness at It
Section titled “5. Point Your Agent Harness at It”The token your harness holds is consumed by the local gateway, never by the vendor:
with auth off, any value works — the provider’s real key replaces it on the hop upstream
(keyless upstreams like Ollama pass it through — bring your own key there). With OIDC
login enabled, use a key created in the WebUI (sg_...). The real upstream key lives
only in your local Secret Guard config — the harness never holds it — Secret Guard
injects it when forwarding, so even a fully compromised harness (or a breach of its
cloud storage) never exposes your key.
opencode — custom provider via the OpenAI-compatible route, in opencode.json:
{ "$schema": "https://opencode.ai/config.json", "provider": { "secret-guard": { "npm": "@ai-sdk/openai-compatible", "name": "secret-guard (local)", "options": { "baseURL": "http://127.0.0.1:18787/o/<provider-id>/v1", "apiKey": "sg-your-gateway-key" }, "models": { "<model-id>": { "name": "<any display name>" } } } }}Model IDs come from the upstream list — the gateway passes GET /v1/models straight
through, so curl http://127.0.0.1:18787/o/<provider-id>/v1/models shows what you can
use.
claude-code — two env vars, zero config:
export ANTHROPIC_BASE_URL=http://127.0.0.1:18787/a/<provider-id>export ANTHROPIC_AUTH_TOKEN=sg-your-gateway-key # any value with auth off; a WebUI-created sg_... key with OIDC login onCross-protocol translation is built in (e.g. an OpenAI-form o route to an Anthropic
upstream, streaming included), so pick the route that matches your harness — not your
upstream.
6. URL Routing Conventions
Section titled “6. URL Routing Conventions”URLs look like /{proto_short}/{provider_id}/*rest, encoding both the ingress
protocol and the target Provider:
| proto_short | Protocol | SDK example (base_url) |
|---|---|---|
o |
OpenAI | http://127.0.0.1:18787/o/<provider-id>/v1 |
a |
Anthropic | http://127.0.0.1:18787/a/<provider-id> |
g |
Gemini | http://127.0.0.1:18787/g/<provider-id> |
l |
Ollama | http://127.0.0.1:18787/l/<provider-id> |
r |
Responses (OpenAI Responses API) | http://127.0.0.1:18787/r/<provider-id>/v1 |
Note: the URLs above are the SDK base_url form — the OpenAI SDK (Chat Completions and
Responses share one SDK) needs the /v1 prefix included; the Anthropic SDK appends
/v1/messages itself, so pointing it at /a/<provider-id> is enough; with plain curl,
write the full path (see the example above).
7. Logs and Troubleshooting
Section titled “7. Logs and Troubleshooting”Each completed forward logs a one-line INFO summary to stdout
(forward method=... path=... status=... elapsed_ms=... redactions=N provider=...),
so you can confirm traffic is flowing through Secret Guard without opening the WebUI.
Upstream failures (502/504) return an error body with a readable cause (e.g.
upstream error: http://127.0.0.1:29999 (Connection refused)). Under heavy volume,
lower the verbosity with RUST_LOG=secret_guard=warn (default info).
For a symptom-to-fix table of configuration errors, see Configuration Reference — Common Configuration Errors.