Most guides on how to add an AI chatbot to your website start at the install script. Start a step earlier. In our view, most of what gets sold as AI on a website is a chat bubble nobody opens, and the bots worth keeping answer only from your own content, hand off to a person cleanly, and still behave when the model doesn't.
- Ask whether anyone needs it. If visitors email the same ten questions, put the answers on the page first. A bot can't answer what your site doesn't say.
- There are three routes: your platform's built-in assistant, a SaaS widget you paste in, or a small endpoint you own that answers from your content.
- The API key never reaches the browser. The widget talks to your server; your server talks to the model.
- Design the failure first. No good answer, a refusal, an error and an outage all end in the same place: a handoff to your contact form.
- Tell people it's AI and don't fish for personal details. Canada's privacy regulators named both in their 2023 generative AI principles.
- Keep the widget keyboard-friendly and off the content. WCAG 2.2 names an open chat window as a way to hide whatever has focus.
- Measure answers and handoffs, not opens, and write down the number that would make you remove it before you launch.
This is the tutorial in our series on AI built into websites: the decision, the three routes, a working server-side example on the Claude API, then guardrails, privacy, accessibility and measurement. Product facts come from vendor documentation as fetched in December 2026. If you're weighing AI for the business more broadly, AI agents for business covers the internal jobs, which is usually where AI pays for itself first.
Should you add an AI chatbot to your website at all?
People arrive at a small business site to do a handful of things. They check that you do what they need, in their area, at a price they can live with. They find out how to start. They contact you. A chatbot helps with the first two only if the answers already exist somewhere it can read. It can't help with the third at all, except by getting out of the way.
So before building anything, look at what visitors already ask. Three quick sources:
- Your inbox. Pull the last few months of enquiries and list the questions. If the same ones keep arriving, the site isn't answering them.
- Your site search, if you have one. Searches with no results are content gaps with a label on them.
- Whoever answers the email. They know the five questions they answer every day, and the words people use to ask them.
Then be honest about what a bot can't fix:
| Problem | Will a chatbot fix it? |
|---|---|
| The answer isn't on the site | No. It will hand off, or worse, guess. Write the page. |
| The answer is buried | Partly. Better headings and an FAQ fix it for everyone, search engines included. |
| The offer is unclear | No. That's positioning and copy. |
| The site is slow on a phone | No. A chat script adds weight. |
| Enquiries go unanswered | No. That's a staffing problem a bot hides. |
| Visitors ask detailed questions your content does answer | Yes. This is the real use case. |
The last row is the honest one. A chatbot earns its place on sites with a lot of genuinely useful content that people struggle to search: a manufacturer's product documentation, a clinic's policies, a firm's published guides, a store's sizing and care pages. On a ten-page brochure site, a good FAQ and a short form usually beat it.
Three ways to add an AI chatbot to a website
| Route | What it is | Good when | Watch for |
|---|---|---|---|
| Built-in | The AI answer feature in your website builder, store platform or help desk | You already keep your help content in that platform | It only knows what that platform holds; limited control over tone and failure |
| SaaS widget | A script you paste in that crawls your site or takes uploaded documents | You want something live this month without writing code | Where the data goes, whether it answers beyond your content, script weight, log export |
| Custom endpoint | A small server route that searches your content and calls a model API | Your content is good and structured, and you want control of scope, logs and handoff | You own the maintenance, the testing and the bill |
We haven't benchmarked the widget vendors, so the first two rows describe the categories as they're documented and sold, not a product test. The questions that separate one product from another are the same whichever you look at:
- Does it answer only from my content, or does it fall back on general knowledge?
- Can I read every conversation, and export them?
- What happens when it doesn't know? Can I make that a handoff to my form?
- Where is the data stored, for how long, and is it used to train anything?
- How much script does it add, and does it load before or after the page is usable?
- Has the widget been tested with a keyboard and a screen reader?
- Can I switch it off without losing the logs?
A vendor that can't answer the second and third questions plainly is selling a demo.
The custom route: an endpoint that answers from your own content
The custom version has four parts. The widget in the browser sends the visitor's question to your server. Your server searches your own pages for the most relevant passages. It sends the question and those passages to the model with a short set of rules. It returns the answer with the pages it used, or a handoff.
The browser never talks to the model provider directly, because it would need your key to do that. Anthropic's API key documentation is blunt about it: "Keep keys out of source control, client-side code, and prompts." A key in website JavaScript is a public key, and someone else's spending money.
Here's the server side in Node with Anthropic's SDK. The searchSite function is yours to write; RAG for small business covers how to build and test that part. We ran this file against a local mock of the Messages API to confirm the request it sends and each failure path, and it passes node --check.
// chat.mjs: runs on your server. The browser never sees the API key.
import Anthropic from "@anthropic-ai/sdk";
import { searchSite } from "./search.mjs"; // your retrieval: [{ url, text }]
const client = new Anthropic(); // reads ANTHROPIC_API_KEY from the environment
const HANDOFF = "I can't answer that from our site. Use the contact form and a person will reply within one business day.";
const SYSTEM = `You answer visitors' questions on Example Co's website.
Use only the documents provided. If they don't answer the question, reply with exactly: HANDOFF
Don't give legal, medical or financial advice, quote prices, or promise dates unless a document states them.
Never ask for personal details. Answer in under 120 words, then name the page you used.`;
export async function answer(question) {
const docs = await searchSite(question, { limit: 4 });
if (docs.length === 0) return { text: HANDOFF, sources: [], handoff: true };
const documents = docs.map((d, i) =>
`<document index="${i + 1}"><source>${d.url}</source>\n<document_content>${d.text}</document_content></document>`
).join("\n");
try {
const msg = await client.messages.create({
model: "claude-opus-5-5", // check the models page, then test a faster model on your question set
max_tokens: 2000,
output_config: { effort: "low" },
system: SYSTEM,
messages: [{ role: "user", content: `<documents>\n${documents}\n</documents>\n\nVisitor's question: ${question}` }],
});
const text = msg.content.filter((b) => b.type === "text").map((b) => b.text).join("").trim();
if (msg.stop_reason !== "end_turn" || !text || text === "HANDOFF") {
return { text: HANDOFF, sources: [], handoff: true };
}
return { text, sources: docs.map((d) => d.url), handoff: false };
} catch (err) {
console.error("chat_error", err.status ?? err.name); // log it; never show it to the visitor
return { text: HANDOFF, sources: [], handoff: true };
}
}
What each guard is doing:
- The key comes from the environment.
new Anthropic()readsANTHROPIC_API_KEY. Nothing secret lives in the file or the repository. - No passages, no model call. If search finds nothing, the visitor gets the handoff straight away. That saves a call and removes the commonest source of invented answers.
- Rules in the system prompt, material above the question. Anthropic's prompting guide recommends wrapping documents in tags like these and placing long material near the top, with the question at the end.
- A fixed word for "I don't know". Asking for
HANDOFFgives your code something exact to check, instead of guessing whether "I'm not sure" counts as an answer. - Anything but a clean finish is a handoff. The documented stop reasons include
max_tokensandrefusal, and we treat every stop other thanend_turnthe same way. So does an error or an outage. That's the path that works when the model is unavailable, and every AI feature needs one. - Low effort. As of December 2026,
output_config.efforttakeslowthroughmax, and Claude Opus 5.5 defaults tomedium. A short answer from four passages doesn't need deep reasoning, and low keeps it quick.
On the model itself: Anthropic's models overview says to start with Claude Opus 5.5 if you're unsure, and describes Claude Haiku 5.5 as built for high-volume, latency-sensitive tasks. A public widget may be exactly that. Don't choose from the descriptions. Run your question set through both, compare answers and speed, and check current per-token rates on the pricing page.
The route that exposes answer() should be short and strict: POST only, a cap on question length, a rate limit per IP address, JSON out. A free text box that costs you money per message is an obvious target for the same bots that fill contact forms, so give it the same protection. Stopping contact form spam covers the layers that apply.
Guardrails: scope, refusal, handoff and logging
The snippet handles the mechanics. The policy is yours to write down before launch, in plain language, where whoever maintains the site will find it.
Scope. List what the bot may answer: services, areas served, how to book, published policies, hours. Then list what it may not: prices you don't publish, anything that needs a professional's judgement, a specific customer's account, competitors. Put both lists in the system prompt and in your test questions.
Refusal. Decide the exact words. A good refusal says what the bot can't do and what to do instead, in one sentence. It never apologises three times or explains its instructions.
Handoff. The handoff is the product. It should open your form with the visitor's question already filled in, so they don't type it twice, and say who replies and when. Then make sure someone does. A bot that hands off into an inbox nobody owns is worse than no bot, because the visitor believes they were heard.
No tools on a public bot. The example reads your pages and does nothing else. It can't send email, book appointments, change records or look up accounts. Visitor input is untrusted text, and a model that has tools can be talked into using them. If you need booking, link to your booking system. If you need account lookups, that's a logged-in feature with its own security review, not a widget.
Logging. Log the question, the pages retrieved, whether it answered or handed off, the stop reason and the response time. Don't log names, emails or phone numbers; the bot shouldn't be collecting them anyway. Set a retention period and delete on schedule. Read the handoffs every week: each one is either a question the site should answer or one the bot should refuse.
Privacy: what Canadian rules expect from a website chatbot
A chatbot collects whatever people type into it, and people type surprising things. Canada's federal, provincial and territorial privacy regulators published joint principles for generative AI on December 7, 2023. Three of them land directly on a website bot:
- Openness. Make sure people know they're interacting with a generative AI tool. Label the widget plainly, in the panel, not only in the privacy policy.
- Limiting collection. Use de-identified information where you can, and don't retain prompts or use them for secondary purposes unless you're required to.
- A potential no-go zone. The regulators flagged "the use of conversational bots to deliberately nudge individuals into divulging personal information." A bot that asks for a phone number so it can "help further" is walking toward it.
Under PIPEDA you stay responsible for personal information you pass to another company for processing, and you're expected to protect it by contract or other means (Schedule 1, clause 4.1.3). In practice, your privacy policy should say a chat assistant exists, which provider processes the messages and where. On the model side, as of December 2026 Anthropic says it doesn't use inputs or outputs from its commercial products, the API included, to train its models by default (Anthropic privacy centre). Check the equivalent terms for any widget vendor, and for whichever model provider sits behind it.
This isn't legal advice. If visitors could type health, financial or legal details into your bot, talk to a privacy lawyer before launch. Client data in ChatGPT or Claude goes deeper on PIPEDA, BC PIPA and what the vendors' business terms say.
Accessibility of the chat widget
Chat widgets fail accessibility checks often, because they float over the page and manage their own focus. The checks that matter most:
- Keyboard first. The launcher is a real button. Opening the panel moves focus into it; Escape closes it and returns focus to the launcher. Tab never gets trapped inside.
- Don't hide what has focus. WCAG 2.2 criterion 2.4.11, Focus Not Obscured (Minimum), is level AA. Its Understanding document names a user-opened chat window as content that can fail it, and says it can pass if it reflows the page or the user can reveal the focused item, for example by pressing Escape.
- Announce new messages without moving focus. The status messages criterion, 4.1.3 at level AA, points to
role="log"for sequential updates like a conversation, and warns against assertive announcements for anything that isn't urgent. - Labels and contrast. The input has a visible label, the send button has an accessible name, and the text meets contrast in your brand colours.
- Never open it automatically. A panel that slides up on load covers content on a phone and interrupts a screen reader mid-sentence.
- Watch the corner. On mobile, the launcher often sits on top of the cookie banner, a sticky call button or the last field of a form. Test at phone width, with the keyboard open.
Measuring whether anyone uses it
Opens are a vanity number. Track the chain instead:
- Widget opened.
- Question sent.
- Answered with sources, or handed off.
- Handoff completed: the form was actually submitted.
- Enquiry that became work.
Send the first four as analytics events from the widget, and count the same things on your server. The server count matters. In November 2026, about half of our own site's GA4 sessions looked like bots: direct visits with zero to one second of engagement. A dashboard alone can tell you a widget is popular when it isn't. Your endpoint's log is the source of truth for questions asked.
Before launch, write down your baseline (enquiries per month from the site) and the result that would make you take the bot down. After launch, look at three things monthly: the share of questions answered from sources, the handoffs that became enquiries, and the questions that keep coming back unanswered. That third list is your next content brief, and it's often worth more than the bot.
Our recommendation
- A brochure site with a handful of pages → don't add a bot. Write the FAQ, shorten the form, answer enquiries fast.
- A site with deep, well-organised content people struggle to search → a custom endpoint that answers only from that content, with a handoff, server-side logs and no tools.
- No developer time and an idea to test → a SaaS widget, but only one that answers solely from your content and lets you read every conversation. Treat it as an experiment with an end date.
- Anything that needs to act (book, change, look up an account) → not a public chat widget. Build it as a logged-in feature with its own review.
If you have a content-heavy site and a hunch that a bot would help, send us the site and the questions your customers ask. We'll tell you whether it's a chatbot, a better FAQ or neither, because that answer is where our AI integration work starts.
Keep reading
- How to hire an AI consultant: questions, scope, red flags
- AI agents for business: what to automate, what to keep
Work with Rough Works
Need a partner for your next site? We're a Vancouver-based digital agency building websites and AI-enhanced experiences for brands across Canada and the United States. Start a project →
Common questions
How do I add an AI chatbot to my website?
There are three routes. Turn on the AI answer feature in a platform you already use, if it has one; paste in a SaaS widget that reads your site or uploaded documents; or build a small server endpoint that searches your own pages and sends the best passages to a model API with strict rules. Whichever you choose, decide first what happens when it can't answer. The best default is a handoff to your contact form with the visitor's question already filled in. Never put an API key in the website's JavaScript.
Can I put my OpenAI or Claude API key in my website's JavaScript?
No. Anything in browser JavaScript can be read by every visitor, so a key there is effectively public and anyone can spend against it. Anthropic's API key documentation says to keep keys out of source control, client-side code and prompts. The browser should talk to your own server endpoint, which holds the key in an environment variable or a secrets manager and calls the model. That endpoint is also where you add rate limits, question length caps and logging, none of which you can enforce in the browser.
Do AI chatbots get small business websites more leads?
Sometimes, and you should measure it rather than assume it. A chatbot helps when your site has a lot of genuinely useful content that visitors struggle to search, such as product documentation or detailed policies. It doesn't help when the answers aren't on the site, the offer is unclear or enquiries go unanswered. Track questions asked, answers with sources, handoffs and handoffs that became enquiries, counted on your server as well as in analytics, because bot traffic inflates dashboards. Decide before launch what result would make you remove it.
Can an AI chatbot answer only from my own website content?
Yes, if it's built that way. The usual pattern is retrieval: your server searches your own pages for the passages most relevant to the question, sends only those to the model, and tells it to answer from them or reply with a fixed handoff word. Skip the model call entirely when the search finds nothing. No instruction makes a model perfectly obedient, so test with a fixed set of real questions, including ones it should refuse, and read the logs every week. Ask any widget vendor this question directly.
Do I have to tell website visitors they are talking to AI in Canada?
Canada's federal, provincial and territorial privacy regulators said in their joint generative AI principles of December 7, 2023 that organisations should make sure people know they're interacting with a generative AI tool. Labelling the widget plainly is the simple way to do that. Your privacy policy should also say that a chat assistant exists and which provider processes the messages. The principles are guidance rather than a statute, and this isn't legal advice. If visitors might share health, financial or legal details, ask a privacy lawyer before launch.
What should a website chatbot do when it doesn't know the answer?
Hand off, in one sentence, every time. The handoff says the bot can't answer from the site, then links to or opens your contact form with the visitor's question already filled in, and says who replies and when. Treat every other failure the same way: no matching content, a refusal, a cut-off response, an API error or an outage. That gives the feature one defined failure mode that still works when the model is unavailable. Read the handoffs weekly, because each one is a page to write or a question to refuse.
Are chat widgets bad for website accessibility?
They often are, because they float over the page and manage their own focus. Make the launcher a real button, move focus into the panel when it opens, let Escape close it and return focus, and never open it automatically. WCAG 2.2's Focus Not Obscured (Minimum) criterion, level AA, names a user-opened chat window as content that can hide focused elements. Announce new messages with a log role rather than moving focus, and test at phone width, where launchers often cover banners, call buttons and form fields.

