A serverless AI gateway deployed at the edge. Routes prompts to Cloudflare Workers AI or Groq based on request complexity, with Cloudflare KV caching that reduces repeated query latency from 2.1 seconds to 44 milliseconds (~48× improvement).
Client Request
│
▼
Cloudflare Workers (Edge)
│
├─► KV Cache Check ──► HIT → Return Cached Response (~44ms)
│
└─► MISS → Route Decision
│
├─► Workers AI (LLaMA 3.8B)
│
└─► Groq (LLaMA 3.3 70B)
│
▼
Store in KV Cache (TTL: 1hr)
│
▼
Return Response + source + latency_ms
Base URL
https://edgemind.mknsvarun.workers.dev
curl https://edgemind.mknsvarun.workers.dev/healthExample Response:
{
"status": "ok",
"region": "SIN"
}curl -X POST https://edgemind.mknsvarun.workers.dev/query \
-H "Content-Type: application/json" \
-d '{"prompt":"Explain DNS in one sentence"}'Example Response:
{
"response": "DNS translates human-readable domain names into IP addresses.",
"source": "workers_ai",
"latency_ms": 834
}Submitting the same prompt again:
curl -X POST https://edgemind.mknsvarun.workers.dev/query \
-H "Content-Type: application/json" \
-d '{"prompt":"Explain DNS in one sentence"}'Example Response:
{
"response": "DNS translates human-readable domain names into IP addresses.",
"source": "cache",
"latency_ms": 44
}curl -X POST https://edgemind.mknsvarun.workers.dev/query \
-H "Content-Type: application/json" \
-d '{"prompt":"Write a detailed essay on BGP","force_groq":true}'Measured on the deployed production endpoint:
| Request Type | Latency |
|---|---|
| Cache Miss | 2113 ms |
| Cache Hit | 44 ms |
| Improvement | ~48× Faster |
| Latency Reduction | 97.9% |
Benchmark command:
time curl -X POST https://edgemind.mknsvarun.workers.dev/query \
-H "Content-Type: application/json" \
-d '{"prompt":"What is BGP?"}'Results:
First Request (Cache Miss): 2113 ms
Second Request (Cache Hit): 44 ms
| Field | Type | Default | Description |
|---|---|---|---|
| prompt | string | required | User query |
| max_tokens | number | 256 | Token budget |
| force_groq | boolean | false | Route directly to Groq |
Returns:
{
"status": "ok",
"region": "SIN"
}DELETE /cache?prompt=<query>Removes a cached response.
if force_groq or max_tokens > 500:
route_to_groq()
else:
route_to_workers_ai()
if workers_ai_fails:
route_to_groq()git clone https://github.com/MKN-Sai-Varun/EdgeMind.git
cd EdgeMind
npm install
npx wrangler secret put GROQ_API_KEY
npx wrangler dev
npx wrangler deploy- Runtime: Cloudflare Workers
- Framework: Hono
- Primary Model: @cf/meta/llama-3-8b-instruct
- Fallback Model: Groq llama-3.3-70b-versatile
- Cache Layer: Cloudflare KV
- Language: TypeScript
- Built a globally distributed edge AI gateway using Cloudflare Workers.
- Implemented intelligent model routing between Workers AI and Groq.
- Reduced repeated query latency from 2.1s to 44ms using KV caching.
- Achieved 97.9% latency reduction and 48× faster responses for cached requests.
- Eliminated unnecessary LLM inference for repeated queries, reducing response cost and improving user experience.
Traditional LLM applications perform full inference on every request, introducing significant latency and cost. EdgeMind moves AI inference closer to users through Cloudflare's edge network and aggressively caches responses, allowing repeat queries to be served in tens of milliseconds instead of seconds.