# Computer-Use Cache

Discord License: MIT Release: v0.1.1 npm Node 18+ Python 3.11+ OpenAI compatible OpenRouter compatible SQLite cache Docker ready

Stop paying twice for the same computer-use task.

Replay repeated browser, coding, and tool workflows at near-zero cost through a drop-in OpenAI-compatible API.

Super API computer-use cache benchmark preview

Benchmark preview: 256/256 cache hits, 100% computer-use cost saved, 60%+ faster runtime.
Live demo:
Try the live Super API dashboard

--- ## Why This Exists Computer-Use Cache makes repeatable agent workflows cheap and reliable. Computer-use agents often repeat the same planning, browser, coding, and tool-use prompts. This server sits between your app and any OpenAI-compatible provider, forwards cache misses upstream, stores successful JSON responses, and serves exact repeated requests from cache. It is intentionally small and provider-neutral. There is no app auth, billing, credits, realtime voice, product state, or custom model catalog logic. Use the npm package for a zero-dependency local proxy, or use the Python server when you want the SQLite implementation. ## Features - Drop-in `baseURL` replacement for OpenAI-compatible clients. - One-command setup for Codex, Claude Code, Cursor, OpenClaw, and Hermes. - `npx` CLI for agents: `computer-use-cache start`, `install`, `init`, `stats`, `clear`, and `env`. - Zero-dependency Node proxy packaged for npm. - Works with OpenRouter by default and OpenAI directly via `UPSTREAM_BASE_URL`. - File-backed npm cache or SQLite-backed Python cache with TTL, model allowlists, and denylists. - Cache hit/miss headers on every response. - Streaming support for cache hits via Server-Sent Events. - Request-level cache bypass controls. - Concrete examples for YouTube downloads, website generation, Browserbase replay, Daytona replay, OpenClaw, and Hermes. - Docker and Gunicorn-ready deployment. - MIT licensed. ## Quick Start ### NPM Agent Tool Install setup files for your agent, then run a local OpenAI-compatible cache in front of OpenRouter or OpenAI: ```bash export UPSTREAM_BASE_URL=https://openrouter.ai/api/v1 export UPSTREAM_API_KEY=sk-or-v1-your-key-here npx -y github:rohanarun/computer-use-cache install all npx -y github:rohanarun/computer-use-cache start ``` Install one agent at a time: ```bash npx -y github:rohanarun/computer-use-cache install codex npx -y github:rohanarun/computer-use-cache install claude-code npx -y github:rohanarun/computer-use-cache install cursor npx -y github:rohanarun/computer-use-cache install openclaw npx -y github:rohanarun/computer-use-cache install hermes ``` Point any OpenAI-compatible agent or SDK at: ```bash export OPENAI_BASE_URL=http://127.0.0.1:8000/v1 export OPENAI_API_KEY=$UPSTREAM_API_KEY ``` Useful CLI commands: ```bash npx -y github:rohanarun/computer-use-cache install all npx -y github:rohanarun/computer-use-cache init npx -y github:rohanarun/computer-use-cache env npx -y github:rohanarun/computer-use-cache stats npx -y github:rohanarun/computer-use-cache clear npx -y github:rohanarun/computer-use-cache doctor ``` Install locally: ```bash npm i computer-use-cache computer-use-cache start --port 8000 ``` ### Paste This Into Any Agent ```text Use Computer-Use Cache as the OpenAI-compatible base URL for repeatable computer-use, browser, coding, and tool workflows. Base URL: http://127.0.0.1:8000/v1 Keep deterministic parameters stable when replaying work: model, messages, tools, tool_choice, response_format, temperature, top_p, and seed. Use cache: false only for private, one-off, or credential-bearing requests. Never include API keys, passwords, private tokens, or credentials in cached prompts. Check X-Computer-Use-Cache: HIT, MISS, or BYPASS to understand savings. ``` ### Python Server ```bash cd code-model-cache-server python3 -m venv .venv source .venv/bin/activate pip install -r requirements.txt export UPSTREAM_BASE_URL=https://openrouter.ai/api/v1 export UPSTREAM_API_KEY=sk-or-v1-your-key-here python server.py ``` Point any OpenAI-compatible client at: ```text http://127.0.0.1:8000/v1 ``` The npm and Python servers expose the same OpenAI-compatible routes. ## JEV-powered cache reuse Set your own TypeSafe API key to enable JEV in either server: ```bash export TYPESAFE_API_KEY=your-typesafe-api-key export JEV_MODEL=jev-latest export UPSTREAM_API_KEY=your-generation-provider-key npx -y github:rohanarun/computer-use-cache start ``` The Node CLI also accepts `--typesafe-api-key` and `--jev-model`, or the server factory accepts `typesafeApiKey` and `jevModel`. Prefer environment variables for secrets. The CLI reports whether a key is set without printing it. Generated env examples are templates: export the values before starting the server. JEV is a structured decision model, not a chat generator. Exact hits stay local. After an exact miss, JEV compares recent cached requests and responses with the current request and chooses an unchanged reusable response or `none`. A rejected, uncertain, malformed, timed-out, or failed decision falls through to your normal upstream generation provider. Without `TYPESAFE_API_KEY`, caching remains exact-only. The TypeSafe key is separate from the upstream key and is never put into cached requests or forwarded to the generation provider. This is opt-in: current request content and candidate requests/responses are sent to TypeSafe for judgment. Only unexpired entries for the same upstream, credential scope, model and endpoint are candidates. Existing unscoped cache files are not reused. Explicit bypass, sensitive-input checks and model filters run first. Streaming requests use exact caching only. A semantic hit has `X-Computer-Use-Cache-Match: jev`; an ordinary JSON exact hit has `exact`. Defaults are `JEV_MODEL=jev-latest`, `JEV_MIN_CONFIDENCE=0.95`, `JEV_MAX_CANDIDATES=8`, `JEV_MAX_INPUT_CHARS=24000`, and `JEV_TIMEOUT_SECONDS=10`. These are configurable operating defaults, not validated accuracy guarantees. Oversized comparison state skips JEV. Tune the prompt in `src/jev-question.json` and evaluate thresholds against your workflows before relying on semantic reuse. For live observations, irreversible tool actions, or freshness-sensitive work, use `cache: false`. Cache replay returns a model response; it does not prove an external action ran. Pin a versioned JEV model if you need stable judge behavior. See the [TypeSafe API](https://docs.typesafe.ai/api) and [model catalog](https://docs.typesafe.ai/models). ## Concrete Workflows These examples are designed to make cache wins obvious. The first run does the real work. The second run reuses the same model request and should return `X-Computer-Use-Cache: HIT`. - [YouTube download workflow](examples/youtube-download.md) - [Generated website workflow](examples/website-generation.md) - [Browserbase replay workflow](examples/browserbase-replay.md) - [Daytona replay workflow](examples/daytona-replay.md) - [OpenClaw and Hermes provider setup](examples/openclaw-hermes.md) ## OpenAI SDK Example ```js import OpenAI from "openai"; const client = new OpenAI({ baseURL: "http://127.0.0.1:8000/v1", apiKey: "local-dev", }); const result = await client.chat.completions.create({ model: "openai/gpt-4.1-mini", messages: [ { role: "user", content: "Generate a TypeScript debounce helper." }, ], temperature: 0.2, }); console.log(result.choices[0].message.content); ``` ## JS SDK Helper ```js import OpenAI from "openai"; import { openAIConfig } from "computer-use-cache"; const client = new OpenAI(openAIConfig({ baseURL: "http://127.0.0.1:8000/v1", apiKey: process.env.UPSTREAM_API_KEY, })); ``` If `UPSTREAM_API_KEY` is configured on the server, client API keys are ignored for upstream forwarding. If it is not configured, the server forwards the incoming `Authorization: Bearer ...` token upstream. ## Curl Example ```bash curl http://127.0.0.1:8000/v1/chat/completions \ -H "Authorization: Bearer local-dev" \ -H "Content-Type: application/json" \ -d '{ "model": "openai/gpt-4.1-mini", "messages": [ {"role": "user", "content": "Write a tiny Python function that adds two numbers."} ], "temperature": 0.2 }' ``` The first request is a cache miss and gets forwarded upstream. Repeat the exact same request to get a cache hit. Cache status is returned in headers: ```text X-Computer-Use-Cache: MISS X-Computer-Use-Cache-Key: ... X-Computer-Use-Cache-Store: stored ``` The legacy `X-Code-Model-Cache` headers are also returned for compatibility. ## Routes | Method | Route | Description | | --- | --- | --- | | `POST` | `/v1/chat/completions` | OpenAI-compatible chat completions. | | `POST` | `/chat/completions` | Chat completions alias. | | `POST` | `/api/v1/chat/completions` | Chat completions alias. | | `POST` | `/api/chat/completions` | Chat completions alias. | | `POST` | `/v1/completions` | OpenAI-compatible legacy completions. | | `POST` | `/completions` | Legacy completions alias. | | `GET` | `/v1/models` | Proxy upstream models. | | `GET` | `/models` | Models alias. | | `GET` | `/healthz` | Health check. | | `GET` | `/cache/stats` | Cache stats. | | `POST` | `/cache/clear` | Clear cache, optionally protected by `CACHE_ADMIN_TOKEN`. | ## Docker ```bash docker build -t code-model-cache-server . docker run --rm -p 8000:8000 \ -e UPSTREAM_BASE_URL=https://openrouter.ai/api/v1 \ -e UPSTREAM_API_KEY=sk-or-v1-your-key-here \ -v "$PWD/data:/data" \ code-model-cache-server ``` ## Configuration | Variable | Default | Description | | --- | --- | --- | | `UPSTREAM_BASE_URL` | `https://openrouter.ai/api/v1` | Upstream OpenAI-compatible base URL. | | `UPSTREAM_API_KEY` | empty | Server-side upstream API key. Falls back to `OPENROUTER_API_KEY` or `OPENAI_API_KEY`. | | `UPSTREAM_TIMEOUT_SECONDS` | `180` | Upstream request timeout. | | `HOST` | `127.0.0.1` for npm, `0.0.0.0` for Python | Bind host for local runs. | | `PORT` | `8000` | Bind port for local runs. | | `CACHE_DIR` | `./.computer-use-cache` | NPM package file cache directory. | | `CACHE_DB_PATH` | `./code_model_cache.sqlite3` | SQLite cache location. | | `CACHE_ENABLED` | `1` | Default cache behavior. Requests can override with `"cache": false`. | | `CACHE_TTL_SECONDS` | `2592000` | Cache entry TTL. Set `0` to disable expiry. | | `CACHE_MAX_INPUT_CHARS` | `120000` | Max canonical request size to cache. | | `CACHE_MAX_RESPONSE_CHARS` | `240000` | Max response JSON size to cache. | | `CACHE_MODEL_ALLOWLIST` | empty | Comma-separated shell-style model patterns. Empty means cache all models. | | `CACHE_MODEL_DENYLIST` | empty | Comma-separated shell-style model patterns to never cache. | | `CACHE_IGNORE_KEYS` | empty | Extra request body keys to exclude from cache hashing. | | `INCLUDE_CACHE_METADATA` | `0` | Adds a `code_model_cache` object to JSON responses. Headers are always set. | | `CACHE_ADMIN_TOKEN` | empty | If set, required for `POST /cache/clear`. | | `OPENROUTER_HTTP_REFERER` | empty | Optional OpenRouter attribution header. | | `OPENROUTER_X_TITLE` | empty | Optional OpenRouter attribution header. | The keys `stream`, `cache`, `cache_control`, and `metadata` are excluded from cache hashing by default. ## Request Cache Controls Disable caching for one call: ```json { "model": "openai/gpt-4.1-mini", "messages": [{ "role": "user", "content": "Do not cache this." }], "cache": false } ``` You can also use: ```json { "cache_control": { "enabled": false } } ``` Or send: ```text X-Cache-Bypass: true ``` ## Cache Key Behavior The cache key is a SHA-256 hash of a canonical JSON payload containing the request body minus cache-control-only fields: - `stream` - `cache` - `cache_control` - `metadata` - any extra keys listed in `CACHE_IGNORE_KEYS` This means `model`, `messages`, `tools`, `tool_choice`, `response_format`, `temperature`, `top_p`, `max_tokens`, `seed`, provider-specific params, and most other body fields participate in the key. Requests that appear to contain secrets such as API keys, passwords, access tokens, refresh tokens, or private keys are not cached. ## Streaming For `stream: true`: - Cache hits are returned as Server-Sent Events using the cached response text. - Cache misses are proxied upstream as streams and are not written to cache. For best cache population, make the first request non-streaming, then repeat it with `stream: true` if your client requires streaming behavior. ## Production Checklist - Put the service behind HTTPS before exposing it publicly. - Set `CACHE_ADMIN_TOKEN` if `/cache/clear` is reachable outside localhost. - Use a persistent volume for `CACHE_DB_PATH`. - Configure allowlists or denylists if only certain models should be cached. - Monitor `/cache/stats` for hit rate, saved calls, and cache size. ## License MIT. See [LICENSE](LICENSE).