ROHAN

NOTES / INFRA

A proxy API layer: how to let a frontend use third-party APIs without shipping keys

2026-03

The fastest way to integrate a third-party API is usually the wrong one: call it straight from the frontend. It works in a demo. It also means the API key is sitting in a network request that anyone with browser devtools can read, which means it's not really a secret anymore — it's public, just inconvenient to find.

The pattern

Every call to a third-party service goes through your own backend instead. The frontend calls your API; your backend holds the credentials, makes the actual third-party request, and returns only what the frontend needs. The key never leaves the server process. This is the proxy layer, and it's a small amount of extra plumbing for a category of vulnerability that otherwise ships by default.

It's not just about hiding the key from a curious user, either. A backend proxy is also the place to enforce rate limits per user instead of trusting whatever the third-party API's global limit gives you, to cache responses so five identical frontend requests don't become five billed API calls, and to swap providers later without touching the frontend at all — the frontend only ever knew about your API, never the vendor's.

What it costs

One more service hop, and slightly more latency than calling the third party directly. For anything where the round trip matters — streaming an LLM response, for instance — the proxy has to actually stream through rather than buffering the whole response, or you've traded a security problem for a UX one.

Where this bites people

I've seen the direct-call pattern most often in exactly the kind of project that starts as a weekend build and quietly becomes a real product: a hackathon prototype, a client demo, an AI chatbot bolted onto an existing site. Nobody sets out to ship a key to the browser; it's just the default shape of "call the API from the component that needs the answer." The fix is cheap early and expensive late — rotating a leaked key after the fact is the easy part, auditing everywhere that key was used and confirming nothing was abused in the meantime is not.

If you're prototyping and genuinely don't care yet, at least know you're doing it. The proxy layer is the difference between a prototype and something you can actually put in front of users.