KMBCBUILDTUTORIAL

Your First AI

Chatbot

A hands-on, project-based tutorial. Build a working AI chatbot from scratch in about 30 minutes using the OpenAI or Anthropic API. Choose the code path or the no-code path. Either way, you ship something real today.

~30 min
Beginner
Ship today
What you will build

A conversational AI chatbot that takes user input, sends it to an AI API, and streams back intelligent responses. It remembers context, has a custom personality, and runs on the web.

{0_0}
my-chatbot
v1.0 \u00B7 ONLINE
Type a message...
SEND
Prerequisites
API key (OpenAI or Anthropic)free tier works
Basic coding knowledge (or choose no-code)JS/Python or visual builder
Node.js v18+ installed (code path)node --version to check
A code editorVS Code recommended
~30 minutesstart to ship
Choose your path

Two ways to build the same thing. Pick the one that matches where you are right now. You can always switch later.

OPTION B

Code Path

JavaScript + OpenAI/Anthropic API. Full control. You write every line. Best if you want to understand how things work under the hood.

Node.jsOpenAI SDKVercel
OPTION A

No-Code Path

Visual builders like Botpress, Voiceflow, or Coze. Drag-and-drop. Ship a working chatbot without writing a single line of code.

BotpressVoiceflowCoze
Step-by-step guide
Step 1 of 7

Get your API key

Head to platform.openai.com (or console.anthropic.com for Claude) and create an account. Navigate to the API keys section, generate a new secret key, and copy it somewhere safe. This key is how the API knows it’s you making requests. Never share it publicly or commit it to GitHub.

Codeenv
# Save your key in a .env file # Never commit this file to git! OPENAI_API_KEY="sk-proj-your-key-here" # Or for Anthropic Claude: ANTHROPIC_API_KEY="sk-ant-your-key-here"
System prompts & personality

The system prompt is the single most important piece of your chatbot. It defines personality, tone, boundaries, and behavior. Here are three examples showing how different prompts create completely different bots.

FRIENDLY TUTOR

You are a patient, encouraging coding tutor. Explain concepts using simple analogies. Always celebrate progress. Keep responses under 3 paragraphs. If you don't know something, say "Great question — let me look into that."

STRICT DEBUGGER

You are a senior engineer doing code review. Be direct and concise. Point out bugs, suggest fixes, and explain why. No fluff. Use code examples. If the code is good, say so briefly.

CREATIVE WRITER

You are a creative writing assistant with a witty, warm tone. Help brainstorm ideas, suggest plot twists, and give feedback on prose. Use vivid language. Ask clarifying questions before diving in.

Memory & context

AI APIs are stateless by default. Every request starts fresh. To make your chatbot remember the conversation, you manage context yourself by passing the full message history with each API call.

Short-term: Message Array

Store messages in an array during the session. Send the full array with every API call. Simple, effective, and what most chatbots use.

Sliding Window

Keep only the last N messages to stay within token limits. Older messages get dropped. Good for long conversations on a budget.

Persistent Memory

Save conversation history to a database (Supabase, Redis, etc.) and reload it when the user returns. Your bot remembers across sessions.

What comes next

You built a chatbot. Now level it up. Here are the three most common next moves.

INTERMEDIATE

Add RAG

Give your chatbot access to your own documents using retrieval-augmented generation. It answers questions about your data, not just general knowledge.

ADVANCED

Add Tools

Let your chatbot take actions: search the web, call APIs, query databases. Function calling turns a chatbot into an assistant that does things.

NEXT LEVEL

Build an Agent

Chain multiple AI calls together with decision-making logic. Agents can plan, execute, and iterate autonomously on complex tasks.

Frequently asked questions
How much does the API cost?
Do I need to know how to code?
Which API should I use — OpenAI or Anthropic?
Can I make the bot remember past conversations?
How do I keep my API key safe?
Can I use this to build a business?
BACK TO HOME
{0_0}
KMBC