Cloudflare Workers primer
Cloudflare Workers run JavaScript and WebAssembly at the edge across 300+ data centers with sub-millisecond cold starts. This primer walks through deploying a Worker that proxies a Meridian inference call, attaches auth, and caches responses for repeat prompts.
1.Install Wrangler and scaffold
Wrangler is the official Cloudflare CLI. It handles auth, local dev, and deploys. Spin up a fresh TypeScript Worker in under a minute.
npm install -g wrangler wrangler login wrangler init meridian-edge --type ts cd meridian-edge
2.Proxy Meridian with secret bindings
Never embed an API key in source. Use wrangler secret put MERIDIAN_KEY to store it encrypted at the edge. Reference it from the Worker handler via the env binding.
export default {
async fetch(req: Request, env: Env) {
const body = await req.text();
return fetch("https://llm.getnimbus.net/v1/chat/completions", {
method: "POST",
headers: {
"Authorization": "Bearer " + env.MERIDIAN_KEY,
"Content-Type": "application/json"
},
body
});
}
};3.Cache identical prompts
Workers ship with the Cache API for free. Hash the request body, key the response on that hash, and watch your bill collapse for repeat prompts in chatbots or RAG retrievers. Deploy with wrangler deploy and you are live at the edge.