Smart-Cache Proxy: AI & B2B API Cost Optimizer
Under maintenancePricing
from $0.01 / 1,000 results
Smart-Cache Proxy: AI & B2B API Cost Optimizer
Under maintenanceUltra-fast caching middleware proxy for AI & B2B APIs. Hashes and caches identical request payloads using Apify's Key-Value Store, eliminating redundant API hits and slashing your monthly API bills by 50-80%.
Pricing
from $0.01 / 1,000 results
Rating
0.0
(0)
Developer
Riad Hossain
Maintained by CommunityActor stats
0
Bookmarked
2
Total users
1
Monthly active users
18 days ago
Last modified
Categories
Share
Ultra-fast caching middleware that sits between your application and expensive APIs (OpenAI, Claude, Google Maps, scraping endpoints). Identical requests are served from cache — slashing your API bills by 50-80% with microsecond-level responses.
How It Works
Your App → Smart-Cache Proxy → Expensive API (OpenAI, Claude, etc.)↓Apify Key-Value Store(persistent cache)
- Your app sends a request to the proxy (instead of the upstream API)
- The proxy generates a SHA-256 fingerprint of the request (method + URL + body)
- If the response is cached and not expired → instant cache HIT (no upstream call)
- If not cached → forwards to the upstream API, caches the response, returns it
- The
X-Cache: HITorX-Cache: MISSheader tells you exactly what happened
Key Features
- SHA-256 Request Fingerprinting — deterministic hashing with stable key ordering, so
{a:1, b:2}and{b:2, a:1}produce the same cache key - Zero Infrastructure — uses Apify's built-in Key-Value Store. No Redis, no database, no maintenance
- Bearer Token Pass-Through — your API keys are forwarded to the upstream API but never stored or logged by the proxy
- X-Cache Headers — every response includes
X-Cache: HITorX-Cache: MISSso you can monitor savings in real-time - Configurable TTL — set cache expiration per deployment (1 second to 7 days)
- Only Caches Success — 2xx JSON responses are cached; errors (4xx, 5xx) are never cached
- All HTTP Methods — supports GET, POST, PUT, PATCH, DELETE
Input Configuration
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
targetUrl | string | ✅ | https://api.openai.com/v1 | The upstream API base URL to proxy |
cacheTtlSeconds | integer | ❌ | 86400 (24h) | Cache time-to-live in seconds |
requestTimeoutMs | integer | ❌ | 30000 | Upstream request timeout |
maxBodySizeMb | integer | ❌ | 10 | Max request body size |
Quick Start
1. Configure the Actor
Set targetUrl to the API you want to proxy. For example:
- OpenAI:
https://api.openai.com/v1 - Anthropic:
https://api.anthropic.com/v1 - Google Maps:
https://maps.googleapis.com/maps/api
2. Get your proxy URL
After running the Actor (or enabling Standby mode), you'll get a URL like:
https://api.apify.com/v2/acts/riad_h~smart-cache-proxy/runs/:runId
3. Point your client at the proxy
OpenAI SDK (Python):
from openai import OpenAIclient = OpenAI(api_key="sk-your-key-here", # Stays 100% privatebase_url="https://your-proxy-url.apify.net/v1" # Smart-Cache Proxy)# First call → X-Cache: MISS (forwards to OpenAI, caches response)response = client.chat.completions.create(model="gpt-4o",messages=[{"role": "user", "content": "Extract emails from this text..."}])# Second identical call → X-Cache: HIT (instant, $0.00 cost!)response2 = client.chat.completions.create(model="gpt-4o",messages=[{"role": "user", "content": "Extract emails from this text..."}])
OpenAI SDK (Node.js):
import OpenAI from "openai";const openai = new OpenAI({apiKey: process.env.OPENAI_API_KEY,baseURL: "https://your-proxy-url.apify.net/v1"});
cURL:
# First call — cache MISScurl -X POST https://your-proxy-url/v1/chat/completions \-H "Authorization: Bearer sk-your-key" \-H "Content-Type: application/json" \-d '{"model":"gpt-4o","messages":[{"role":"user","content":"Hello"}]}'# → X-Cache: MISS# Same payload — cache HIT (no upstream call!)curl -X POST https://your-proxy-url/v1/chat/completions \-H "Authorization: Bearer sk-your-key" \-H "Content-Type: application/json" \-d '{"model":"gpt-4o","messages":[{"role":"user","content":"Hello"}]}'# → X-Cache: HIT
Management Endpoints
| Endpoint | Method | Description |
|---|---|---|
/__health | GET | Check proxy status and configuration |
/__cache_stats | GET | View cache hit/miss counts and hit rate |
/__cache | DELETE | Clear all cached entries |
Example:
curl https://your-proxy-url/__cache_stats# {"hits": 1247, "misses": 893, "totalRequests": 2140, "hitRate": "58.27%"}
Response Headers
| Header | Value | Description |
|---|---|---|
X-Cache | HIT or MISS | Whether the response was served from cache |
X-Cache-Key | <16-char hex> | First 16 chars of the SHA-256 cache key |
X-Cache-Expires | ISO timestamp | When the cached entry expires (HIT only) |
X-Response-Time-ms | integer | Server-side processing time (MISS only) |
Use Cases
- AI Cost Optimization — cache identical LLM completions to avoid paying for the same prompt twice
- Duplicate Query Elimination — cache API responses for common queries
- Rate Limit Avoidance — serve cached responses instead of hitting rate-limited APIs
- Response Acceleration — cached responses return in <5ms instead of 500-3000ms
- Development & Testing — cache API responses during development to avoid burning credits
Privacy & Security
- Your API keys (Bearer tokens, x-api-key) are passed through to the upstream API but never stored in the cache or logs
- Only the API response data is cached — never headers, auth tokens, or request metadata
- The proxy runs on Apify's secure infrastructure with full isolation
Pricing
This Actor uses pay-per-event billing:
| Event | Charged When | Suggested Price |
|---|---|---|
cache-hit | A request is served from cache (saving you an upstream API call) | $0.001 per hit |
cache-miss | A request is forwarded to the upstream API (and cached) | $0.01 per miss |
You only pay when the proxy delivers value (cache hits). Configure pricing in the Actor's Monetization tab.
Technical Details
- Runtime: Node.js 20 + Express + axios
- Cache: Apify Key-Value Store (named store
smart-cache-proxyfor persistence across container restarts) - Hashing: SHA-256 with stable JSON key ordering
- TTL: Enforced on read — expired entries are treated as misses and replaced
- Response parsing: Auto-detects JSON vs text responses; only caches successful JSON
License
MIT


