Building Agentic Websites End-to-End: OpenAI, Next.js, n8n & Sanity
How I architect agentic websites: Next.js UI, OpenAI reasoning, n8n orchestration, and Sanity CMS content — and where each piece earns its place.

An agentic website is a normal website that can do things: answer product questions, qualify a lead, trigger a follow-up, pull the right content at the right moment. The stack I use to build them — and the one behind the gig I offer on Fiverr — is OpenAI, Next.js, n8n, and Sanity CMS. This is how the four pieces fit together.
The four pieces
- Next.js — the UI and the entry point: server components for rendering, route handlers for the agent's API, streaming responses so the user sees tokens as they arrive.
- OpenAI — the reasoning layer: models, tool calling, and structured outputs. The agent loop lives here.
- n8n — orchestration for everything that outlives a request: webhooks, retries, and connectors to CRMs, email, and sheets.
- Sanity CMS — structured content with GROQ queries and a hosted Studio, so editors publish without touching code or waiting for a deploy.
A reference architecture
One request flows through the system in one direction:
- A Next.js server component renders the page and fetches content from Sanity at build or request time.
- A user action hits a route handler. The OpenAI key stays on the server — never in the browser bundle.
- The agent loop runs: prompt, tools, model decision. Tool results and structured outputs are schema-validated before anything acts on them.
- Side effects — emails, CRM updates, enrichment — are handed to an n8n webhook, where retries and logging already exist.
- The model's answer streams back into the UI while the workflow continues in the background.
Why the content lives in a CMS, not in code
Content changes at editor speed; code changes at engineering speed. Keeping articles, pages, and copy in Sanity means a non-developer can publish without a git commit or a deploy. This very portfolio runs on Next.js with an embedded Sanity Studio — the post you are reading was authored there.
Where n8n earns its place
An agent answer is request-time work measured in seconds. Business workflows are human-time work measured in minutes or days: lead follow-ups, enrichment, notifications, handoffs. n8n owns that half with durable executions and retries, so the model never has to wait on a slow external API — and the workflow survives a timeout.
Guardrails I keep by default
- Schema-validate every structured output before acting on it.
- Human approval for anything that sends externally — email, SMS, invoices.
- Secrets server-side only, tool calls logged, and token/loop caps to keep costs predictable.
Agentic features earn their place only when they remove friction — answering the same question for the hundredth time, qualifying a lead at 2 a.m., moving data between tools that should have talked anyway. Everything else stays a plain, fast page. If you are planning an agentic build and want a second pair of hands, get in touch.
Related posts

How to Add an AI Assistant to Your Website That Actually Books Clients
Most website chatbots collect dust. Here is the step-by-step way to add an AI assistant that answers, qualifies, and books meetings — without feeling like a robot.
Read article
How Much Does It Cost to Build an AI Agent in 2026?
What does an AI agent actually cost in 2026 — from a simple FAQ bot to a production voice agent? Honest price ranges, cost drivers, and how to avoid overpaying.
Read article
Google ADK Tutorial: Build Your First AI Agent in 30 Minutes
A practical Google ADK walkthrough: install, write an agent with a tool, run the dev UI, and know what to learn next — from someone who contributes to the ADK docs.
Read article