Skip to main content

Local HTTP daemon for generic-ml-cache: REST API, gateway proxy, and session transport. A thin inbound driver over generic-ml-cache-core.

Project description

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.1 by default, and a non-loopback --host is refused (a ConfigError) unless you pass --unsafe-allow-network-gateway to 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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

generic_ml_cache_daemon-0.29.0.tar.gz (36.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

generic_ml_cache_daemon-0.29.0-py3-none-any.whl (34.8 kB view details)

Uploaded Python 3

File details

Details for the file generic_ml_cache_daemon-0.29.0.tar.gz.

File metadata

  • Download URL: generic_ml_cache_daemon-0.29.0.tar.gz
  • Upload date:
  • Size: 36.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for generic_ml_cache_daemon-0.29.0.tar.gz
Algorithm Hash digest
SHA256 b21b5736c1b0ab3a44583fbdcc1f139d8ccf0f620a079b44bdf3340295fb1fc6
MD5 db9ee7a33574f816e0d495eccd0b60b0
BLAKE2b-256 2a7c565e40fa1ae2fef0caba0d88bd3a72ef6bac161048b6397b5a36e0145a3e

See more details on using hashes here.

Provenance

The following attestation bundles were made for generic_ml_cache_daemon-0.29.0.tar.gz:

Publisher: release.yml on danielslobozian/generic-ml-cache

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file generic_ml_cache_daemon-0.29.0-py3-none-any.whl.

File metadata

File hashes

Hashes for generic_ml_cache_daemon-0.29.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d42dfb06b1f0ccd33ca6de4896040cd75cc872a0db4c1ca5f99720ee4a09fb85
MD5 6e756ca3b7e2fdfd5092a13d62cfffe3
BLAKE2b-256 b03098596d41f5a5ab5340edec9d13ad6726e0677504d02ffe65474984e64baf

See more details on using hashes here.

Provenance

The following attestation bundles were made for generic_ml_cache_daemon-0.29.0-py3-none-any.whl:

Publisher: release.yml on danielslobozian/generic-ml-cache

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page