Nivå 3 — Advanced

Building chatbots

Learn to build a fully functional chatbot with conversation history, system prompt and streaming — in PHP and Python.
📅 21.05.2026 👁 56 views 🇳🇴 Les på norsk

What separates a chatbot from a simple API call?

A single API call is stateless — Claude remembers nothing between calls. A chatbot must keep track of the conversation history itself and send it with every API call. This is the most important concept to understand for chatbot development.

💡 How conversation history works:
Round 1: Send [user: "Hi"] → get answer
Round 2: Send [user: "Hi", assistant: "Hello!", user: "What is your name?"] → get answer
Round 3: Send all previous messages + new message → get answer

Claude "remembers" because you send the full history each time.

Key design choices

📏
History length — keep the last 10–20 turns. Older context is rarely necessary and costs tokens.
🛡️
Never send the API key to the frontend! All communication with the Anthropic API must happen server-side.
Loading indicator — always show that something is happening while Claude responds. Users leave pages that appear frozen.
"A good chatbot remembers enough to be useful — and forgets enough to keep costs down." — On the balance in conversation history
All good is now coming to me, and I receive it with gratitude.
— Florence Scovel Shinn

🎯 Test your knowledge

Test yourself — completely optional, but fun! 🎯

Question 1 of 3

Question 1 of 3

Why must a chatbot send the full conversation history in every API call?

The Claude API is stateless — Claude remembers nothing between calls. The history must be sent along for Claude to have context.

Question 2 of 3

Question 2 of 3

Where should communication with the Anthropic API always happen?

Always server-side — never from the frontend. The API key must never be exposed in JavaScript or HTML that the user can see.

Question 3 of 3

Question 3 of 3

How many message rounds should you typically keep in the history?

The last 10–20 turns are usually enough — older context is rarely necessary and increases token costs unnecessarily.
Share:

Read also