Skip to main content

OmniCache

PyPI version License: MIT

OmniCache is a lightweight, local caching proxy for Anthropic (Claude), OpenAI (GPT), and Google (Gemini) APIs.

When developing with AI agents (like Claude Code, Cursor, Aider, or custom LLM scripts), repeated prompts, test runs, and static file queries frequently make duplicate upstream API calls. OmniCache sits between your client and upstream providers to intercept matching requests locally in <1ms, saving API costs and eliminating remote network latency.


Installation

pip install omnicache-proxy

Quickstart

1. Start the Proxy Server

omnicache

By default, the proxy runs on http://localhost:8000. You can change the port with --port:

omnicache --port 8080

2. Connect Your Client

Claude Code (Terminal CLI)

Set the Anthropic base URL environment variable before running claude:

export ANTHROPIC_BASE_URL="http://localhost:8000"
claude

Python (OpenAI SDK)

Route the base_url parameter to the local proxy:

from openai import OpenAI

client = OpenAI(
    api_key="your-api-key",
    base_url="http://localhost:8000/v1"
)

response = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "How do I reverse a linked list in Python?"}]
)
print(response.choices[0].message.content)

Cursor / VS Code / Other Tools

In your tool's model settings, set the API Base URL to http://localhost:8000/v1.


Key Features

  • Two-Tier Cache Engine:
    • L1 Exact Match (Trie Hash): Sub-0.05ms lookup for identical payloads.
    • L2 Semantic Match (Cosine Similarity): Matches semantically equivalent prompts using an in-memory 512-dimension vector projection.
  • Agent Stream Replayer: Emulates natural token-streaming for cached responses so interactive CLIs (like Claude Code) stream smoothly without terminal glitches.
  • Request Coalescing (SingleFlight): Deduplicates concurrent in-flight requests for the same prompt, making only one upstream call.
  • Zero Configuration Persistence: Automatically writes cache snapshots to ~/.omnicache/omnicache.db (SQLite) so cache state survives restarts.
  • Built-in CLI Utilities:
    • omnicache doctor: Checks database state, port bindings, and embedder health.
    • omnicache benchmark: Measures P50, P95, and P99 cache lookup latencies on your machine.
    • omnicache stats: Prints total tokens and cost savings directly to the console.
  • Observability:
    • Web Dashboard: http://localhost:8000/dashboard
    • Prometheus Metrics: http://localhost:8000/metrics
    • CSV Ledger Export: http://localhost:8000/v1/cache/export

CLI Reference

# Start server with clean terminal output
omnicache

# Start on custom port and host
omnicache --host 0.0.0.0 --port 9000

# Run with verbose HTTP access logs
omnicache --verbose

# Run system diagnostic checks
omnicache doctor

# Run local micro-benchmarks (1,000 queries)
omnicache benchmark

# View current token and cost savings
omnicache stats

Configuration

OmniCache can be configured via command-line flags or environment variables (in your shell or a local .env file):

Environment Variable Default Description
PORT 8000 Port to bind the proxy server to.
HOST 0.0.0.0 Host interface to listen on.
SEMANTIC_CACHE_TTL_SECONDS 86400 Default time-to-live for cache entries (24 hours).
SEMANTIC_SIMILARITY_THRESHOLD 0.92 Minimum cosine similarity required for an L2 semantic cache hit.
OMNICACHE_DB_PATH ~/.omnicache/omnicache.db Path to SQLite persistence database.
ANTHROPIC_API_KEY (Optional) Default upstream Anthropic API key (if not passed in client headers).
OPENAI_API_KEY (Optional) Default upstream OpenAI API key (if not passed in client headers).
GEMINI_API_KEY (Optional) Default upstream Google Gemini API key.

Running Tests

Run the test suite using pytest:

git clone https://github.com/13manmayarai-hash/omnicache-proxy.git
cd omnicache-proxy
pip install -e .
pytest tests/ -v

Documentation


License

MIT License. See LICENSE for details.

Download files

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

Source Distribution

omnicache_proxy-2.1.3.tar.gz (52.1 kB view details)

Uploaded Source

Built Distribution

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

omnicache_proxy-2.1.3-py3-none-any.whl (49.3 kB view details)

Uploaded Python 3

File details

Details for the file omnicache_proxy-2.1.3.tar.gz.

File metadata

  • Download URL: omnicache_proxy-2.1.3.tar.gz
  • Upload date:
  • Size: 52.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.28.1

File hashes

Hashes for omnicache_proxy-2.1.3.tar.gz
Algorithm Hash digest
SHA256 3dc3d68c6eaceb015818e36e9243dd7c1c2433b1f2a628a7135513fbde32b247
MD5 2a3accd744018b1d7212f5e8a28b5a60
BLAKE2b-256 5c306430fff65f3831c858cf0237e07e8c4e8c0aaad712394e7b2f14cc1e03db

See more details on using hashes here.

File details

Details for the file omnicache_proxy-2.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for omnicache_proxy-2.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 8d7725d97dfc3baa2cc9e68ce40a0de874ec90ce929f3e870e8f4d0c0a7eb373
MD5 9e623bc55c6490c11cbbc23fc27a0ba3
BLAKE2b-256 5ae6a32c96f7cd8e11c74a34119f328af21392d1eb03d513138cb4b2ed200972

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

2.1.3 This release

2 files

2.1.2

2 files

2.1.1

2 files

2.1.0

2 files

2.0.5

2 files

2.0.4

2 files

2.0.3

2 files

2.0.2

2 files

2.0.1

2 files

2.0.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page