Pattern: LLM in frontend

LLM-in-frontend is an architectural approach for building LLM-powered applications where the frontend owns the AI experience: prompts, orchestration, and even OpenAI SDK usage all live in the browser. The backend's job is to securely proxy OpenAI requests and expose business data, but it no longer blocks rapid iteration on prompts or AI flows.

See also: Pattern: LLM in backend.

When to use it

Use the LLM-in-frontend pattern when:

Avoid this pattern if:

LLM-in-frontend is best for teams and products that value speed, flexibility, and a modern, collaborative workflow between frontend and backend roles.

How it works

In this model, the UI isn't just a thin client. The frontend manages prompts, orchestrates AI logic, and controls the flow of interaction. The backend acts as a secure gatekeeper, proxying requests and keeping secrets safe.

Frontend                 Backend
+----------------+       +---------------------+
| UI components  |       | OpenAI proxy        |
| Prompts        | ----> |                     | ----> OpenAI
| OpenAI SDK     |       +---------------------+
+----------------+

Advantages

Disadvantages

Case study: moving LLM logic to the frontend

I was once building an LLM-powered RAG chatbot in an innovation team. Our chatbot was already built with LLM-in-backend architecture: every prompt tweak required a backend deploy, and backend deploys were usually a lot harder than frontend deploys. Eventually, experimenting became painful, especially when frontend UX changes demanded backend modifications to prompts.

But I realized there was a better way. As the technical lead, I made the architectural decision to move AI logic, prompts, and orchestration to the frontend (while keeping secrets and business APIs in the backend). This enabled much faster experimentation and feature development. The backend's main job became securely proxying OpenAI requests and exposing business data, not handling prompt tweaks or AI flows.

What actually changed:

Moved to frontend:

Stayed in backend:

The biggest advantage was speed: our frontend team could experiment and ship AI features fast, without waiting for backend deploys. We could try new ideas, tune prompts, and improve user experience in real time.

The main risk was security. I had to be careful about what stayed server-side. If too much moved to the frontend, I risked exposing sensitive operations. Rate limiting, access control, and security all had to be handled robustly in the backend proxy, or we would open ourselves up to abuse.

The result: we shipped better AI features, faster, with a leaner backend and a more empowered frontend.

Summary

LLM-in-frontend architecture is ideal for teams that want to move fast with LLMs, empower frontend developers, and keep sensitive operations secure. If you want to ship better AI features, faster, with a leaner backend, LLM-in-frontend is a proven approach.