Building a Chatbot with Claude and OpenAI: The AI Chat Project

A student-friendly tour of the AI Chat project: a terminal travel assistant built first with Anthropic's Claude, then with OpenAI, and then protected with a topic guardrail and moderation.

Published: 22 November 2026

Overview

Have you ever wondered how a chatbot remembers what you said two messages ago? Or how it can tell you today's weather when it was trained long before today?

The AI Chat project answers those questions by having you build a chatbot yourself. It's a hands-on course for students who know some TypeScript but haven't used an AI API before. You write the code, run it in your terminal and watch it work.

👉 Open the AI Chat project


What you'll build

A travel assistant that runs in your terminal. You ask for a holiday idea, and the assistant suggests a destination. You can then ask follow-up questions.

Later the assistant gets tools, so it can look up today's date, work out dates like "three weeks from now" and fetch the current weather for the place it recommends. In those lessons you pick the kind of holiday from a menu (a Christmas market, winter sun, a ski trip, a culture trip, a city break, or describe your own).

You build it twice: first with Anthropic's Claude, then with OpenAI. Seeing the same chatbot built two ways is the quickest way to learn what is essential and what is just a different spelling.


How a chat works

Here is the idea that surprises most people: the model has no memory. Every time you send a message, the API starts from nothing.

So how does a conversation work? Your code keeps the whole conversation in a list and sends the entire list every time. Think of it like a friend who forgets everything between texts, so before each reply you hand them the full message thread to re-read.

That's all the "memory" is. Here's the heart of the Claude version:

messages.push({ role: "user", content: input });

const response = await client.messages.create({
  model: model,
  max_tokens: 4000,
  messages,
  system: basicTravelSystemPrompt,
});
messages.push({ role: "assistant", content: response.content });

You add the user's message, send everything, then add the reply to the list so it's there next time. The system prompt tells the assistant who it is ("a helpful travel assistant"), and max_tokens caps the reply length.

This is covered in Module 1.


Giving the chatbot tools

A model can't know today's weather. But it can ask for it. That's what a tool is. The model never runs anything itself. It replies with a request, your code does the work, and you hand the result back.

The chatbot has three tools: get_weather, get_todays_date and add_time_period. The model can't know today's date, so it asks for it. It's also poor at calendar arithmetic, so add_time_period does the sums in your code. get_weather returns the weather right now, not a forecast.

The loop can go round several times for one question. For "what will the date be in 3 weeks?" the model asks for today's date, then asks your code to add three weeks to it, and then answers.


Same chatbot, two providers

The shape of the program is the same for both companies. Only the names change:

IdeaAnthropic (Module 1)OpenAI (Module 2)
System promptsysteminstructions
The conversationmessagesinput
Plain-text replytext blocks in contentoutput_text
Tool requesttool_use blockfunction_call item
Tool resulttool_result blockfunction_call_output item

The lessons use claude-sonnet-5-5 for Anthropic and gpt-6-luna for OpenAI.


Where the conversation lives

In most of the course, your code stores the conversation and resends it. That gives you full control: you can trim it, edit it or choose not to store anything on the provider's side.

OpenAI also offers a second way, the Conversations API, where OpenAI keeps the history and you send only the new items each time (your new message, or the tool results). The last lesson of Module 2 shows it as a small difference from the previous lesson, so you can see exactly what changes and when each approach makes sense.

Anthropic's Messages API only offers the first style, which is why Module 1 has one version.


Seeing how the model thinks

Some models think before they answer. You can ask them to show you a summary of that thinking, which is very handy when you want to know why the assistant chose a tool or an answer. Each module has a short lesson on it.

Neither company gives you the raw thought process. Both give you a summary, and you have to ask for it.

  • Anthropic (Module 1, lesson 4): add display: "summarized" to the thinking setting. On the newest Claude models the thinking is still returned by default, but its text is empty, so without this option there is nothing to print.
  • OpenAI (Module 2, lesson 5): add reasoning: { summary: "auto" } to the request. Without it, no summary comes back.

The summary lives in a different place in each API.

AnthropicOpenAI
Where the reasoning appearsthinking blocks inside the replySeparate reasoning items in the output
How to ask for itdisplay: "summarized"reasoning.summary
Without askingEmpty textNo summary

In both lessons the program prints the summary after every response, including the turns where the model asks for a tool. When you run the chat, the summaries appear between the lines that show which tool was called.


Keeping the chatbot on topic and safe

So far the assistant answers whatever it is sent. Ask your travel assistant to debug your Python script, or to reveal its instructions, and it will probably try. The last two modules put checks in front of it.

A topic guardrail (Module 3). A small, cheap model reads each message before the main model sees it and labels it ON_TOPIC or OFF_TOPIC. An off-topic message is blocked, with a short reason, and never reaches the main model or the conversation. If the guardrail itself breaks, the message is blocked too. You build it with both SDKs, then write a script that generates test messages and a runner that scores the guardrail on them, so you can measure how well it works instead of guessing.

Moderation (Module 4). The guardrail asks "is this about travel?", which isn't the same as "is this harmful?". A threat can be dressed up as a trip question, and a maths question is harmless but off topic. OpenAI's Moderation API is a free service that flags harmful content such as threats, harassment, hate and self-harm. It knows nothing about travel, so it lets the maths question through.

ModerationTopic guardrail
AsksIs this harmful?Is this about travel?
Built fromOpenAI's free Moderation APIA small chat model and a prompt
CatchesThreats, harassment, hate, self-harmOff-topic messages and prompt injection
Blind toTopic: a maths question passesSome harm dressed up as travel

Neither check replaces the other, so the chat runs both. Moderation goes first because it is free and fast. Either check can block a message.

The last lessons test both checks on generated cases. In the author's first test, each check alone missed some messages and the two together missed none. That is a small set with generated labels, so treat it as a first look, not proof. Moderation is an OpenAI service, so even the Anthropic version of this chat needs an OpenAI API key.


Getting started

You need:

  • Node.js 22 or later and pnpm
  • An Anthropic API key for Module 1
  • An OpenAI API key for Module 2 (and for moderation in Module 4, even with the Anthropic chat)
  • A free weatherapi.com key for the weather tool

Then follow the lessons in order:

  1. Setup: create the project and the shared code.
  2. Module 1: Chat with Anthropic
  3. Module 2: Chat with OpenAI
  4. Module 3: Guardrails
  5. Module 4: Moderation

Each lesson shows the code you need, so you can type it in and run it as you go. API calls are billed per use, so check each provider's pricing.


Summary

  • A chat API is stateless, so your code keeps the conversation and resends it.
  • A system prompt shapes how the assistant behaves.
  • Tool calling is a loop: the model asks, your code runs the tool, the model continues.
  • You can ask both APIs for a summary of the model's reasoning, but you have to opt in, and each provider returns it in a different shape.
  • Anthropic and OpenAI do the same job with different names, and seeing both makes the ideas clearer.
  • A topic guardrail and a moderation check ask different questions (is it about travel, and is it harmful), so a chatbot that needs both runs both, and you test them on generated cases.

The project is still growing, and more will be added over time. What's there now is a complete path from "hello" to a chatbot that uses tools and checks every message before answering it. Start here.