prefixwise 0.3.0__tar.gz → 0.4.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {prefixwise-0.3.0 → prefixwise-0.4.0}/.gitignore +1 -0
- prefixwise-0.4.0/CHANGELOG.md +86 -0
- {prefixwise-0.3.0 → prefixwise-0.4.0}/PKG-INFO +88 -11
- {prefixwise-0.3.0 → prefixwise-0.4.0}/README.md +80 -9
- prefixwise-0.4.0/benchmarks/README.md +35 -0
- prefixwise-0.4.0/docs/API.md +82 -0
- prefixwise-0.4.0/docs/DATA.md +103 -0
- prefixwise-0.4.0/docs/ENGINES.md +125 -0
- {prefixwise-0.3.0 → prefixwise-0.4.0}/docs/USE_CASES.md +2 -2
- prefixwise-0.4.0/docs/VLLM.md +81 -0
- prefixwise-0.4.0/experiments/compat/2026-11-07.md +37 -0
- prefixwise-0.4.0/experiments/dogfood/2026-11-07-opencode-2.md +26 -0
- {prefixwise-0.3.0 → prefixwise-0.4.0}/experiments/e1_hosted/e1_hosted.py +16 -8
- prefixwise-0.4.0/experiments/e1_hosted/runs/2026-11-07-anthropic-lanes.md +23 -0
- {prefixwise-0.3.0 → prefixwise-0.4.0}/experiments/e1_open/e1_open.py +56 -25
- prefixwise-0.4.0/experiments/e1_open/runs/2026-11-07-lanes.md +25 -0
- prefixwise-0.4.0/experiments/e1_open/sglang_server.sh +38 -0
- prefixwise-0.4.0/experiments/e1_open/vllm_lmcache_server.sh +54 -0
- {prefixwise-0.3.0 → prefixwise-0.4.0}/experiments/e1_open/vllm_server.sh +5 -2
- prefixwise-0.4.0/experiments/e_evict/README.md +75 -0
- prefixwise-0.4.0/experiments/e_evict/e_evict.py +194 -0
- prefixwise-0.4.0/experiments/e_evict/runs/2026-11-07-colab-l4.md +38 -0
- {prefixwise-0.3.0 → prefixwise-0.4.0}/pyproject.toml +5 -3
- {prefixwise-0.3.0 → prefixwise-0.4.0}/src/prefixwise/__init__.py +1 -1
- prefixwise-0.4.0/src/prefixwise/api.py +168 -0
- {prefixwise-0.3.0 → prefixwise-0.4.0}/src/prefixwise/classifier.py +89 -7
- {prefixwise-0.3.0 → prefixwise-0.4.0}/src/prefixwise/cli.py +265 -32
- prefixwise-0.4.0/src/prefixwise/engines.py +280 -0
- {prefixwise-0.3.0 → prefixwise-0.4.0}/src/prefixwise/explain.py +6 -25
- prefixwise-0.4.0/src/prefixwise/findings.py +145 -0
- {prefixwise-0.3.0 → prefixwise-0.4.0}/src/prefixwise/fingerprint.py +25 -3
- {prefixwise-0.3.0 → prefixwise-0.4.0}/src/prefixwise/fixes.py +29 -0
- {prefixwise-0.3.0 → prefixwise-0.4.0}/src/prefixwise/ledger.py +119 -103
- prefixwise-0.4.0/src/prefixwise/metrics.py +227 -0
- prefixwise-0.4.0/src/prefixwise/prices.json +92 -0
- {prefixwise-0.3.0 → prefixwise-0.4.0}/src/prefixwise/pricing.py +19 -10
- {prefixwise-0.3.0 → prefixwise-0.4.0}/src/prefixwise/proxy.py +316 -37
- prefixwise-0.4.0/tests/test_api.py +92 -0
- {prefixwise-0.3.0 → prefixwise-0.4.0}/tests/test_classifier.py +34 -2
- {prefixwise-0.3.0 → prefixwise-0.4.0}/tests/test_cli.py +17 -0
- prefixwise-0.4.0/tests/test_compat.py +87 -0
- prefixwise-0.4.0/tests/test_data.py +184 -0
- {prefixwise-0.3.0 → prefixwise-0.4.0}/tests/test_e1_open.py +2 -2
- prefixwise-0.4.0/tests/test_engine_join.py +299 -0
- prefixwise-0.4.0/tests/test_engines.py +49 -0
- prefixwise-0.4.0/tests/test_lanes.py +67 -0
- {prefixwise-0.3.0 → prefixwise-0.4.0}/tests/test_pricing.py +28 -4
- prefixwise-0.4.0/tests/test_production.py +244 -0
- {prefixwise-0.3.0 → prefixwise-0.4.0}/tests/test_proxy.py +6 -3
- {prefixwise-0.3.0 → prefixwise-0.4.0}/tests/test_routing.py +2 -1
- prefixwise-0.4.0/tests/test_run.py +231 -0
- prefixwise-0.3.0/CHANGELOG.md +0 -31
- prefixwise-0.3.0/src/prefixwise/prices.json +0 -61
- {prefixwise-0.3.0 → prefixwise-0.4.0}/LICENSE +0 -0
- {prefixwise-0.3.0 → prefixwise-0.4.0}/SECURITY.md +0 -0
- {prefixwise-0.3.0 → prefixwise-0.4.0}/examples/openai_agent.py +0 -0
- {prefixwise-0.3.0 → prefixwise-0.4.0}/examples/session.jsonl +0 -0
- {prefixwise-0.3.0 → prefixwise-0.4.0}/examples/turn1.json +0 -0
- {prefixwise-0.3.0 → prefixwise-0.4.0}/examples/turn2.json +0 -0
- {prefixwise-0.3.0 → prefixwise-0.4.0}/experiments/dogfood/2026-11-06-opencode.md +0 -0
- {prefixwise-0.3.0 → prefixwise-0.4.0}/experiments/e1_hosted/README.md +0 -0
- {prefixwise-0.3.0 → prefixwise-0.4.0}/experiments/e1_hosted/runs/2026-11-06-anthropic-claude-haiku-5-5.md +0 -0
- {prefixwise-0.3.0 → prefixwise-0.4.0}/experiments/e1_hosted/runs/2026-11-06-openai-probes-round3.md +0 -0
- {prefixwise-0.3.0 → prefixwise-0.4.0}/experiments/e1_hosted/runs/2026-11-06-probes.md +0 -0
- {prefixwise-0.3.0 → prefixwise-0.4.0}/experiments/e1_hosted/runs/2026-11-06-round4.md +0 -0
- {prefixwise-0.3.0 → prefixwise-0.4.0}/experiments/e1_open/README.md +0 -0
- {prefixwise-0.3.0 → prefixwise-0.4.0}/experiments/e1_open/colab_e1_open.ipynb +0 -0
- {prefixwise-0.3.0 → prefixwise-0.4.0}/experiments/e1_open/runs/2026-11-06-colab-l4-qwen3-4b.json +0 -0
- {prefixwise-0.3.0 → prefixwise-0.4.0}/experiments/e1_open/runs/2026-11-06-colab-l4-qwen3-4b.md +0 -0
- {prefixwise-0.3.0 → prefixwise-0.4.0}/experiments/e4/README.md +0 -0
- {prefixwise-0.3.0 → prefixwise-0.4.0}/experiments/e4/e4.py +0 -0
- {prefixwise-0.3.0 → prefixwise-0.4.0}/experiments/e4/runs/2026-11-06-live.md +0 -0
- {prefixwise-0.3.0 → prefixwise-0.4.0}/experiments/e4/sessions/tool-order-drift.jsonl +0 -0
- {prefixwise-0.3.0 → prefixwise-0.4.0}/src/prefixwise/__main__.py +0 -0
- {prefixwise-0.3.0 → prefixwise-0.4.0}/src/prefixwise/diagnostics.py +0 -0
- {prefixwise-0.3.0 → prefixwise-0.4.0}/tests/test_diagnostics.py +0 -0
- {prefixwise-0.3.0 → prefixwise-0.4.0}/tests/test_e1_hosted.py +0 -0
- {prefixwise-0.3.0 → prefixwise-0.4.0}/tests/test_e4.py +0 -0
- {prefixwise-0.3.0 → prefixwise-0.4.0}/tests/test_examples.py +0 -0
- {prefixwise-0.3.0 → prefixwise-0.4.0}/tests/test_fingerprint.py +0 -0
- {prefixwise-0.3.0 → prefixwise-0.4.0}/tests/test_fixes.py +0 -0
- {prefixwise-0.3.0 → prefixwise-0.4.0}/tests/test_ledger.py +0 -0
- {prefixwise-0.3.0 → prefixwise-0.4.0}/tests/test_security.py +0 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.4.0: 2026-11-07
|
|
4
|
+
|
|
5
|
+
`prefixwise run`, a report that says what to do, every metric as data (API and export), and
|
|
6
|
+
self-hosted engines (vLLM, SGLang, LMCache) validated live.
|
|
7
|
+
|
|
8
|
+
**Python 3.10 is now supported** (the test suite passes on 3.10 to 3.13); vLLM users on 3.10 can install it.
|
|
9
|
+
|
|
10
|
+
**Upgrading:**
|
|
11
|
+
- Existing ledgers migrate in place (schema 3); old rows count as succeeded.
|
|
12
|
+
- `prefixwise report` now prints plain-English findings by default. The totals and tables
|
|
13
|
+
are behind `--detail` (or `--by`). Scripts should use `--json`, which keeps its keys and
|
|
14
|
+
adds `findings`.
|
|
15
|
+
- Failed requests (upstream errors, cut-off streams) are now recorded as rows without a
|
|
16
|
+
verdict. Token and cost metrics exclude them; `summary` adds `failed_requests`.
|
|
17
|
+
|
|
18
|
+
- **Self-hosted engines (vLLM, SGLang, LMCache):** `prefixwise serve --engine vllm|sglang` declares one self-hosted engine. With no routing possible, an unchanged-prefix miss is named `evicted` (inferred, and the evidence says so) instead of `routing_miss`. On vLLM, `--kv-events tcp://host:5557` reads the engine's KV-cache events: Prefixwise tags requests with its session id and asks vLLM to report every block a request uses, then checks the block where the cache read stopped (removed: confirmed eviction; still there: not an eviction). The verdict becomes `evicted` confirmed with a block count, or `unknown` ("not an eviction: the engine still holds this session's blocks"). Library callers: `handle("vllm", ...)` sends `session_id` only with `engine="vllm"`. Prefixes restored by LMCache or HiCache count as hits. `GET /engine` shows the stream. Optional extra `prefixwise[engines]`. Design and limits: `docs/ENGINES.md`.
|
|
19
|
+
- **SGLang and LMCache:** E1-open takes `--engine vllm | vllm-lmcache | sglang | sglang-hicache`, with launch scripts `sglang_server.sh` and `vllm_lmcache_server.sh` (flags checked against each project's source). Prefixwise sends a body `session_id` only to vLLM; SGLang reads it as its own session handle and rejects unknown ones.
|
|
20
|
+
- **E-evict** (`experiments/e_evict`): floods an engine past its GPU KV capacity and checks whether the session's prefix survives, with and without an offload tier (LMCache, HiCache), and with and without KV events.
|
|
21
|
+
- **E1-open report:** the misses list compares against the expected cause, so `switch_back` hits no longer appear as misses.
|
|
22
|
+
- **Fixed:** `vllm_server.sh` enabled KV events with a field name current vLLM rejects (`enable_kv_cache_events` is the field).
|
|
23
|
+
- **`prefixwise run -- <agent>`**: zero setup. Starts the proxy on a free port, points the agent at it (`ANTHROPIC_BASE_URL` / `OPENAI_BASE_URL`; the agent keeps its own keys; existing base URLs become the upstreams), runs it, and prints a plain-English report on that run. The agent's exit code is passed through; Ctrl-C goes to the agent (it cancels a turn, it does not kill the agent) and SIGTERM is passed on. Gateway base URLs are kept exactly as set; a base URL that is already a Prefixwise proxy is refused rather than double-counted; `PREFIXWISE_API_KEY` never replaces the agent's keys.
|
|
24
|
+
- **A report that says what to do:** `prefixwise report` now leads with findings in plain English (cache share, cost, avoidable waste by cause with the fix for each, expected misses, failures); `--detail` (or `--by`) adds the tables; `--since 24h` narrows the window. The same findings are data at `GET /api/v1/findings`.
|
|
25
|
+
- **One proxy, two providers:** per-provider upstreams, so Anthropic and OpenAI requests each reach their own API.
|
|
26
|
+
- **Data first** ([docs/DATA.md](docs/DATA.md)): every request leaves a row of facts, failures included. New per-request fields: status and error (upstream errors and cut-off streams are rows now, without a verdict, so rates keep honest denominators), api, stream, uncached and cache-write tokens, upstream latency, Prefixwise's own overhead, the gap since the previous turn, the verdict's evidence and secondary causes, and where the prompt first diverged. Existing ledgers migrate in place.
|
|
27
|
+
- **Every metric defined once** (`prefixwise.metrics`): a catalog of names, units and definitions that the CLI, the API and exports all use. Ratios are ratios of sums. Token and cost metrics count requests with a verdict; failures count in `requests_failed` and `error_rate`.
|
|
28
|
+
- **HTTP API `/api/v1`** ([docs/API.md](docs/API.md)): `metrics` (the catalog), `summary`, `breakdown?by=`, `timeseries?bucket=`, `requests` (paginated), `requests/{id}`, `fixes`, `prices`, `POST tasks`, `POST explain`; filters and time windows; same token auth as the proxy.
|
|
29
|
+
- **`prefixwise export`**: raw rows as JSONL or CSV.
|
|
30
|
+
- **Summary** reports `failed_requests`.
|
|
31
|
+
- **Fixed (agent compatibility check):** a session mixing Chat Completions and the Responses API on one model had its Responses calls rejected (400): Prefixwise chained a `chatcmpl-` id into `prompt_cache_options`. Diagnostics now chain only to an id from the same API (`resp_`, `msg_`).
|
|
32
|
+
- **Fixed:** a short Anthropic prompt (below the model's minimum cacheable prefix: 512 tokens for Claude 5.x, up to 4,096 for older models) was reported as a misplaced cache breakpoint, with avoidable tokens and advice that could not help. It is now `below_min_prefix`, not waste.
|
|
33
|
+
- **Fixed (agent compatibility check):** under `prefixwise run`, cancelling a streamed turn with Ctrl-C printed proxy tracebacks (BrokenPipeError) into the agent's terminal. Client disconnects are now silent, other server errors are one line, and while the agent runs the proxy's own messages go to `prefixwise-run.log` next to the ledger.
|
|
34
|
+
- **Fixed:** when the previous request was below the provider's minimum cacheable prefix, a change since (e.g. a rewritten message) was reported as waste. Nothing could have been cached, so it is now `below_min_prefix`.
|
|
35
|
+
- **Codex works with `prefixwise run`:** Codex 0.167+ ignores `OPENAI_BASE_URL`, so its requests bypassed the proxy. `prefixwise run -- codex ...` now adds `-c` overrides for a custom provider (plain HTTP + SSE instead of WebSocket, key from `OPENAI_API_KEY`, no sign-in screen, nothing written to `~/.codex`). The proxy forwards Codex's headers, including the `x-codex-turn-state` sticky routing that keeps requests on the same backend, and uses its thread id as the session.
|
|
36
|
+
- Report wording: "1 request", not "1 requests".
|
|
37
|
+
|
|
38
|
+
## 0.3.1: 2026-11-07
|
|
39
|
+
|
|
40
|
+
Production hardening, found by a new benchmark; per-model lanes; OpenAI prices.
|
|
41
|
+
**Upgrading:** existing ledgers are migrated in place on first start. Rows written before
|
|
42
|
+
0.3.1 have no timestamp, so `prefixwise prune` keeps them unless you add `--include-undated`.
|
|
43
|
+
|
|
44
|
+
- **Production benchmark** (`benchmarks/bench.py`): added latency, throughput, memory, a soak and 13 failure cases, against the real `prefixwise serve` and a fake upstream. Results in `benchmarks/runs/`; README "Running in production" summarises them. CI runs the failure cases on every push.
|
|
45
|
+
- **3-4x lower overhead on long prompts:** masked block hashes are cached, since an agent resends the same prefix every turn. A 120k-token request went from +50 ms to +13 ms (p50).
|
|
46
|
+
- **Fails open:** a ledger write or classifier failure no longer turns a paid upstream response into a 500 (or, mid-stream, appends an error to the stream). The response passes through with `X-Prefixwise-Error: not recorded`.
|
|
47
|
+
- **Upstream headers relayed:** `retry-after`, `retry-after-ms`, `x-should-retry`, rate-limit headers and the provider's request id now reach the client, on success, errors and streams. They were dropped, so SDKs could not honour the provider's backoff.
|
|
48
|
+
- **Idle connections are closed** after `PREFIXWISE_CLIENT_TIMEOUT` (120 s). Before, 300 idle sockets held 300 threads forever.
|
|
49
|
+
- **Graceful shutdown:** SIGTERM drains in-flight requests and streams (up to `PREFIXWISE_DRAIN_SECONDS`, 8 s) and exits 0. In Docker the proxy is PID 1, where an unhandled SIGTERM was ignored and `docker stop` killed it mid-stream after 10 s.
|
|
50
|
+
- **Ledger retention:** entries record when they were written; `prefixwise prune --older-than 30d` deletes old ones.
|
|
51
|
+
- **Per-model lanes within a session.** Each request is compared with the last request to the same model, so small-model side calls no longer mask causes on the main thread. Found by dogfooding opencode, which interleaves Haiku calls with Sonnet. A first call to a new model is still `model_switch`; switching back to a model whose prefix is still cached is a hit. Provider diagnostics chain to the same model's last response.
|
|
52
|
+
- **Replacing a one-shot request is not a history edit:** a single-message request followed by a different one (side calls) is judged on its shared-prefix cache reuse.
|
|
53
|
+
- **E1-open harness fix:** Session B turns 8–10 now keep the compacted history. They had reverted to the pre-compaction history, hidden by the model switch until lanes exposed it.
|
|
54
|
+
- **CLI:** `prefixwise report | head` exits quietly.
|
|
55
|
+
- **OpenAI prices:** GPT-5.6 Luna, Terra and Sol are priced from OpenAI's own pricing page (read 2026-11-07; standard speed, short context). The cache-write column is OpenAI's 30-minute write; the 12-hour rate is recorded but not applied. Sol's price is promotional and expires after 2026-11-30, after which it shows `-` until updated. Plain `gpt-5.6` has no published row and stays unpriced.
|
|
56
|
+
- **Price matching is stricter:** a table id matches only itself plus a dated snapshot or cloud version suffix, so `gpt-5.6-sol-pro` no longer borrows Sol's price.
|
|
57
|
+
|
|
58
|
+
## 0.3.0: 2026-11-07
|
|
59
|
+
|
|
60
|
+
- **Fixes the proxy can apply:** `prefixwise serve --fix canonical_tools` sorts tools so a drifting tool list stops breaking the cache. It is opt-in and reversible, and the ledger records which requests it rewrote.
|
|
61
|
+
- **`prefixwise fixes`:** ranks fixes by the tokens your own ledger says they would save.
|
|
62
|
+
- **Found by dogfooding (opencode):** `/messages`-style paths without `/v1` are accepted. Query strings are forwarded. Endpoints Prefixwise does not analyse (`/v1/models`, `count_tokens`, ...) pass through unrecorded. `HEAD` is answered. Sonnet 4.6 is priced.
|
|
63
|
+
- **Dollar costs:** every request is priced from a dated price table. Built in: Claude Haiku, Sonnet and Opus 5.5 and Fable 5.1, verified from Anthropic's pricing page on 2026-11-06, including Haiku's over-100k tier and 1-hour cache writes. Add your own with `PREFIXWISE_PRICES`. `report` shows cost, avoidable cost and cost per successful task; `fixes` shows savings in dollars; `prefixwise prices` shows the table. Unknown rates stay empty, never estimated.
|
|
64
|
+
- **E4 harness** (`experiments/e4`): replays recorded sessions with a fix off and on, and measures predicted vs. realised savings and task success. **`canonical_tools` is proven:** 99.9% (Anthropic) and 97.5% (vLLM) of predicted savings realised, with task success flat. `prefixwise fixes` shows the evidence.
|
|
65
|
+
- **E1-hosted:** on Anthropic, Prefixwise agreed with Anthropic's own miss diagnosis on 37 of 37 misses. OpenAI's diagnostics returned `unavailable` (recorded as an open question).
|
|
66
|
+
- **Fixed:** the moving Anthropic `cache_control` breakpoint, and string vs. text-block content, were both misread as `history_edit`.
|
|
67
|
+
- **Fixed:** Anthropic's real diagnostics shape (`diagnostics.cache_miss_reason`) is now read.
|
|
68
|
+
- **Fixed:** a request with no usage is now `unknown`, not `below_min_prefix`.
|
|
69
|
+
- **Security:**
|
|
70
|
+
- `PREFIXWISE_AUTH_TOKEN`, and the proxy refuses to expose an API key without one
|
|
71
|
+
- input validation and body limits
|
|
72
|
+
- the ledger file is owner-only
|
|
73
|
+
- `SECURITY.md`
|
|
74
|
+
|
|
75
|
+
## 0.2.0: 2026-11-06
|
|
76
|
+
|
|
77
|
+
- **CLI:** `prefixwise serve | report | task | request | explain`.
|
|
78
|
+
- **Proxy:** a drop-in pass-through for OpenAI chat completions, the Responses API and Anthropic messages, streaming included. Verdicts come back in `X-Prefixwise-*` headers.
|
|
79
|
+
- **Tokens per successful task:** measured per task, not per request, with a `/tasks` endpoint.
|
|
80
|
+
- **Causes:** tool-result, TTL and fork causes now fire, and the timing rules no longer guess.
|
|
81
|
+
- **E1-open** passed live on vLLM: 120 turns, 100%.
|
|
82
|
+
- Docker image and CI on Python 3.11 to 3.13.
|
|
83
|
+
|
|
84
|
+
## 0.1.0: 2026-11-05
|
|
85
|
+
|
|
86
|
+
- First version: fingerprinting, the 19-cause classifier, the ledger and the proxy.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: prefixwise
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.0
|
|
4
4
|
Summary: Name why your LLM prompt cache missed, price the miss, and measure tokens per successful task. A local proxy and CLI for OpenAI, Anthropic and vLLM.
|
|
5
5
|
Project-URL: Homepage, https://github.com/tejachavali/prefixwise
|
|
6
6
|
Project-URL: Issues, https://github.com/tejachavali/prefixwise/issues
|
|
@@ -12,14 +12,20 @@ Classifier: Development Status :: 3 - Alpha
|
|
|
12
12
|
Classifier: Environment :: Console
|
|
13
13
|
Classifier: Intended Audience :: Developers
|
|
14
14
|
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
16
|
Classifier: Programming Language :: Python :: 3.11
|
|
16
17
|
Classifier: Programming Language :: Python :: 3.12
|
|
17
18
|
Classifier: Programming Language :: Python :: 3.13
|
|
18
19
|
Classifier: Topic :: Software Development :: Libraries
|
|
19
20
|
Classifier: Topic :: System :: Monitoring
|
|
20
|
-
Requires-Python: >=3.
|
|
21
|
+
Requires-Python: >=3.10
|
|
21
22
|
Provides-Extra: dev
|
|
23
|
+
Requires-Dist: msgspec>=0.18; extra == 'dev'
|
|
22
24
|
Requires-Dist: pytest; extra == 'dev'
|
|
25
|
+
Requires-Dist: pyzmq>=25; extra == 'dev'
|
|
26
|
+
Provides-Extra: engines
|
|
27
|
+
Requires-Dist: msgspec>=0.18; extra == 'engines'
|
|
28
|
+
Requires-Dist: pyzmq>=25; extra == 'engines'
|
|
23
29
|
Description-Content-Type: text/markdown
|
|
24
30
|
|
|
25
31
|
# Prefixwise
|
|
@@ -53,11 +59,35 @@ none 790 5,925,000 84.0% 0 0
|
|
|
53
59
|
## Quickstart
|
|
54
60
|
|
|
55
61
|
```bash
|
|
56
|
-
pip install
|
|
62
|
+
pip install prefixwise
|
|
63
|
+
prefixwise run -- claude # or any agent: your command after the --
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
`prefixwise run` starts the proxy, points the agent at it (`ANTHROPIC_BASE_URL`, `OPENAI_BASE_URL`; the agent keeps its own API key), and when the agent exits prints what that run's cache did, in plain English:
|
|
67
|
+
|
|
68
|
+
```
|
|
69
|
+
42 requests, 1,812,400 prompt tokens, 91% served from cache. Cost $3.08.
|
|
70
|
+
Avoidable: 96,500 tokens ($0.26), 5.3% of prompt tokens. Fix these, biggest first:
|
|
71
|
+
1. The system prompt changed only in a date, time or id (14 requests, 88,200 tokens, $0.24).
|
|
72
|
+
Fix: Move dates, times and ids out of the system prompt, to the end of the prompt or the latest user message.
|
|
73
|
+
2. The same tools were sent in a different order or format (3 requests, 8,300 tokens, $0.02).
|
|
74
|
+
Fix: Send tools in a fixed order with deterministic serialization (...)
|
|
75
|
+
Prefixwise can do it for you: prefixwise serve --fix canonical_tools (proven)
|
|
76
|
+
Expected misses (not waste): 2 x first request of a session: nothing to reuse yet; 1 x switched model: each model has its own cache.
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
(Illustrative output. `prefixwise run --mock -- <agent>` tries it with synthetic responses and no API calls.)
|
|
80
|
+
|
|
81
|
+
Ctrl-C goes to the agent as usual. If you already set `ANTHROPIC_BASE_URL` or `OPENAI_BASE_URL` (a gateway), Prefixwise forwards there, so the agent reaches the same place. It works with agents that use an **API key**; an agent signed in with a subscription instead cannot be routed through a proxy, and the report says so if the provider rejects it. **Codex** ignores `OPENAI_BASE_URL`, so `prefixwise run -- codex ...` adds `-c` settings that point it at the proxy as a custom provider (plain HTTP, the key from `OPENAI_API_KEY`, no sign-in screen, nothing written to `~/.codex`).
|
|
82
|
+
|
|
83
|
+
### Running the proxy yourself
|
|
84
|
+
|
|
85
|
+
For a long-running proxy, start it and point any OpenAI- or Anthropic-compatible client at it:
|
|
86
|
+
|
|
87
|
+
```bash
|
|
57
88
|
prefixwise serve --mock # no API key, synthetic responses; try it first
|
|
58
89
|
```
|
|
59
90
|
|
|
60
|
-
Point any OpenAI- or Anthropic-compatible client at it:
|
|
61
91
|
|
|
62
92
|
```python
|
|
63
93
|
from openai import OpenAI
|
|
@@ -71,7 +101,7 @@ Then:
|
|
|
71
101
|
|
|
72
102
|
```bash
|
|
73
103
|
prefixwise task fix-bug-42 --success # when the task ends (or POST /tasks)
|
|
74
|
-
prefixwise report #
|
|
104
|
+
prefixwise report # what the cache did, and what to fix (--detail for tables)
|
|
75
105
|
prefixwise report --by agent_id # compare agent / prompt versions per successful task
|
|
76
106
|
prefixwise explain examples/session.jsonl # offline: diagnose a saved session (examples/ is in this repo)
|
|
77
107
|
```
|
|
@@ -89,7 +119,7 @@ docker build -t prefixwise . && docker run -p 127.0.0.1:8080:8080 -v pw:/data pr
|
|
|
89
119
|
|
|
90
120
|
## What it tells you
|
|
91
121
|
|
|
92
|
-
One cause per request: the first thing, in prefix order, that broke reuse. Waste is avoidable; legitimate changes cost tokens but are not waste.
|
|
122
|
+
One cause per request: the first thing, in prefix order, that broke reuse. Each request is compared with the previous request **to the same model** in its session, so an agent's small-model side calls (titles, summaries) never mask what is happening on its main thread. Waste is avoidable; legitimate changes cost tokens but are not waste.
|
|
93
123
|
|
|
94
124
|
| Cause | Meaning | Waste? | Typical fix |
|
|
95
125
|
|---|---|---|---|
|
|
@@ -103,7 +133,7 @@ One cause per request: the first thing, in prefix order, that broke reuse. Waste
|
|
|
103
133
|
| `tool_result_mutation` | An earlier tool result was re-rendered or removed | **yes** | Freeze tool output once sent |
|
|
104
134
|
| `compaction_rewrite` | Context was compacted (send `X-Prefixwise-Compaction-Event: 1`) | no | Compact at task boundaries, not per turn |
|
|
105
135
|
| `param_rendered` | Blocks equal, but tool_choice / thinking / reasoning / format changed | depends | Keep those params stable within a session |
|
|
106
|
-
| `model_switch` |
|
|
136
|
+
| `model_switch` | First call to a different model in the session | no | - |
|
|
107
137
|
| `retry_replay` | Identical request within 60 s with nothing cached | **yes** | Check retry logic |
|
|
108
138
|
| `breakpoint_misplaced` | Anthropic: no `cache_control` breakpoint | **yes** | Add `cache_control` after the stable prefix |
|
|
109
139
|
| `below_min_prefix` | Prompt below the provider's minimum cacheable length | depends | - |
|
|
@@ -121,8 +151,11 @@ Avoidable tokens for a waste turn = the part of the previous turn's prompt that
|
|
|
121
151
|
|
|
122
152
|
| Command | |
|
|
123
153
|
|---|---|
|
|
124
|
-
| `prefixwise serve [--upstream URL] [--mock] [--fix canonical_tools] [--host H] [--port P] [--ledger FILE]` | Run the proxy. Ledger defaults to `./prefixwise.db`. `--fix` applies an opt-in, reversible rewrite to every request (see below). |
|
|
154
|
+
| `prefixwise serve [--upstream URL] [--mock] [--fix canonical_tools] [--engine vllm\|sglang] [--kv-events ENDPOINT] [--host H] [--port P] [--ledger FILE]` | Run the proxy. `--engine`/`--kv-events`: see Self-hosted engines. Ledger defaults to `./prefixwise.db`. `--fix` applies an opt-in, reversible rewrite to every request (see below). |
|
|
155
|
+
| `prefixwise run [--mock] [--fix NAME] -- <agent>` | Run an agent through Prefixwise and report on that run when it exits. |
|
|
125
156
|
| `prefixwise prices [--json]` | The dated price table behind dollar costs, and where each rate came from. |
|
|
157
|
+
| `prefixwise prune --older-than 30d` | Delete ledger entries older than that (retention). Add `--include-undated` to also drop rows written before 0.3.1. |
|
|
158
|
+
| `prefixwise export [--format jsonl\|csv] [--since 7d] [--where session=s1]` | Every ledger row (facts, never prompt text) for a spreadsheet, notebook or warehouse. |
|
|
126
159
|
| `prefixwise fixes [--json]` | The fixes that would save the most, ranked by the avoidable tokens your own ledger attributes to each cause. |
|
|
127
160
|
| `prefixwise report [--by cause\|session_id\|agent_id\|model\|provider\|task_id] [--json]` | Totals and a breakdown, most avoidable first. |
|
|
128
161
|
| `prefixwise task ID --success\|--failure` | Record a task outcome (safe while the proxy runs). |
|
|
@@ -144,12 +177,16 @@ Avoidable tokens for a waste turn = the part of the previous turn's prompt that
|
|
|
144
177
|
|
|
145
178
|
**Response headers:** `X-Prefixwise-Request-Id` always; `X-Prefixwise-Cause`, `X-Prefixwise-Legit`, `X-Prefixwise-Avoidable-Tokens` on non-streaming responses; `X-Prefixwise-Fixes` when a fix rewrote the request. Streamed requests are classified when the stream ends: read them from `GET /requests/<id>`.
|
|
146
179
|
|
|
147
|
-
**Environment:** `PREFIXWISE_UPSTREAM_URL`, `PREFIXWISE_API_KEY` (overrides client auth; `x-api-key` for Anthropic), `PREFIXWISE_LEDGER_PATH`, `PREFIXWISE_HMAC_KEY` (HMAC short blocks so their hashes cannot be dictionary-guessed), `PREFIXWISE_MAX_SESSIONS` (default 10,000), `PREFIXWISE_FIXES` (e.g. `canonical_tools`), `PREFIXWISE_AUTH_TOKEN` (require `X-Prefixwise-Token`), `PREFIXWISE_MAX_BODY_BYTES`, `PREFIXWISE_PRICES` (your own rates file), `PORT`.
|
|
180
|
+
**Environment:** `PREFIXWISE_UPSTREAM_URL`, `PREFIXWISE_API_KEY` (overrides client auth; `x-api-key` for Anthropic), `PREFIXWISE_LEDGER_PATH`, `PREFIXWISE_HMAC_KEY` (HMAC short blocks so their hashes cannot be dictionary-guessed), `PREFIXWISE_MAX_SESSIONS` (default 10,000), `PREFIXWISE_FIXES` (e.g. `canonical_tools`), `PREFIXWISE_AUTH_TOKEN` (require `X-Prefixwise-Token`), `PREFIXWISE_MAX_BODY_BYTES`, `PREFIXWISE_PRICES` (your own rates file), `PREFIXWISE_CLIENT_TIMEOUT` (default 120 s), `PREFIXWISE_DRAIN_SECONDS` (default 8), `PORT`.
|
|
148
181
|
|
|
149
|
-
**Dollar costs.** Each request is priced from the provider's own usage breakdown (uncached input, cache reads, cache writes by TTL, output), using a dated price table: `prefixwise prices` shows it. *Avoidable cost* is the avoidable tokens times (input price − cache-read price): what they would have cost as cache hits. A model with no rates shows `-`, never an estimate. To add
|
|
182
|
+
**Dollar costs.** Each request is priced from the provider's own usage breakdown (uncached input, cache reads, cache writes by TTL, output), using a dated price table: `prefixwise prices` shows it. *Avoidable cost* is the avoidable tokens times (input price − cache-read price): what they would have cost as cache hits. A model with no rates shows `-`, never an estimate. To add other models or your negotiated rates, write a JSON file in the same format (`prefixwise prices --json` prints one) and set `PREFIXWISE_PRICES=/path/prices.json`. Your entries override the built-in ones. `prefixwise report` and `prefixwise fixes` then show dollars, and say how many requests were priced.
|
|
150
183
|
|
|
151
184
|
**Fixes the proxy can apply.** `canonical_tools` sorts tools by name and sorts each tool's keys before forwarding, so a tool list that drifts between turns (plugin reload, dict rebuild) stops breaking the cache. It is off by default; with it off, requests pass through unchanged. Prefixwise classifies the request the provider actually received. Fixes that would change what the model reads, like moving a timestamp out of the system prompt, are advice only: `prefixwise fixes` lists them. `canonical_tools` is **proven**: in [E4](experiments/e4/runs/2026-11-06-live.md), turning it on realised 99.9% (Anthropic Haiku 5.5) and 97.5% (vLLM Qwen3-4B) of the savings Prefixwise predicted, with task success flat.
|
|
152
185
|
|
|
186
|
+
## Data and API
|
|
187
|
+
|
|
188
|
+
Every number Prefixwise shows is also data. Each request leaves a row of facts (verdict and its evidence, token breakdown, cost, latency, status; failed requests too), and every metric is defined once and served three ways: `prefixwise report`, the HTTP API at `/api/v1` (summary, breakdowns by cause, session, model, day..., request rows, fixes, prices, explain; [docs/API.md](docs/API.md)), and `prefixwise export`. `GET /api/v1/metrics` lists every metric and what it means. Design: [docs/DATA.md](docs/DATA.md).
|
|
189
|
+
|
|
153
190
|
## Security
|
|
154
191
|
|
|
155
192
|
- **What it stores:** the ledger keeps fingerprints of prompt blocks (hashes), token counts, causes, and your session, task and agent labels. It never stores prompt text or API keys. The ledger file is created readable by its owner only. Set `PREFIXWISE_HMAC_KEY` so hashes of short, guessable blocks are keyed.
|
|
@@ -159,6 +196,45 @@ Avoidable tokens for a waste turn = the part of the previous turn's prompt that
|
|
|
159
196
|
|
|
160
197
|
Found a vulnerability? See [SECURITY.md](SECURITY.md).
|
|
161
198
|
|
|
199
|
+
## Self-hosted engines: vLLM, SGLang, LMCache
|
|
200
|
+
|
|
201
|
+
Step-by-step for vLLM users, with what each verdict means: **[docs/VLLM.md](docs/VLLM.md)**.
|
|
202
|
+
|
|
203
|
+
Prefixwise reads the engine's `cached_tokens` like any provider's: start vLLM with `--enable-prompt-tokens-details`, SGLang with `--enable-cache-report`. Tell it there is one self-hosted engine behind it:
|
|
204
|
+
|
|
205
|
+
```bash
|
|
206
|
+
prefixwise serve --upstream http://127.0.0.1:8000 --engine vllm # or --engine sglang
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
One engine means one cache and no routing, so a request whose prefix is unchanged but was not reused is named `evicted` (the engine ran out of GPU memory). That verdict is **inferred**, and the evidence says so: a chat template that renders history differently, or data-parallel routing, looks the same.
|
|
210
|
+
|
|
211
|
+
**vLLM: confirm it with KV events.** vLLM can tag the blocks each request uses with a session, so Prefixwise can check the block where the cache read stopped: removed means a confirmed eviction, still on the GPU means the prompt's tokens changed there:
|
|
212
|
+
|
|
213
|
+
```bash
|
|
214
|
+
pip install "prefixwise[engines]" # pyzmq + msgspec; the core stays stdlib-only
|
|
215
|
+
vllm serve MODEL --enable-prefix-caching --enable-prompt-tokens-details \
|
|
216
|
+
--kv-events-config '{"enable_kv_cache_events": true, "publisher": "zmq", "endpoint": "tcp://*:5557"}'
|
|
217
|
+
prefixwise serve --upstream http://127.0.0.1:8000 --engine vllm --kv-events tcp://127.0.0.1:5557
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
The verdict becomes `evicted` **confirmed** ("the engine removed N of this session's blocks"), or `unknown` with "not an eviction: the engine still holds this session's blocks" when the cause lies elsewhere. `GET /engine` shows the event stream's health.
|
|
221
|
+
|
|
222
|
+
**LMCache and HiCache need nothing extra.** A prefix restored from CPU memory counts as a hit (vLLM's `cached_tokens` includes tokens loaded from LMCache), so only prefixes lost from every tier are evictions. Why it works this way, the alternatives considered and the known limits (several replicas, lost events): [docs/ENGINES.md](docs/ENGINES.md).
|
|
223
|
+
|
|
224
|
+
## Running in production
|
|
225
|
+
|
|
226
|
+
Measured by [`benchmarks/bench.py`](benchmarks/README.md) (results in [`benchmarks/runs/`](benchmarks/runs/)); rerun it on your own hardware.
|
|
227
|
+
|
|
228
|
+
- **Added latency:** about 3 ms per request at a 2k-token prompt, 6 ms at 30k, 13 ms at 120k (p50; p95 under 22 ms). Streaming adds the same to time to first byte. A model call takes seconds, so this is well under 1%.
|
|
229
|
+
- **Live, against real providers** (records: [Anthropic](benchmarks/runs/2026-11-07-live-anthropic.md), [OpenAI](benchmarks/runs/2026-11-07-live-openai.md)): 20 pairs each, direct vs. through the proxy, from Colab. Cache hit share identical both ways (Anthropic Haiku 5.5: 98.1% and 98.1%; OpenAI GPT-5.6 Luna: 97.9% and 97.9%), every request recorded. Median added latency +29 ms and +43 ms on ~1 s calls, which is within the network variance between two separate calls; the proxy's own cost is 3-6 ms.
|
|
230
|
+
- **Capacity:** one proxy process handles about 185 requests/s of agent-sized traffic before CPU-bound, with no errors up to 128 concurrent clients. An agent sends roughly one request every few seconds, so one process serves hundreds of agents at once. Session state lives in the process: to run several, route each session to the same instance (e.g. hash `X-Prefixwise-Session-Id`).
|
|
231
|
+
- **Memory:** about 11 KB per tracked session, capped by `PREFIXWISE_MAX_SESSIONS` (default 10,000: roughly 100-150 MB), plus a bounded cache of block hashes (about 8 MB). In a 15-minute soak (148,000 requests, 0 errors) RSS went 60 to 74 MB; Python-level memory is flat once the caches fill (tracemalloc: 16.2 MB at both 2,400 and 4,800 sessions), so the remainder is the allocator keeping freed request buffers.
|
|
232
|
+
- **It fails open.** If the ledger cannot be written (disk full, locked) or classification fails, the client still gets the upstream response, with `X-Prefixwise-Error: not recorded`; the proxy logs why to stderr. Upstream errors (429, 500, ...) reach the client unchanged, with `retry-after`, `x-should-retry`, rate-limit headers and the provider's request id, so SDK retries behave as without the proxy. An unreachable or broken upstream is a 502.
|
|
233
|
+
- **Timeouts:** a client connection idle for `PREFIXWISE_CLIENT_TIMEOUT` seconds (default 120) is closed, so idle or half-sent connections cannot pin threads. Upstream calls time out after 600 s (long generations stream for minutes).
|
|
234
|
+
- **Shutdown:** on SIGTERM (`docker stop`, systemd, Kubernetes) the proxy stops accepting connections, lets in-flight requests and streams finish for up to `PREFIXWISE_DRAIN_SECONDS` (default 8), then exits 0.
|
|
235
|
+
- **Ledger growth and retention:** about 450 bytes per request (a million requests is about 450 MB); `prefixwise report` takes about 2 s at a million rows. Delete old rows with `prefixwise prune --older-than 30d`, e.g. from a daily cron. Back it up while the proxy runs with `sqlite3 prefixwise.db ".backup backup.db"`.
|
|
236
|
+
- **Not built yet:** shared session state across processes, a metrics endpoint, and request logging (the proxy logs only errors).
|
|
237
|
+
|
|
162
238
|
## Limits
|
|
163
239
|
|
|
164
240
|
- **What has been verified live (2026-11-06):**
|
|
@@ -169,11 +245,12 @@ Found a vulnerability? See [SECURITY.md](SECURITY.md).
|
|
|
169
245
|
- **OpenAI native agreement.** OpenAI's `prompt_cache_diagnostics` returned `unavailable` for every comparison on gpt-5.6, -luna and -sol. That held with turn delays of 1 s, 30 s and 120 s, and on a minimal standalone call with a completed baseline. OpenAI's dashboard shows 0 diagnosed responses. Prefixwise still classifies OpenAI traffic; only the cross-check against OpenAI's own verdict is missing.
|
|
170
246
|
- **Causes E1 does not inject:** TTL expiry, routing, eviction, tool-result mutation.
|
|
171
247
|
- **Real agent traffic,** which is messier than scripted turns.
|
|
248
|
+
- **Self-hosted engines:** with `--engine`, an engine eviction is inferred from one cache and no routing; on vLLM, `--kv-events` confirms it or rules it out. Validated live on vLLM 0.33 and SGLang 0.5.23 (Colab L4): evictions named 5/5 (confirmed with KV events), LMCache and HiCache restores counted as hits 5/5 ([record](experiments/e_evict/runs/2026-11-07-colab-l4.md)). Not yet measured live: how often the "not an eviction" verdict (token-level divergence) occurs in real agent traffic. Several replicas need one Prefixwise each.
|
|
172
249
|
- **Divergence is located per block, not per token.** An edit at the very end of a long system prompt is reported as `system_edit`, even if the provider could have reused everything before it. In one live OpenAI call, appending three words to 2,100 tokens of instructions gave 0 cached tokens, which looks more like routing than the edit itself.
|
|
173
250
|
- One proxy process keeps session state in memory: run one instance per agent fleet, or send all of a session's turns to the same instance.
|
|
174
251
|
- `evicted` needs vLLM KV events, which the proxy does not consume yet.
|
|
175
252
|
- OpenAI's default in-memory cache TTL is not a fixed number, so after a long gap a cold OpenAI cache is `unknown` unless you send `X-Prefixwise-Cache-Ttl`.
|
|
176
|
-
- **Dollar costs:** only models in the dated price table are priced: Claude Haiku, Sonnet and Opus 5.5, Fable 5.1 and Sonnet 4.6
|
|
253
|
+
- **Dollar costs:** only models in the dated price table are priced: Claude Haiku, Sonnet and Opus 5.5, Fable 5.1 and Sonnet 4.6 (Anthropic's pricing page, 2026-11-06/07), and OpenAI GPT-5.6 Luna, Terra and Sol (OpenAI's pricing page, 2026-11-07; Sol's promotional price expires after 2026-11-30). Everything else shows `-` until you add rates with `PREFIXWISE_PRICES`. OpenAI cache writes are priced at the 30-minute rate. Batch, fast-mode and data-residency multipliers are not modelled.
|
|
177
254
|
|
|
178
255
|
## Working on Prefixwise
|
|
179
256
|
|
|
@@ -29,11 +29,35 @@ none 790 5,925,000 84.0% 0 0
|
|
|
29
29
|
## Quickstart
|
|
30
30
|
|
|
31
31
|
```bash
|
|
32
|
-
pip install
|
|
32
|
+
pip install prefixwise
|
|
33
|
+
prefixwise run -- claude # or any agent: your command after the --
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
`prefixwise run` starts the proxy, points the agent at it (`ANTHROPIC_BASE_URL`, `OPENAI_BASE_URL`; the agent keeps its own API key), and when the agent exits prints what that run's cache did, in plain English:
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
42 requests, 1,812,400 prompt tokens, 91% served from cache. Cost $3.08.
|
|
40
|
+
Avoidable: 96,500 tokens ($0.26), 5.3% of prompt tokens. Fix these, biggest first:
|
|
41
|
+
1. The system prompt changed only in a date, time or id (14 requests, 88,200 tokens, $0.24).
|
|
42
|
+
Fix: Move dates, times and ids out of the system prompt, to the end of the prompt or the latest user message.
|
|
43
|
+
2. The same tools were sent in a different order or format (3 requests, 8,300 tokens, $0.02).
|
|
44
|
+
Fix: Send tools in a fixed order with deterministic serialization (...)
|
|
45
|
+
Prefixwise can do it for you: prefixwise serve --fix canonical_tools (proven)
|
|
46
|
+
Expected misses (not waste): 2 x first request of a session: nothing to reuse yet; 1 x switched model: each model has its own cache.
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
(Illustrative output. `prefixwise run --mock -- <agent>` tries it with synthetic responses and no API calls.)
|
|
50
|
+
|
|
51
|
+
Ctrl-C goes to the agent as usual. If you already set `ANTHROPIC_BASE_URL` or `OPENAI_BASE_URL` (a gateway), Prefixwise forwards there, so the agent reaches the same place. It works with agents that use an **API key**; an agent signed in with a subscription instead cannot be routed through a proxy, and the report says so if the provider rejects it. **Codex** ignores `OPENAI_BASE_URL`, so `prefixwise run -- codex ...` adds `-c` settings that point it at the proxy as a custom provider (plain HTTP, the key from `OPENAI_API_KEY`, no sign-in screen, nothing written to `~/.codex`).
|
|
52
|
+
|
|
53
|
+
### Running the proxy yourself
|
|
54
|
+
|
|
55
|
+
For a long-running proxy, start it and point any OpenAI- or Anthropic-compatible client at it:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
33
58
|
prefixwise serve --mock # no API key, synthetic responses; try it first
|
|
34
59
|
```
|
|
35
60
|
|
|
36
|
-
Point any OpenAI- or Anthropic-compatible client at it:
|
|
37
61
|
|
|
38
62
|
```python
|
|
39
63
|
from openai import OpenAI
|
|
@@ -47,7 +71,7 @@ Then:
|
|
|
47
71
|
|
|
48
72
|
```bash
|
|
49
73
|
prefixwise task fix-bug-42 --success # when the task ends (or POST /tasks)
|
|
50
|
-
prefixwise report #
|
|
74
|
+
prefixwise report # what the cache did, and what to fix (--detail for tables)
|
|
51
75
|
prefixwise report --by agent_id # compare agent / prompt versions per successful task
|
|
52
76
|
prefixwise explain examples/session.jsonl # offline: diagnose a saved session (examples/ is in this repo)
|
|
53
77
|
```
|
|
@@ -65,7 +89,7 @@ docker build -t prefixwise . && docker run -p 127.0.0.1:8080:8080 -v pw:/data pr
|
|
|
65
89
|
|
|
66
90
|
## What it tells you
|
|
67
91
|
|
|
68
|
-
One cause per request: the first thing, in prefix order, that broke reuse. Waste is avoidable; legitimate changes cost tokens but are not waste.
|
|
92
|
+
One cause per request: the first thing, in prefix order, that broke reuse. Each request is compared with the previous request **to the same model** in its session, so an agent's small-model side calls (titles, summaries) never mask what is happening on its main thread. Waste is avoidable; legitimate changes cost tokens but are not waste.
|
|
69
93
|
|
|
70
94
|
| Cause | Meaning | Waste? | Typical fix |
|
|
71
95
|
|---|---|---|---|
|
|
@@ -79,7 +103,7 @@ One cause per request: the first thing, in prefix order, that broke reuse. Waste
|
|
|
79
103
|
| `tool_result_mutation` | An earlier tool result was re-rendered or removed | **yes** | Freeze tool output once sent |
|
|
80
104
|
| `compaction_rewrite` | Context was compacted (send `X-Prefixwise-Compaction-Event: 1`) | no | Compact at task boundaries, not per turn |
|
|
81
105
|
| `param_rendered` | Blocks equal, but tool_choice / thinking / reasoning / format changed | depends | Keep those params stable within a session |
|
|
82
|
-
| `model_switch` |
|
|
106
|
+
| `model_switch` | First call to a different model in the session | no | - |
|
|
83
107
|
| `retry_replay` | Identical request within 60 s with nothing cached | **yes** | Check retry logic |
|
|
84
108
|
| `breakpoint_misplaced` | Anthropic: no `cache_control` breakpoint | **yes** | Add `cache_control` after the stable prefix |
|
|
85
109
|
| `below_min_prefix` | Prompt below the provider's minimum cacheable length | depends | - |
|
|
@@ -97,8 +121,11 @@ Avoidable tokens for a waste turn = the part of the previous turn's prompt that
|
|
|
97
121
|
|
|
98
122
|
| Command | |
|
|
99
123
|
|---|---|
|
|
100
|
-
| `prefixwise serve [--upstream URL] [--mock] [--fix canonical_tools] [--host H] [--port P] [--ledger FILE]` | Run the proxy. Ledger defaults to `./prefixwise.db`. `--fix` applies an opt-in, reversible rewrite to every request (see below). |
|
|
124
|
+
| `prefixwise serve [--upstream URL] [--mock] [--fix canonical_tools] [--engine vllm\|sglang] [--kv-events ENDPOINT] [--host H] [--port P] [--ledger FILE]` | Run the proxy. `--engine`/`--kv-events`: see Self-hosted engines. Ledger defaults to `./prefixwise.db`. `--fix` applies an opt-in, reversible rewrite to every request (see below). |
|
|
125
|
+
| `prefixwise run [--mock] [--fix NAME] -- <agent>` | Run an agent through Prefixwise and report on that run when it exits. |
|
|
101
126
|
| `prefixwise prices [--json]` | The dated price table behind dollar costs, and where each rate came from. |
|
|
127
|
+
| `prefixwise prune --older-than 30d` | Delete ledger entries older than that (retention). Add `--include-undated` to also drop rows written before 0.3.1. |
|
|
128
|
+
| `prefixwise export [--format jsonl\|csv] [--since 7d] [--where session=s1]` | Every ledger row (facts, never prompt text) for a spreadsheet, notebook or warehouse. |
|
|
102
129
|
| `prefixwise fixes [--json]` | The fixes that would save the most, ranked by the avoidable tokens your own ledger attributes to each cause. |
|
|
103
130
|
| `prefixwise report [--by cause\|session_id\|agent_id\|model\|provider\|task_id] [--json]` | Totals and a breakdown, most avoidable first. |
|
|
104
131
|
| `prefixwise task ID --success\|--failure` | Record a task outcome (safe while the proxy runs). |
|
|
@@ -120,12 +147,16 @@ Avoidable tokens for a waste turn = the part of the previous turn's prompt that
|
|
|
120
147
|
|
|
121
148
|
**Response headers:** `X-Prefixwise-Request-Id` always; `X-Prefixwise-Cause`, `X-Prefixwise-Legit`, `X-Prefixwise-Avoidable-Tokens` on non-streaming responses; `X-Prefixwise-Fixes` when a fix rewrote the request. Streamed requests are classified when the stream ends: read them from `GET /requests/<id>`.
|
|
122
149
|
|
|
123
|
-
**Environment:** `PREFIXWISE_UPSTREAM_URL`, `PREFIXWISE_API_KEY` (overrides client auth; `x-api-key` for Anthropic), `PREFIXWISE_LEDGER_PATH`, `PREFIXWISE_HMAC_KEY` (HMAC short blocks so their hashes cannot be dictionary-guessed), `PREFIXWISE_MAX_SESSIONS` (default 10,000), `PREFIXWISE_FIXES` (e.g. `canonical_tools`), `PREFIXWISE_AUTH_TOKEN` (require `X-Prefixwise-Token`), `PREFIXWISE_MAX_BODY_BYTES`, `PREFIXWISE_PRICES` (your own rates file), `PORT`.
|
|
150
|
+
**Environment:** `PREFIXWISE_UPSTREAM_URL`, `PREFIXWISE_API_KEY` (overrides client auth; `x-api-key` for Anthropic), `PREFIXWISE_LEDGER_PATH`, `PREFIXWISE_HMAC_KEY` (HMAC short blocks so their hashes cannot be dictionary-guessed), `PREFIXWISE_MAX_SESSIONS` (default 10,000), `PREFIXWISE_FIXES` (e.g. `canonical_tools`), `PREFIXWISE_AUTH_TOKEN` (require `X-Prefixwise-Token`), `PREFIXWISE_MAX_BODY_BYTES`, `PREFIXWISE_PRICES` (your own rates file), `PREFIXWISE_CLIENT_TIMEOUT` (default 120 s), `PREFIXWISE_DRAIN_SECONDS` (default 8), `PORT`.
|
|
124
151
|
|
|
125
|
-
**Dollar costs.** Each request is priced from the provider's own usage breakdown (uncached input, cache reads, cache writes by TTL, output), using a dated price table: `prefixwise prices` shows it. *Avoidable cost* is the avoidable tokens times (input price − cache-read price): what they would have cost as cache hits. A model with no rates shows `-`, never an estimate. To add
|
|
152
|
+
**Dollar costs.** Each request is priced from the provider's own usage breakdown (uncached input, cache reads, cache writes by TTL, output), using a dated price table: `prefixwise prices` shows it. *Avoidable cost* is the avoidable tokens times (input price − cache-read price): what they would have cost as cache hits. A model with no rates shows `-`, never an estimate. To add other models or your negotiated rates, write a JSON file in the same format (`prefixwise prices --json` prints one) and set `PREFIXWISE_PRICES=/path/prices.json`. Your entries override the built-in ones. `prefixwise report` and `prefixwise fixes` then show dollars, and say how many requests were priced.
|
|
126
153
|
|
|
127
154
|
**Fixes the proxy can apply.** `canonical_tools` sorts tools by name and sorts each tool's keys before forwarding, so a tool list that drifts between turns (plugin reload, dict rebuild) stops breaking the cache. It is off by default; with it off, requests pass through unchanged. Prefixwise classifies the request the provider actually received. Fixes that would change what the model reads, like moving a timestamp out of the system prompt, are advice only: `prefixwise fixes` lists them. `canonical_tools` is **proven**: in [E4](experiments/e4/runs/2026-11-06-live.md), turning it on realised 99.9% (Anthropic Haiku 5.5) and 97.5% (vLLM Qwen3-4B) of the savings Prefixwise predicted, with task success flat.
|
|
128
155
|
|
|
156
|
+
## Data and API
|
|
157
|
+
|
|
158
|
+
Every number Prefixwise shows is also data. Each request leaves a row of facts (verdict and its evidence, token breakdown, cost, latency, status; failed requests too), and every metric is defined once and served three ways: `prefixwise report`, the HTTP API at `/api/v1` (summary, breakdowns by cause, session, model, day..., request rows, fixes, prices, explain; [docs/API.md](docs/API.md)), and `prefixwise export`. `GET /api/v1/metrics` lists every metric and what it means. Design: [docs/DATA.md](docs/DATA.md).
|
|
159
|
+
|
|
129
160
|
## Security
|
|
130
161
|
|
|
131
162
|
- **What it stores:** the ledger keeps fingerprints of prompt blocks (hashes), token counts, causes, and your session, task and agent labels. It never stores prompt text or API keys. The ledger file is created readable by its owner only. Set `PREFIXWISE_HMAC_KEY` so hashes of short, guessable blocks are keyed.
|
|
@@ -135,6 +166,45 @@ Avoidable tokens for a waste turn = the part of the previous turn's prompt that
|
|
|
135
166
|
|
|
136
167
|
Found a vulnerability? See [SECURITY.md](SECURITY.md).
|
|
137
168
|
|
|
169
|
+
## Self-hosted engines: vLLM, SGLang, LMCache
|
|
170
|
+
|
|
171
|
+
Step-by-step for vLLM users, with what each verdict means: **[docs/VLLM.md](docs/VLLM.md)**.
|
|
172
|
+
|
|
173
|
+
Prefixwise reads the engine's `cached_tokens` like any provider's: start vLLM with `--enable-prompt-tokens-details`, SGLang with `--enable-cache-report`. Tell it there is one self-hosted engine behind it:
|
|
174
|
+
|
|
175
|
+
```bash
|
|
176
|
+
prefixwise serve --upstream http://127.0.0.1:8000 --engine vllm # or --engine sglang
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
One engine means one cache and no routing, so a request whose prefix is unchanged but was not reused is named `evicted` (the engine ran out of GPU memory). That verdict is **inferred**, and the evidence says so: a chat template that renders history differently, or data-parallel routing, looks the same.
|
|
180
|
+
|
|
181
|
+
**vLLM: confirm it with KV events.** vLLM can tag the blocks each request uses with a session, so Prefixwise can check the block where the cache read stopped: removed means a confirmed eviction, still on the GPU means the prompt's tokens changed there:
|
|
182
|
+
|
|
183
|
+
```bash
|
|
184
|
+
pip install "prefixwise[engines]" # pyzmq + msgspec; the core stays stdlib-only
|
|
185
|
+
vllm serve MODEL --enable-prefix-caching --enable-prompt-tokens-details \
|
|
186
|
+
--kv-events-config '{"enable_kv_cache_events": true, "publisher": "zmq", "endpoint": "tcp://*:5557"}'
|
|
187
|
+
prefixwise serve --upstream http://127.0.0.1:8000 --engine vllm --kv-events tcp://127.0.0.1:5557
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
The verdict becomes `evicted` **confirmed** ("the engine removed N of this session's blocks"), or `unknown` with "not an eviction: the engine still holds this session's blocks" when the cause lies elsewhere. `GET /engine` shows the event stream's health.
|
|
191
|
+
|
|
192
|
+
**LMCache and HiCache need nothing extra.** A prefix restored from CPU memory counts as a hit (vLLM's `cached_tokens` includes tokens loaded from LMCache), so only prefixes lost from every tier are evictions. Why it works this way, the alternatives considered and the known limits (several replicas, lost events): [docs/ENGINES.md](docs/ENGINES.md).
|
|
193
|
+
|
|
194
|
+
## Running in production
|
|
195
|
+
|
|
196
|
+
Measured by [`benchmarks/bench.py`](benchmarks/README.md) (results in [`benchmarks/runs/`](benchmarks/runs/)); rerun it on your own hardware.
|
|
197
|
+
|
|
198
|
+
- **Added latency:** about 3 ms per request at a 2k-token prompt, 6 ms at 30k, 13 ms at 120k (p50; p95 under 22 ms). Streaming adds the same to time to first byte. A model call takes seconds, so this is well under 1%.
|
|
199
|
+
- **Live, against real providers** (records: [Anthropic](benchmarks/runs/2026-11-07-live-anthropic.md), [OpenAI](benchmarks/runs/2026-11-07-live-openai.md)): 20 pairs each, direct vs. through the proxy, from Colab. Cache hit share identical both ways (Anthropic Haiku 5.5: 98.1% and 98.1%; OpenAI GPT-5.6 Luna: 97.9% and 97.9%), every request recorded. Median added latency +29 ms and +43 ms on ~1 s calls, which is within the network variance between two separate calls; the proxy's own cost is 3-6 ms.
|
|
200
|
+
- **Capacity:** one proxy process handles about 185 requests/s of agent-sized traffic before CPU-bound, with no errors up to 128 concurrent clients. An agent sends roughly one request every few seconds, so one process serves hundreds of agents at once. Session state lives in the process: to run several, route each session to the same instance (e.g. hash `X-Prefixwise-Session-Id`).
|
|
201
|
+
- **Memory:** about 11 KB per tracked session, capped by `PREFIXWISE_MAX_SESSIONS` (default 10,000: roughly 100-150 MB), plus a bounded cache of block hashes (about 8 MB). In a 15-minute soak (148,000 requests, 0 errors) RSS went 60 to 74 MB; Python-level memory is flat once the caches fill (tracemalloc: 16.2 MB at both 2,400 and 4,800 sessions), so the remainder is the allocator keeping freed request buffers.
|
|
202
|
+
- **It fails open.** If the ledger cannot be written (disk full, locked) or classification fails, the client still gets the upstream response, with `X-Prefixwise-Error: not recorded`; the proxy logs why to stderr. Upstream errors (429, 500, ...) reach the client unchanged, with `retry-after`, `x-should-retry`, rate-limit headers and the provider's request id, so SDK retries behave as without the proxy. An unreachable or broken upstream is a 502.
|
|
203
|
+
- **Timeouts:** a client connection idle for `PREFIXWISE_CLIENT_TIMEOUT` seconds (default 120) is closed, so idle or half-sent connections cannot pin threads. Upstream calls time out after 600 s (long generations stream for minutes).
|
|
204
|
+
- **Shutdown:** on SIGTERM (`docker stop`, systemd, Kubernetes) the proxy stops accepting connections, lets in-flight requests and streams finish for up to `PREFIXWISE_DRAIN_SECONDS` (default 8), then exits 0.
|
|
205
|
+
- **Ledger growth and retention:** about 450 bytes per request (a million requests is about 450 MB); `prefixwise report` takes about 2 s at a million rows. Delete old rows with `prefixwise prune --older-than 30d`, e.g. from a daily cron. Back it up while the proxy runs with `sqlite3 prefixwise.db ".backup backup.db"`.
|
|
206
|
+
- **Not built yet:** shared session state across processes, a metrics endpoint, and request logging (the proxy logs only errors).
|
|
207
|
+
|
|
138
208
|
## Limits
|
|
139
209
|
|
|
140
210
|
- **What has been verified live (2026-11-06):**
|
|
@@ -145,11 +215,12 @@ Found a vulnerability? See [SECURITY.md](SECURITY.md).
|
|
|
145
215
|
- **OpenAI native agreement.** OpenAI's `prompt_cache_diagnostics` returned `unavailable` for every comparison on gpt-5.6, -luna and -sol. That held with turn delays of 1 s, 30 s and 120 s, and on a minimal standalone call with a completed baseline. OpenAI's dashboard shows 0 diagnosed responses. Prefixwise still classifies OpenAI traffic; only the cross-check against OpenAI's own verdict is missing.
|
|
146
216
|
- **Causes E1 does not inject:** TTL expiry, routing, eviction, tool-result mutation.
|
|
147
217
|
- **Real agent traffic,** which is messier than scripted turns.
|
|
218
|
+
- **Self-hosted engines:** with `--engine`, an engine eviction is inferred from one cache and no routing; on vLLM, `--kv-events` confirms it or rules it out. Validated live on vLLM 0.33 and SGLang 0.5.23 (Colab L4): evictions named 5/5 (confirmed with KV events), LMCache and HiCache restores counted as hits 5/5 ([record](experiments/e_evict/runs/2026-11-07-colab-l4.md)). Not yet measured live: how often the "not an eviction" verdict (token-level divergence) occurs in real agent traffic. Several replicas need one Prefixwise each.
|
|
148
219
|
- **Divergence is located per block, not per token.** An edit at the very end of a long system prompt is reported as `system_edit`, even if the provider could have reused everything before it. In one live OpenAI call, appending three words to 2,100 tokens of instructions gave 0 cached tokens, which looks more like routing than the edit itself.
|
|
149
220
|
- One proxy process keeps session state in memory: run one instance per agent fleet, or send all of a session's turns to the same instance.
|
|
150
221
|
- `evicted` needs vLLM KV events, which the proxy does not consume yet.
|
|
151
222
|
- OpenAI's default in-memory cache TTL is not a fixed number, so after a long gap a cold OpenAI cache is `unknown` unless you send `X-Prefixwise-Cache-Ttl`.
|
|
152
|
-
- **Dollar costs:** only models in the dated price table are priced: Claude Haiku, Sonnet and Opus 5.5, Fable 5.1 and Sonnet 4.6
|
|
223
|
+
- **Dollar costs:** only models in the dated price table are priced: Claude Haiku, Sonnet and Opus 5.5, Fable 5.1 and Sonnet 4.6 (Anthropic's pricing page, 2026-11-06/07), and OpenAI GPT-5.6 Luna, Terra and Sol (OpenAI's pricing page, 2026-11-07; Sol's promotional price expires after 2026-11-30). Everything else shows `-` until you add rates with `PREFIXWISE_PRICES`. OpenAI cache writes are priced at the 30-minute rate. Batch, fast-mode and data-residency multipliers are not modelled.
|
|
153
224
|
|
|
154
225
|
## Working on Prefixwise
|
|
155
226
|
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Benchmarks
|
|
2
|
+
|
|
3
|
+
`bench.py` measures what Prefixwise costs you in production: added latency,
|
|
4
|
+
throughput, memory, behaviour over time, and what happens when things break.
|
|
5
|
+
No API keys and no network: the real `prefixwise serve` runs as its own process
|
|
6
|
+
in front of a fake model API (`upstream.py`, a third process), with an on-disk
|
|
7
|
+
ledger, and is driven with realistic agent sessions: a long system prompt and
|
|
8
|
+
eight tools, then one turn (user message, assistant reply) appended per request.
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
python benchmarks/bench.py --quick # ~3 minutes
|
|
12
|
+
python benchmarks/bench.py # ~10 minutes
|
|
13
|
+
python benchmarks/bench.py --soak 1800 # with a 30-minute soak
|
|
14
|
+
python benchmarks/bench.py --only faults # one part
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
It writes `benchmarks/runs/<date>-<host>.md` (tables) and `.json` (every
|
|
18
|
+
sample), and exits non-zero if any request errored or any fault case failed.
|
|
19
|
+
CI runs the fault suite on every push.
|
|
20
|
+
|
|
21
|
+
| part | what it measures | pass means |
|
|
22
|
+
|---|---|---|
|
|
23
|
+
| overhead | proxy latency minus direct latency to the same upstream, same request, at 2k, 30k and 120k-token prompts, streaming and not, OpenAI and Anthropic shapes; also time to first byte | small next to model latency |
|
|
24
|
+
| throughput | requests/s and p50/p99 at concurrency 1-128, with an instant upstream (the proxy's own ceiling) and a 300 ms one | 0 errors, every request in the ledger |
|
|
25
|
+
| memory | RSS over 6,000 sessions, with the default session cap and a cap of 1,000 | RSS plateaus at the cap |
|
|
26
|
+
| soak | mixed traffic for a fixed time: both providers, a third streamed, sessions of 5-25 turns, task outcomes posted; RSS, threads and fds sampled | 0 errors, RSS flat once warm, no thread or fd growth |
|
|
27
|
+
| faults | upstream 500 / 429 / dropped connection / HTML body / no usage / slow / drop mid-stream; client invalid JSON / non-object / oversize / disconnect mid-stream / 300 idle or half-sent sockets | the right status, and the proxy healthy after each |
|
|
28
|
+
|
|
29
|
+
What it does not measure: real provider latency (the overhead is additive, so
|
|
30
|
+
it carries over), or the classifier's accuracy. Accuracy is E1:
|
|
31
|
+
`experiments/e1_open` (vLLM, injected causes) and `experiments/e1_hosted`
|
|
32
|
+
(agreement with Anthropic's own diagnostics).
|
|
33
|
+
|
|
34
|
+
Results are machine-dependent; the fake upstream and the load generator share
|
|
35
|
+
the CPUs with the proxy, so throughput figures are a floor.
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# Prefixwise API (v1)
|
|
2
|
+
|
|
3
|
+
`prefixwise serve` serves the API next to the proxy, under `/api/v1`. Every number comes from
|
|
4
|
+
`prefixwise.metrics`, the same definitions `prefixwise report` uses, so the CLI and the API
|
|
5
|
+
cannot disagree. Why it is built this way: [DATA.md](DATA.md).
|
|
6
|
+
|
|
7
|
+
- **Auth:** with `PREFIXWISE_AUTH_TOKEN` set, send `X-Prefixwise-Token`. Without it, the API
|
|
8
|
+
is open to whoever can reach the port (localhost by default).
|
|
9
|
+
- **Errors:** a 4xx with `{"error": {"message": "..."}}`. Unknown metrics, dimensions and
|
|
10
|
+
filters are 400s that name the valid ones.
|
|
11
|
+
- **Privacy:** no endpoint returns prompt text or block hashes; rows hold counts, causes,
|
|
12
|
+
timings and your own labels.
|
|
13
|
+
- **Stability:** `/api/v1` paths and field names only grow. Metrics may be added; existing
|
|
14
|
+
ones keep their meaning. The older `/ledger`, `/requests/{id}` and `/tasks` keep working.
|
|
15
|
+
|
|
16
|
+
## Common parameters
|
|
17
|
+
|
|
18
|
+
| parameter | meaning |
|
|
19
|
+
|---|---|
|
|
20
|
+
| `metrics=a,b` | which metrics (names from `/metrics`); default: a standard set |
|
|
21
|
+
| `since`, `until` | unix seconds, or a duration back from now: `30m`, `24h`, `7d`, `2w` |
|
|
22
|
+
| `cause`, `session`, `agent`, `model`, `provider`, `task`, `api`, `error` | equality filters |
|
|
23
|
+
|
|
24
|
+
## Endpoints
|
|
25
|
+
|
|
26
|
+
### `GET /api/v1/metrics`
|
|
27
|
+
The catalog: every metric's `name`, `unit`, `kind` (sum, ratio, percentile, task) and
|
|
28
|
+
`description`, plus the `dimensions` you can group by and the `filters` you can apply.
|
|
29
|
+
|
|
30
|
+
### `GET /api/v1/summary`
|
|
31
|
+
Every metric (or `metrics=`) over the whole ledger or a window.
|
|
32
|
+
```json
|
|
33
|
+
{"summary": {"requests": 120, "requests_failed": 2, "error_rate": 0.016, "prompt_tokens": 1840000,
|
|
34
|
+
"cached_tokens": 1702000, "cache_hit_rate": 0.925, "avoidable_tokens": 38000,
|
|
35
|
+
"cost_usd": 4.12, "tokens_per_successful_task": 61000.0, "...": "..."}}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### `GET /api/v1/breakdown?by=cause`
|
|
39
|
+
Metrics per group. `by`: cause, session, agent, model, provider, task, api, status, error,
|
|
40
|
+
divergence, day, hour. `order=-avoidable_tokens` sorts (a leading `-` is descending);
|
|
41
|
+
`limit=` caps the rows.
|
|
42
|
+
```json
|
|
43
|
+
{"by": "cause", "rows": [{"cause": "volatile_system", "requests": 14, "avoidable_tokens": 31000, "...": "..."}]}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### `GET /api/v1/timeseries?bucket=day`
|
|
47
|
+
Like breakdown, by `day` or `hour` (UTC), oldest first.
|
|
48
|
+
|
|
49
|
+
### `GET /api/v1/requests`
|
|
50
|
+
Request rows, newest first: verdict, evidence, token breakdown, timings, status. `limit`
|
|
51
|
+
(default 100, max 1000); page back with `before=<next_before>`.
|
|
52
|
+
```json
|
|
53
|
+
{"requests": [{"id": 812, "request_id": "...", "session_id": "s1", "cause": "none", "evidence": "...",
|
|
54
|
+
"prompt_tokens": 15400, "cached_tokens": 15104, "latency_ms": 1180.4, "status": 200, "...": "..."}],
|
|
55
|
+
"next_before": 812}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### `GET /api/v1/requests/{request_id}`
|
|
59
|
+
One row, by the `X-Prefixwise-Request-Id` the proxy returned.
|
|
60
|
+
|
|
61
|
+
### `GET /api/v1/fixes`
|
|
62
|
+
Fixes ranked by the avoidable tokens (and dollars) this ledger attributes to their cause, with
|
|
63
|
+
whether the proxy can apply them and the evidence behind them.
|
|
64
|
+
|
|
65
|
+
### `GET /api/v1/findings`
|
|
66
|
+
What `prefixwise report` says, as data: a summary, the avoidable-waste causes with a plain
|
|
67
|
+
explanation and the fix for each, expected misses, and failures. `since`/`until` narrow it.
|
|
68
|
+
|
|
69
|
+
### `GET /api/v1/prices`
|
|
70
|
+
The dated price table behind the dollar metrics, and the files it came from.
|
|
71
|
+
|
|
72
|
+
### `POST /api/v1/tasks`
|
|
73
|
+
`{"task_id": "fix-bug-1", "success": true}`: record a task outcome, for the per-task metrics.
|
|
74
|
+
|
|
75
|
+
### `POST /api/v1/explain`
|
|
76
|
+
`{"previous": <request body>, "current": <request body>, "current_usage": {...}?}`: why would
|
|
77
|
+
(or did) the cache miss between two requests? The same classifier as the proxy, offline.
|
|
78
|
+
|
|
79
|
+
## Raw data
|
|
80
|
+
|
|
81
|
+
`prefixwise export [--format jsonl|csv] [--since 7d] [--where session=s1] [-o FILE]` writes
|
|
82
|
+
every row, oldest first, for spreadsheets, notebooks or a warehouse.
|