smartcontext-proxy
v0.4.2
Published
Intelligent context window optimization proxy for LLM APIs
Maintainers
Readme
SmartContext Proxy
Intelligent context window optimization proxy for LLM APIs. Sits between your client and LLM providers, dynamically replacing bloated conversation history with relevant context — saving 40-70% on token costs.
Quick Start
npx smartcontext-proxyThat's it. SmartContext auto-detects your providers from env vars and starts proxying.
Client Integration
Change one env var:
# Anthropic
ANTHROPIC_API_URL=http://localhost:4800/v1/anthropic
# OpenAI
OPENAI_BASE_URL=http://localhost:4800/v1/openai
# Ollama
OLLAMA_HOST=http://localhost:4800/v1/ollamaHow It Works
Client App ──► SmartContext Proxy ──► LLM Provider
(unchanged) (intercept+optimize) (any provider)SmartContext operates like a network firewall — the client and provider don't know it exists. It intercepts conversations, replaces growing history with optimized context (recent exchanges + semantically retrieved chunks), and forwards transparently.
Tiered Context Strategy
| Tier | What | Source | |------|------|--------| | T0 | System prompt | Kept stable (KV-cache friendly) | | T1 | Last 3 exchanges | Verbatim from request | | T2 | Relevant context | Vector search retrieval | | T3 | Summaries | Pre-computed session summaries |
Key Features
- Zero-config: Auto-detects providers, embeddings, and storage
- Provider-agnostic: Anthropic, OpenAI, Google, Ollama, OpenRouter
- SSE streaming: Zero-latency pass-through
- Web dashboard: Real-time stats at
localhost:4800 - Graceful degradation: Any failure → transparent pass-through
- Daemon mode:
start/stop/restart+ system service
CLI
npx smartcontext-proxy # Start (foreground)
npx smartcontext-proxy start # Start daemon
npx smartcontext-proxy stop # Stop daemon
npx smartcontext-proxy restart # Restart
npx smartcontext-proxy status # Check status
npx smartcontext-proxy install-service # Auto-start on boot
npx smartcontext-proxy --port 8080 # Custom port
npx smartcontext-proxy --no-optimize # Transparent proxy onlyAPI
GET /health Health check
GET / Web dashboard
GET /_sc/status Proxy status
GET /_sc/stats Aggregate metrics
GET /_sc/feed Recent requests
POST /_sc/pause Pause optimization
POST /_sc/resume Resume optimizationArchitecture
smartcontext-proxy/
├── src/
│ ├── index.ts # CLI + entry point
│ ├── proxy/ # HTTP proxy, router, SSE streaming
│ ├── providers/ # Anthropic, OpenAI, Ollama, Google adapters
│ ├── context/ # Optimizer, chunker, retriever, budget
│ ├── embedding/ # Ollama embedding adapter
│ ├── storage/ # LanceDB storage adapter
│ ├── metrics/ # Request metrics collector
│ ├── ui/ # Web dashboard (inline HTML/CSS/JS)
│ └── daemon/ # Process management, service installer
└── adapters/openclaw/ # OpenClaw-specific adapterLicense
Apache 2.0
