Developer Documentation
Everything you need to integrate CachePilot in under 5 minutes. One line of code. No SDK. No config files.
Quick Start
CachePilot is a caching proxy that sits between your app and your AI provider. Change one string in your code and every duplicate request returns from cache at zero provider cost.
Step 1: Get your API key
Sign up at cachepilot.dev/signup to get your sk-cache-xxx-yyy key. Or skip signup entirely — use auto-provisioning (see below).
Step 2: Change your base URL
Replace your provider's base URL with CachePilot's. Everything else stays the same — your SDK, auth, streaming, response format.
Step 3: Verify it works
Check the response headers. A cache hit returns immediately with X-CachePilot-Status: HIT and zero provider cost. A miss forwards to your provider normally.
Auto-Provisioning
Skip signup entirely. Send your provider API key in the x-provider-key header and CachePilot auto-creates an account, returning your sk-cache-xxx key in the response header.
Authentication
CachePilot supports two authentication methods:
| Method | Header | When to use |
|---|---|---|
| CachePilot key | Authorization: Bearer sk-cache-xxx | Standard usage — all requests after signup or auto-provision |
| Provider key | x-provider-key: sk-xxx | Auto-provisioning — first request only |
When using x-provider-key, the provider key is passed through to the upstream API and never stored. CachePilot only uses it for the single request.
API Reference
Base URL
Supported Endpoints
| Endpoint | Method | Description |
|---|---|---|
/v1/chat/completions | POST | Chat completions (OpenAI-compatible) |
Request & Response Headers
Request Headers
| Header | Required | Description |
|---|---|---|
Authorization | Yes* | Bearer sk-cache-xxx — your CachePilot API key |
x-provider-key | No | Your provider API key for auto-provisioning. Pass on first request only. |
x-cachepilot-mode | No | passthrough — bypass all caching for this request |
* Either Authorization or x-provider-key is required.
Response Headers
| Header | Description |
|---|---|
X-CachePilot-Key | Your CachePilot API key (returned on auto-provision requests) |
X-CachePilot-Status | HIT (cached) or MISS (forwarded to provider) |
X-CachePilot-Savings | Dollar amount saved on this request (e.g., $0.0042) |
Caching Behavior
What gets cached
- Exact duplicate requests — same model, same messages, same parameters
- Normalized matches — whitespace differences, key ordering, and formatting variations are normalized before hashing
- Non-streaming responses — full response bodies cached at multiple layers
What doesn't get cached
- Streaming responses — forwarded directly to preserve SSE format
- Passthrough requests — set
x-cachepilot-mode: passthroughto bypass caching entirely - Requests with
temperature > 0— non-deterministic responses shouldn't be shared across users
Cache layers
| Layer | Speed | TTL | Description |
|---|---|---|---|
| L0 — In-memory | <1ms | 30s | Hot responses in process memory, LRU eviction, max 500 entries |
| L1 — Edge cache | <5ms | 1hr | Cloudflare Cache API, shared across edge locations |
| L2 — KV store | <50ms | 24hr | Cloudflare KV, globally distributed, tenant-isolated |
Normalization
Cache keys are generated from a normalized representation of the request:
- Model name lowercased and trimmed
- Message content whitespace collapsed (multiple spaces → single space)
- Object key ordering standardized
- All parameters except
streamincluded in the hash
Session-Aware Caching
CachePilot detects multi-turn conversations automatically. When a request contains a prefix of previously seen messages, it recognizes this as a session continuation.
How it works
- Each request's message sequence is hashed
- If the current messages are a strict superset of a previous request, the system identifies it as a continuation
- The stable prefix gets Anthropic-compatible
cache_controlheaders injected automatically - Only new messages are processed at full price; the prefix is served from cache
cache_control markers automatically — no code changes needed.
Pricing
CachePilot charges 20% of your calculated savings. No subscription. No minimum. No setup fee.
| Scenario | Provider cost (no cache) | Your cost (with cache) | CachePilot fee |
|---|---|---|---|
| 60% cache hit rate | $100 | $40 | $12 (20% of $60 saved) |
| 80% cache hit rate | $100 | $20 | $16 (20% of $80 saved) |
| 0% cache hit rate | $100 | $100 | $0 (nothing saved) |
First $20 of savings are free. No trial period — if you save less than $20 total, you never pay a cent. After that, 20% of cumulative savings.
View your real-time savings breakdown in the dashboard.