New: my book on artificial intelligence, from its history to agentsDiscover it →

An AI chatbot for your website: how to do it right

What it takes to put an assistant on your site that genuinely answers customers: content, model, costs, key security, transparency duties and privacy. Using this site's chatbot as the example.

Mattia PanattaPublished 11 October 202612 minIntermediate
A website window with a small glowing chat bubble answering a visitor
AI-generated illustration

In short

  • A good chatbot answers only from what you know (your pages, price lists, FAQs) and cites where answers come from.
  • The technical part is the easy part; the real work is content, rules and testing.
  • The API key must stay on the server, never in browser code.
  • Since 2 August 2026 the chatbot must disclose it’s an AI (AI Act, Art. 50).

What it can (and can’t) do

A site assistant can: answer FAQs, explain services and prices, guide to the right page, collect a contact request, book. It must not: give personalised professional advice, promise what isn’t in your documents, collect sensitive data.

How this site’s chatbot is built

I use it as the example because you can try it on this page:

  1. Site knowledge: all pages are split into sections and indexed when the site is published. When you ask, the model calls a search tool and reads only the relevant passages (RAG, explained in the RAG and embeddings guide).
  2. Controlled external sources: for fresh news it can search the web, but only four chosen sites.
  3. Model: a fast, affordable language model from a major provider, with light reasoning to answer quickly.
  4. Server: a small function (on Vercel or Netlify) receives the question, adds instructions, calls the model and streams the answer word by word. The key stays there.
  5. Rules: it introduces itself as AI, cites links, doesn’t ask for personal data, refers to a person for specific cases.

The choices to make

The model

A chatbot doesn’t need the most powerful model. What matters is good-enough quality, speed and cost:

Model Price per million tokens (in / out) When
Claude Haiku 5.5 $0.10 / $0.50 Simple questions, high volume
Gemini 3.8 Flash $0.75 / $3.75 Multimodal, PDFs and images
GPT-6.1 Sol $2 / $10 High quality, built-in web search

Prices as of October 2026. A typical answer reads 5-15 thousand tokens (instructions and site passages) and writes a few hundred: from fractions of a cent to a few cents per question.

The content

This is where you win or lose. Before any technology:

  • write a real FAQ page with the 30 questions you actually get;
  • keep prices and opening hours in one up-to-date place;
  • remove outdated information from the site: the chatbot would use it.

The instructions

The instructions tell the chatbot who it is, what it answers and what it must not do (legal or medical advice, prices not written on the site), when to hand the conversation to a person and how to point to the page its answer comes from. A few lines, but they need care and testing on real questions.

Security: three non-negotiable rules

  1. Key on the server. If the API key is in the page code, anyone can copy it and use it at your expense. It goes in the server function’s environment variables.
  2. Limits. A monthly spending cap in the provider’s dashboard, a per-user message limit, a maximum question length.
  3. Distrust inputs. Users will try to make it say odd things (“ignore your instructions and…”). Clear instructions, no access to dangerous tools (no sending emails or database access without checks), and testing before going live.
  • Transparency (AI Act, Art. 50): people chatting must know they’re talking to an AI. A clear welcome message and a fixed note under the input box are enough.
  • Privacy (GDPR): a notice explaining what data goes to the model provider, how long it’s kept, on which legal basis. Better not to store conversations, or only anonymously.
  • Professionals in Italy: if it’s a firm’s chatbot, remember the AI-use notice under Law 132/2025 too.

Before publishing: the test

Prepare 30 real questions, including hard and “trick” ones (off-topic, provocative, with personal data). Check that the chatbot answers correctly, cites the source, says “I don’t know” when needed, and stays within its rules. Repeat the test after every significant change.

Sources

Informational content, current as of the date shown. Prices, models and rules change often: always check official sources. Written with the support of AI tools and reviewed by the author.

Found it useful? Keep going

The book · €19.90The full picture, from history to agentsEverything behind the guides, in a single path. The first chapter is free.Discover the book →AI training · €30/hourA lesson with meWant to apply it to your case? In one hour we set it up together, screen shared.Book a lesson →
Newsletter · freeEvery Monday, what matters

Next guide →Deepfakes and AI scams: how to spot them and protect yourselfCloned voices, fake executives on video, fake investments with famous faces, flawless phishing. How 2026 scams work, the signals to notice and the defences for families, professionals and companies.