generic-ml-cache-daemon
The HTTP daemon for generic-ml-cache. Exposes the cache store and all session/execution functionality as a local REST API with server-sent event (SSE) streaming, plus a caching proxy gateway for the Anthropic Messages API.
Installation
pip install generic-ml-cache-daemon # runtime only
pip install "generic-ml-cache-daemon[metrics]" # + Prometheus /metrics endpoint
Starting the daemon
python -m generic_ml_cache_daemon # uses defaults
GMLCACHE_STORE=/path/to/store python -m generic_ml_cache_daemon
GMLCACHE_SESSION=abc GMLCACHE_METRICS=1 python -m generic_ml_cache_daemon
Environment variables:
| Variable | Default | Description |
|---|---|---|
GMLCACHE_STORE |
config store path | Path to the cache store directory |
GMLCACHE_SESSION |
(none) | Bind all intercepted calls to a session |
GMLCACHE_METRICS |
0 |
Set 1 to enable the Prometheus /metrics endpoint |
HTTP API
The daemon listens on http://127.0.0.1:8765 by default.
Interactive API docs are available at /docs (Swagger UI) and /redoc.
Observability
| Method | Path | Description |
|---|---|---|
GET |
/health |
Liveness: {"status":"ok"} |
GET |
/ready |
Readiness: probes the store; 503 if inaccessible |
GET |
/info |
Version, store path, adapters, bound session |
GET |
/metrics |
Prometheus text (requires [metrics] extra + --metrics) |
Sessions
| Method | Path | Description |
|---|---|---|
GET |
/sessions |
List all session IDs |
POST |
/sessions |
Create a session (body: {tags, spec}) |
GET |
/sessions/{id} |
Get session tags and spec (404 if unknown) |
GET |
/sessions/{id}/stats |
Calls, hits, hit rate |
PUT |
/sessions/{id}/spec |
Set or replace execution spec |
DELETE |
/sessions/{id}/spec |
Remove execution spec |
POST |
/sessions/{id}/tags |
Add a tag |
DELETE |
/sessions/{id}/tags/{tag} |
Remove a tag |
Executions & Global Stats
| Method | Path | Description |
|---|---|---|
GET |
/executions |
List all current (servable) executions |
GET |
/executions/{key} |
Inspect by exact key or prefix (409 on ambiguous prefix) |
GET |
/stats |
Global execution count + event counts |
POST |
/purge |
Purge by scope: all, key, tag, session, session_tag |
Purge body examples:
{"by": "all"}
{"by": "key", "target": "deadbeef"}
{"by": "session", "target": "abc123"}
Run (synchronous or SSE)
POST /run
{
"client": "anthropic",
"model": "claude-opus-4-8",
"prompt": "Summarise the paper.",
"effort": "medium",
"session_id": "abc"
}
Accept: application/json(default) — blocks and returns{execution_key, state, cache_hit, stdout, stderr}Accept: text/event-stream— SSE:{"type":"accepted"}immediately, then{"type":"complete", ...}on finish
Jobs (detached / async)
| Method | Path | Description |
|---|---|---|
POST |
/jobs |
Submit a background execution; returns {job_id, state} with 202 |
GET |
/jobs |
List all job IDs |
GET |
/jobs/{id} |
Poll state: pending, running, done, error |
GET |
/jobs/{id}/stream |
SSE: periodic status events, then complete or error |
Claude Gateway
POST /gateway/claude/{session_id}/v1/messages
A cache-transparent proxy for the Anthropic Messages API. Requests that hit the cache are returned without a network call to Anthropic. The response is the upstream Anthropic Messages API response returned verbatim — a cache hit is byte-for-byte identical to a live call, with no added fields or headers (the passthrough body must stay exact for SDK compatibility).
⚠️ Security — single-principal, localhost only. The gateway is a single-user tool. Its passthrough cache is keyed on the request body only — deliberately not on the caller's auth token or session (the token refreshes, and keying on it would defeat cross-session cache hits). That is safe for one operator on one machine, but it means two different callers who send the same body share one cache entry regardless of their credentials. Never expose this daemon to a network or to multiple users — a second caller could be served the first caller's provider-authorized response. It binds
127.0.0.1by default, and a non-loopback--hostis refused (aConfigError) unless you pass--unsafe-allow-network-gatewayto loudly accept the risk.
Limitations: single-turn conversations only (one role: user message,
no prior assistant turns). Multi-turn support is planned.
Example:
curl http://127.0.0.1:8765/gateway/claude/my-session/v1/messages \
-H "Content-Type: application/json" \
-d '{
"model": "claude-opus-4-8",
"messages": [{"role": "user", "content": "Hello, world!"}],
"max_tokens": 256
}'
Point any Anthropic SDK client at the gateway by overriding the base URL:
import anthropic
client = anthropic.Anthropic(
api_key="...",
base_url="http://127.0.0.1:8765/gateway/claude/my-session",
)
Architecture
The daemon is a thin FastAPI layer over the generic-ml-cache-core hexagonal
architecture. It does not own any state — all persistence goes through the
existing JournalMetrics (SQLite registry) and ExecutionRepository
that the core library manages.
Background jobs run in a ThreadPoolExecutor inside an in-process
JobRegistry; job state is not persisted across daemon restarts.
License
Apache-2.0
Release files for generic-ml-cache-daemon 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| generic_ml_cache_daemon-1.0.0.tar.gz | 36.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| generic_ml_cache_daemon-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 71.7 kB
Release files / generic_ml_cache_daemon-1.0.0.tar.gz
| Download URL | generic_ml_cache_daemon-1.0.0.tar.gz |
|---|---|
| Size | 36.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
964eb9a38324ef478f5986ad1bcd0bcbf699da339ce25c4c54a7172a50309dbb
|
|
BLAKE2b-256 checksum How to use checksums |
e27bfdcb63f14215797fef434c745d059e2e99ba2b7f7ed2b9fcac3fac32471a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 8, 2026.
Transparency logRelease files / generic_ml_cache_daemon-1.0.0-py3-none-any.whl
| Download URL | generic_ml_cache_daemon-1.0.0-py3-none-any.whl |
|---|---|
| Size | 34.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6841ff96dde8789d08626598c862f620935e6e40bf9d6eadca2af63394df04b6
|
|
BLAKE2b-256 checksum How to use checksums |
f513c1bf5b07a513a17357d6a290da8f9344ee3325e8ff59101b4db9493bf9dc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 8, 2026.
Transparency log