tokensaver-egress
████████╗ ██████╗ ██╗ ██╗███████╗███╗ ██╗███████╗ █████╗ ██╗ ██╗███████╗██████╗
╚══██╔══╝██╔═══██╗██║ ██╔╝██╔════╝████╗ ██║██╔════╝██╔══██╗██║ ██║██╔════╝██╔══██╗
██║ ██║ ██║█████╔╝ █████╗ ██╔██╗ ██║███████╗███████║██║ ██║█████╗ ██████╔╝
██║ ██║ ██║██╔═██╗ ██╔══╝ ██║╚██╗██║╚════██║██╔══██║╚██╗ ██╔╝██╔══╝ ██╔══██╗
██║ ╚██████╔╝██║ ██╗███████╗██║ ╚████║███████║██║ ██║ ╚████╔╝ ███████╗██║ ██║
╚═╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝╚═╝ ╚═══╝╚══════╝╚═╝ ╚═╝ ╚═══╝ ╚══════╝╚═╝ ╚═╝
┌─────────────────────────────────────────────────────────────┐
│ EGRESS · capture · MITM · compress · govern │
│ Claude Code · Cursor · n8n · agents · HTTPS proxy │
└─────────────────────────────────────────────────────────────┘
Capture HTTPS traffic from your AI agents (Claude Code, Cursor, n8n, …) and send audits to TokenSaver → Flux IA.
Same TOKENSAVER ASCII wordmark as the tokensaver CLI — shown when you run tokensaver-egress serve / setup (disable with TOKENSAVER_NO_BANNER=1).
Your agent ──HTTPS──► tokensaver-egress ──► api.anthropic.com / …
│
└── audits ──► api.tokensaver.cloud → Flux IA
Quick start
Once — install and configure:
pip install -U tokensaver-egress
tokensaver-egress setup
Option A — one shell (simplest)
tokensaver-egress claude # Claude Code CLI
# or
tokensaver-egress vscode # VS Code (Claude Code extension) — proxy stays up
# or
tokensaver-egress launch # client chosen during setup
claude starts the proxy if needed, then launches Claude Code. When Claude exits, the auto-proxy stops (unless you used --keep-proxy).
vscode opens VS Code or Cursor (PATH, .app bundle, or open -a) and leaves the proxy running. Stop later with tokensaver-egress stop.
Option B — two shells (see proxy logs)
# Terminal 1 — egress (logs stay visible here)
tokensaver-egress serve
# Terminal 2 — Claude through that proxy
tokensaver-egress claude --no-start
That’s it. Open app.tokensaver.cloud → Flux IA to see traffic.
| Stop | How |
|---|---|
| One-shell auto-proxy | Claude exits, or tokensaver-egress stop (also clears IDE env) |
| Two-shell proxy | Ctrl+C in terminal 1, then tokensaver-egress stop (or unproxy --ide) |
Shell still pointing at :8888 |
eval "$(tokensaver-egress unproxy --sh)" |
Requires Python ≥ 3.10. The wizard asks for a TokenSaver account or a tsv_… virtual key.
What setup configures
Interactive wizard (tokensaver-egress setup):
| Step | Choices |
|---|---|
| Virtual key | Create account · Log in (email/password) · Paste tsv_… · Open console |
| Platform | SaaS (api.tokensaver.cloud) or Local (localhost:8000) |
| Then | Ingest URL · MITM CA · body capture · port · Claude skills · CLI vs VS Code |
Config is written to ~/.tokensaver-egress/env (+ client-env.sh). Setup also persists proxy env in:
~/.claude/settings.jsonenv(Claude Code CLI — skipped if TokenSaver routeANTHROPIC_BASE_URLis set)- VS Code / Cursor
claudeCode.environmentVariables(when you pick VS Code / both) - optional guarded snippet in
~/.zshrc(loadsclient-env.shonly while the proxy port is listening)
Re-apply without the wizard: tokensaver-egress ide. Strip IDE snippets: tokensaver-egress unproxy --ide.
Log in (existing account): choose option 2 → SaaS/Local → email + password → a key labeled Egress CLI is created and saved. Prefer Paste if you already have a key. SSO-only orgs: paste after IdP login. Details: Account options.
Other ways to run
| Goal | Commands |
|---|---|
| One shell | tokensaver-egress claude |
| VS Code | tokensaver-egress vscode (or launch after setup) |
| Two shells — logs + Claude | serve then claude --no-start |
| Any command through the proxy | tokensaver-egress run -- curl -I https://api.anthropic.com |
| Leave auto-proxy up after Claude exits | claude --keep-proxy → later tokensaver-egress stop |
tokensaver-egress stop # kills :8888 + clears Claude / VS Code / shell proxy env
# Other terminals that still exported HTTPS_PROXY:
eval "$(tokensaver-egress unproxy --sh)"
Account options (API key)
| # | Option | Who | What happens |
|---|---|---|---|
| 1 | Create a free account | New users | Signup + key returned once |
| 2 | Log in (default) | Existing email/password | Sign-in → create key Egress CLI |
| 3 | Paste an existing virtual key | CI / SSO / reuse a key | You paste tsv_… from Console → Clés virtuelles |
| 4 | Open the console | Browser | https://app.tokensaver.cloud |
tokensaver-egress setup
→ Keep this key? n # when replacing an old key
→ 2) Log in …
→ 1) TokenSaver SaaS
→ email + password
→ key saved in ~/.tokensaver-egress/env
Notes:
- Login creates a new API key each time (plan key quota). Prefer paste to reuse a key.
- Email must be verified to create keys via login.
- SSO-only orgs: use paste after IdP login — not email/password.
TOKENSAVER_ENTERPRISE=1/TOKENSAVER_ORG_HINT=<slug>hide create account.
Architecture (client only)
tokensaver-egress is a lightweight client-side HTTPS proxy. It does not embed TokenSaver business logic, databases, or admin console.
| Runs locally (this package) | Runs on TokenSaver SaaS (app.tokensaver.cloud) |
|---|---|
| Listen / MITM / forward HTTPS | Ingest, Flux IA, storage |
| Optional body capture (auth headers masked) | Governance policies (cache, RAG, compression, PII, routing) |
Ship audits + call policy APIs with your tsv_… virtual key |
Catalogue enforce, quotas, dashboards |
Default ingest: https://api.tokensaver.cloud/api/v1/egress/ingest.
How it works (principles)
- Runs next to the agent, not in the cloud — laptop, CI, or pod. SaaS never terminates your LLM TLS for you.
- Traffic still goes to the real provider — Anthropic / OpenAI remain the destination. Unset
HTTPS_PROXYand tools talk to providers directly again. - Metadata first — bodies off by default (
EGRESS_CAPTURE_BODIESto opt in). Auth headers masked when bodies are captured. - Visibility levels — explicit
HTTPS_PROXY· MITM (local CA) · transparent (Linux, advanced). - SaaS decides policy — the proxy fetches effective settings for your key.
- Streaming stays interactive — no “buffer everything then reply” for normal chat.
- Fail soft by default — brief SaaS outages usually don’t block forward.
- Your key is the trust boundary — without a valid
TOKENSAVER_API_KEY, Flux IA stays empty.
Everyday commands
| Command | What it does |
|---|---|
tokensaver-egress |
Interactive menu (TTY) or help |
tokensaver-egress setup |
Guided setup (API key, CA, skills, options) |
tokensaver-egress serve |
Start proxy in foreground (logs here) |
tokensaver-egress claude --no-start |
Claude CLI using an already-running serve |
tokensaver-egress claude |
Auto-start proxy + Claude CLI (one terminal) |
tokensaver-egress vscode |
Auto-start proxy + VS Code (proxy stays up) |
tokensaver-egress launch |
Launch the client chosen in setup (claude / vscode / both) |
tokensaver-egress ide |
Write Claude / VS Code / shell proxy settings without launching |
tokensaver-egress claude --keep-proxy |
Auto-start proxy, leave it up after Claude exits |
tokensaver-egress run -- CMD |
Same for any command |
tokensaver-egress stop |
Stop proxy and clear HTTPS_PROXY / Claude / VS Code / shell snippets (--keep-env = process only) |
tokensaver-egress install-skills |
Install Claude skills → ~/.claude/skills/tokensaver-router |
tokensaver-egress unproxy |
Clear HTTPS_PROXY / HTTP_PROXY in this shell (--ide = same IDE cleanup as stop) |
tokensaver-egress init-ca |
(Re)generate the MITM CA |
Ctrl+C |
Stop serve |
If the port is busy: tokensaver-egress serve --port 8889 (and update HTTPS_PROXY), or tokensaver-egress stop.
Claude Code skills
tokensaver-egress install-skills
# or: tokensaver-egress install-skills --force
Installs CCR / onboarding / MCP helpers. Restart Claude Code after install.
After Claude / Ctrl+C — clear proxy env
tokensaver-egress stop kills the process and strips persisted proxy env (Claude settings.json, VS Code, shell rc snippets, client-env.sh). Other interactive shells that already exported HTTPS_PROXY still need a local unset:
| Layer | Clear with |
|---|---|
| Process + IDE / Claude settings | tokensaver-egress stop |
HTTPS_PROXY in another shell |
eval "$(tokensaver-egress unproxy --sh)" |
| Process only (keep IDE env) | tokensaver-egress stop --keep-env |
tokensaver-egress stop
# then restart Claude Code / reload the IDE window
5-minute setup (manual MITM)
MITM can see model, tokens, and tool names. Trust a local CA once.
1. Configure TokenSaver
export TOKENSAVER_API_KEY=tsv_your_virtual_key_here
export TOKENSAVER_INGEST_URL=https://api.tokensaver.cloud/api/v1/egress/ingest
2. Create the local CA (once)
tokensaver-egress init-ca
# Writes: ~/.tokensaver-egress/ca/ca.crt
Trust that CA on this Mac, then tell Node (Claude Code) to use it:
sudo security add-trusted-cert -d -r trustRoot \
-k /Library/Keychains/System.keychain \
"$HOME/.tokensaver-egress/ca/ca.crt"
export NODE_EXTRA_CA_CERTS="$HOME/.tokensaver-egress/ca/ca.crt"
3. Terminal 1 — start the proxy
EGRESS_MITM_ENABLED=true tokensaver-egress serve --port 8888
4. Terminal 2 — point tools at the proxy
export HTTPS_PROXY=http://127.0.0.1:8888
export HTTP_PROXY=http://127.0.0.1:8888
export NODE_EXTRA_CA_CERTS="$HOME/.tokensaver-egress/ca/ca.crt"
claude
# or: tokensaver-egress claude --no-start
5. Check Flux IA
app.tokensaver.cloud → Flux IA — new calls should appear within seconds.
Examples
A. Claude Code (full capture)
# Terminal A — proxy
export TOKENSAVER_API_KEY=tsv_…
export TOKENSAVER_INGEST_URL=https://api.tokensaver.cloud/api/v1/egress/ingest
EGRESS_MITM_ENABLED=true EGRESS_CAPTURE_BODIES=1 \
tokensaver-egress serve --port 8888
# Terminal B — agent
export HTTPS_PROXY=http://127.0.0.1:8888
export HTTP_PROXY=http://127.0.0.1:8888
export NODE_EXTRA_CA_CERTS="$HOME/.tokensaver-egress/ca/ca.crt"
claude
EGRESS_CAPTURE_BODIES=1 stores request/response bodies in TokenSaver (auth headers are masked). Omit it if you only want metadata (host, latency, tokens).
A′. Audit-only (journalisation seule — TNF bisection)
Forward the client body unchanged to Anthropic (no cache / RAG / compression / PII / routing), while still ingesting audit rows. Use this for the « without TokenSaver transforms » leg of a thread_not_found bisection:
EGRESS_MITM_ENABLED=true EGRESS_CAPTURE_BODIES=1 EGRESS_AUDIT_ONLY=1 \
tokensaver-egress serve --port 8888
(EGRESS_PIPELINE_MODE=audit is an alias.) Audit attrs include audit_only=true and pipeline_modules=["audit_only"].
B. One-shot curl through the proxy
# Proxy already running with MITM + CA trusted
export HTTPS_PROXY=http://127.0.0.1:8888
curl -sS https://api.anthropic.com/v1/messages \
-H "x-api-key: $ANTHROPIC_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{"model":"claude-haiku-4-5-20251001","max_tokens":32,"messages":[{"role":"user","content":"ping"}]}'
C. Metadata only (no TLS decrypt)
No CA trust needed. You still see host / bytes / latency, not model tokens.
export TOKENSAVER_API_KEY=tsv_…
export TOKENSAVER_INGEST_URL=https://api.tokensaver.cloud/api/v1/egress/ingest
tokensaver-egress serve --port 8888
# Client
export HTTPS_PROXY=http://127.0.0.1:8888
export HTTP_PROXY=http://127.0.0.1:8888
D. Local TokenSaver backend (dev)
export TOKENSAVER_API_KEY=tsv_…
export TOKENSAVER_INGEST_URL=http://localhost:8000/api/v1/egress/ingest
EGRESS_MITM_ENABLED=true tokensaver-egress serve --port 8888
Modes (simple)
| Mode | How you enable it | What you get |
|---|---|---|
| Explicit | HTTPS_PROXY → proxy |
Host, size, latency |
| MITM | + EGRESS_MITM_ENABLED=true + trusted CA |
Model, tokens, tools, optional bodies |
| Transparent | Linux TPROXY (advanced) | No proxy env on the client; metadata only |
Most people want MITM + explicit proxy (sections above).
Mental model: explicit = “I opted this shell in”; MITM = “I also trust a local cert so TokenSaver can enrich the audit”; transparent = “the network forces traffic through the proxy” (ops / lock-down setups).
Transparent (Linux only):
sudo EGRESS_PORT=8888 ./scripts/tproxy-setup.sh up
tokensaver-egress serve --transparent --port 8888
Useful environment variables
| Variable | Meaning |
|---|---|
TOKENSAVER_API_KEY |
Your tsv_… virtual key (required to ship audits) |
TOKENSAVER_INGEST_URL |
SaaS default: https://api.tokensaver.cloud/api/v1/egress/ingest |
TOKENSAVER_CONTROL_URL |
SaaS default: https://control.tokensaver.cloud (auth, loops, agentic-events) |
EGRESS_MITM_ENABLED |
true = decrypt known LLM hosts |
EGRESS_CAPTURE_BODIES |
1 = store bodies in Flux IA |
EGRESS_ENFORCE_ENABLED |
1 = block non-approved catalogue assets |
TOKENSAVER_NO_BANNER |
1 = hide the ASCII logo |
NODE_EXTRA_CA_CERTS |
Path to ca.crt for Node / Claude Code |
Troubleshooting
| Symptom | Fix |
|---|---|
pip install → Connection refused to localhost:8888 / “No matching distribution” |
Regression footgun: shell still has HTTPS_PROXY after Claude quit (and/or proxy was left with --keep-proxy then died). Run tokensaver-egress stop (clears IDE too); in that shell also eval "$(tokensaver-egress unproxy --sh)", retry with --no-cache-dir. Prefer day-to-day claude without --keep-proxy and without sourcing client-env.sh. |
Claude / VS Code 403 … deny (LOOP_TERMINAL) |
Stale Boucle stamp. Now: 0.1.49+ auto-clears and allows. Until then: tokensaver-egress stop; delete ~/.tokensaver-egress/current-loop.env; tokensaver-egress serve (or vscode). |
loop status / Flux shows traffic but Boucle stuck |
Prefer day-to-day without --loop. Skills manage Boucles via MCP when needed. If stuck: stop, delete current-loop.env, new serve. |
pip install -U stays on an old version |
pip install -U --no-cache-dir tokensaver-egress (after unproxy if needed) |
| TTFT empty on dashboard (egress) | Upgrade to 0.1.18+ and generate new LLM calls — TTFT is attrs.ttft_ms (first body byte after the provider request). Older audits lack the field. With OBSERVABILITY_CLICKHOUSE_READ, confirm clickhouse_summary.py extracts TTFT quantiles (not hardcoded sample_count: 0). |
| Overview Performance / compression blocks / Prompt cache empty (CH READ on) | Ensure worker-observability runs arq (not Uvicorn), dual-write includes payload_json.attrs, and summary maps TTFT / compression.blocks / cache_read_input_tokens — see platform docs ARCHITECTURE-OBSERVABILITY-STORES.md §3.2bis. |
| Smart Cache 0% but Anthropic shows millions of cache tokens | Expected: Smart Cache = TokenSaver semantic hit (no LLM). Prompt cache = provider cache_read_input_tokens (LLM still runs). Token Flow shows a separate Prompt cache node when read > 0. |
TLS / certificate errors in Claude Code (CERT_SIGNATURE_FAILURE) |
Usually stale leaf certs after CA recreate: restart serve (0.1.17+ auto-purges). Or rm -rf ~/.tokensaver-egress/ca/leaves. Also use tokensaver-egress claude --no-start (sets NODE_EXTRA_CA_CERTS) — not bare claude with only HTTPS_PROXY. |
| Nothing in Flux IA | Check TOKENSAVER_API_KEY + TOKENSAVER_INGEST_URL; watch proxy logs |
| Login / signup fails with SSO message | Org requires IdP — open the console via SSO, create a key, paste it (option 3) |
| Login OK but “email not verified” | Verify email in the console, then retry login or paste a key |
| Login OK but “API key quota reached” | Delete an unused key in Settings → API keys, or paste an existing key |
| Port already in use | tokensaver-egress stop / free :8888, or serve --port 8889 (update HTTPS_PROXY) |
| Want quieter startup | TOKENSAVER_NO_BANNER=1 tokensaver-egress serve |
Boucle ends with verification_failed / METRIC_MISSING while Claude says Goal achieved |
Skills must end with work_complete for file labs (not goal_met without metrics). Reinstall: tokensaver-egress install-skills --force. See console Developer workspace alerts + Flux IA. |
| FinOps projet $ OK but 100 % orphelins (no capability) | Expected without ADR-010 stamps — product features Claude listed ≠ FinOps capability. Need SpecRef / feat-* / catalog import. |
| FinOps / Complet missing LLM $ for a Claude session | Upgrade to ≥ 0.1.54, restart proxy so MITM stamps claude_session_id. Platform joins egress via session (+ aliases / time window). |
| Projets badge incomplet | Seq gaps in agentic capture — graph may still render; bench blocked until capture is contiguous. |
Security
- Run MITM only on machines you control. The CA can decrypt traffic you route through the proxy.
HTTPS_PROXYis easy to unset — it is not a hard security boundary. For lock-down, seek8s/networkpolicy.example.yaml/ transparent mode.- Bodies are optional; auth headers are masked unless you opt into raw headers.
Related
| Package | Role |
|---|---|
tokensaver-cli |
Route Claude Code / Cursor through TokenSaver APIs |
tokensaver-sdk |
Python SDK |
| TokenSaver platform | Control plane — Flux IA, Developer workspace (Boucles / costs / alerts), policies, keys |
License
MIT © TokenSaver
Metadata
Release files for tokensaver-egress 0.1.65
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| tokensaver_egress-0.1.65.tar.gz | 165.3 kB | Without provenance | Details for tokensaver_egress-0.1.65.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| tokensaver_egress-0.1.65-py3-none-any.whl | Python 3 | none | any | Details for tokensaver_egress-0.1.65-py3-none-any.whl |
Total release size: 326.3 kB
Release files / tokensaver_egress-0.1.65.tar.gz
| Download URL | tokensaver_egress-0.1.65.tar.gz |
|---|---|
| Size | 165.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4b58ae8fb088b73341f45fde23a33df094b608083062fa8ddfbd1e67dd666cf5
|
|
BLAKE2b-256 checksum How to use checksums |
591d97f886c38d16f0b4abf28a6f9ed14c35f948fefd830aec702c641c0386fd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.18
|
Release files / tokensaver_egress-0.1.65-py3-none-any.whl
| Download URL | tokensaver_egress-0.1.65-py3-none-any.whl |
|---|---|
| Size | 160.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b7a728c9d9ccd9fcb54cbeaf0983713d61e391c3a237c9b279a0587e985edc55
|
|
BLAKE2b-256 checksum How to use checksums |
d50ce5585a78a28fc342bd603c572dfa426ff6d988f652aee9ebb4a4ce9481f7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.18
|
Security for tokensaver-egress 0.1.65
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.