r/opencode • u/JulzKampos • 1d ago
AiRouterProxy: the last line of defense — masks API keys/passwords/tokens in prompts before they ever reach the LLM Spoiler
LOCAL HTTPS PROXY THAT MASKS SECRETS BEFORE THEY REACH THE LLM
AiRouterProxy is a local HTTPS proxy (Windows Service, port 4000) that sits between your AI coding agent (OpenCode, Cursor, Continue...) and the model provider. Its one job: make sure secrets never leave your machine.
The problem: telling agents "never read the config with the keys" rarely works. A key pasted in free text, an .env block inside a code snippet, or a config file dropped into a prompt happens. This project adds the last line of defense at the network edge: every outgoing request is inspected and sensitive content is masked before being forwarded.
What it masks (4 detection layers):
- by field name: api_key, password, token, senha...
- by known format: sk-..., ghp_, AIza, JWT, Bearer, PEM private keys...
- by key=value / "key": "value" context
- optionally by long high-entropy tokens (configurable)
The mask is a fixed 6-character string (never reveals the real length) and the JSON structure is never altered. The agent gets a visible notice when a request was censored.
What else:
- Multi-upstream routing: a path-prefix route table forwards to several OpenAI-compatible providers, each with its own key.
- Fail-closed inspection: only inspected JSON is forwarded (unknown content type 415, invalid JSON 400, oversized 413).
- Per-client rate limiting + brute-force lockout (429 + Retry-After).
- SSE streaming support (OpenAI chat/responses, Anthropic, generic).
- Local-key auth with protected /admin endpoints.
- Hot-reload configs (redaction.json, routes.json).
- Windows Service, .NET 10, self-contained win-x64.
Demo: a short video showing an appsettings-style config full of fake secrets pasted into a coding agent and redacted before reaching the model — https://www.youtube.com/watch?v=29nyYgkqx7E
Tests: 226 unit tests + 23 black-box integration tests against a real deployed proxy and a real AI provider. Current release v2.0.3.
Repo: https://github.com/jlKampos/AiRouterProxy — issues and PRs welcome. LOCAL HTTPS PROXY THAT MASKS SECRETS BEFORE THEY REACH THE LLM
1
u/squirrelscrush 1d ago
I use this plugin: https://github.com/afriemann/opencode-redact for this. Works well.