Smart-Cache Proxy: AI & B2B API Cost Optimizer avatar

Smart-Cache Proxy: AI & B2B API Cost Optimizer

Under maintenance

Pricing

from $0.01 / 1,000 results

Go to Apify Store
Smart-Cache Proxy: AI & B2B API Cost Optimizer

Smart-Cache Proxy: AI & B2B API Cost Optimizer

Under maintenance

Ultra-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

Riad Hossain

Maintained by Community

Actor 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)
  1. Your app sends a request to the proxy (instead of the upstream API)
  2. The proxy generates a SHA-256 fingerprint of the request (method + URL + body)
  3. If the response is cached and not expired → instant cache HIT (no upstream call)
  4. If not cached → forwards to the upstream API, caches the response, returns it
  5. The X-Cache: HIT or X-Cache: MISS header 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: HIT or X-Cache: MISS so 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

FieldTypeRequiredDefaultDescription
targetUrlstringhttps://api.openai.com/v1The upstream API base URL to proxy
cacheTtlSecondsinteger86400 (24h)Cache time-to-live in seconds
requestTimeoutMsinteger30000Upstream request timeout
maxBodySizeMbinteger10Max 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 OpenAI
client = OpenAI(
api_key="sk-your-key-here", # Stays 100% private
base_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 MISS
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: 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

EndpointMethodDescription
/__healthGETCheck proxy status and configuration
/__cache_statsGETView cache hit/miss counts and hit rate
/__cacheDELETEClear all cached entries

Example:

curl https://your-proxy-url/__cache_stats
# {"hits": 1247, "misses": 893, "totalRequests": 2140, "hitRate": "58.27%"}

Response Headers

HeaderValueDescription
X-CacheHIT or MISSWhether the response was served from cache
X-Cache-Key<16-char hex>First 16 chars of the SHA-256 cache key
X-Cache-ExpiresISO timestampWhen the cached entry expires (HIT only)
X-Response-Time-msintegerServer-side processing time (MISS only)

Use Cases

  1. AI Cost Optimization — cache identical LLM completions to avoid paying for the same prompt twice
  2. Duplicate Query Elimination — cache API responses for common queries
  3. Rate Limit Avoidance — serve cached responses instead of hitting rate-limited APIs
  4. Response Acceleration — cached responses return in <5ms instead of 500-3000ms
  5. 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:

EventCharged WhenSuggested Price
cache-hitA request is served from cache (saving you an upstream API call)$0.001 per hit
cache-missA 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-proxy for 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