How to add an AI chatbot to your website that handles orders
The problem
You want visitors to ask "where is my order?" or "change my booking" in plain language, and get a real answer from your order system instead of a generic reply.
The approach
Never put the AI key in the browser. The widget talks to your backend. The backend calls the AI API and, when needed, your order API.
- Build the chat widget (HTML/JS or React) that posts messages to
/chaton your server. - On the server, send the conversation to the AI model together with a short system prompt that sets the rules (what it may do, when to hand over to a human).
- Give the model tools (function calling) such as
get_order_status. Your server runs the tool against your order API and returns the result to the model. - Require confirmation before any change or cancellation, and log every action.
Minimal backend call
import requests, os
r = requests.post(
"https://api.anthropic.com/v1/messages",
headers={"x-api-key": os.environ["ANTHROPIC_API_KEY"],
"anthropic-version": "2023-06-01",
"content-type": "application/json"},
json={"model": "MODEL_NAME", "max_tokens": 500,
"system": "You help customers with orders. Ask before changing anything.",
"messages": [{"role": "user", "content": "Where is order 123?"}]})
print(r.json())Replace MODEL_NAME with a current model from the provider documentation. Keep the key in an environment variable.
Safety checklist
- Identify the customer before showing order data.
- Let the model read data through tools only. Do not paste the whole database into the prompt.
- Rate limit the endpoint.
- Always offer a way to reach a human.
