Call a language model over HTTP, keep conversation memory, stream the reply, protect your API key behind a backend, handle errors and cost, and ship a web chat UI — built step by step with Node.js.
You have used AI chat apps. Now you will build one. This series shows how any app talks to a large language model (LLM): it sends an HTTP request with the conversation so far, and the model sends text back. That is the whole trick. Once you can do it, you can add AI to a Telegram bot, a school project, a customer-support page, or a backend service at work.
You will learn the parts that tutorials often skip. A model has no memory, so your code must keep the conversation and resend it. Replies arrive faster if you stream them word by word. An API key is money, so it must never reach the browser; it lives on your own backend, and the browser talks to your backend instead. Real networks fail, so you need timeouts, retries, and a spending limit. And a chat is only useful if people can open it, so you will finish with a small web page.
Across eight chapters you build chatlab: an API client, a
conversation manager, a streaming parser, a command-line chatbot, a
secure backend proxy, a retry and budget layer, and a browser chat UI.
To keep everything free and runnable anywhere, chapter 1 gives you a
tiny mock LLM server (about 90 lines, no dependencies) that speaks
the same style of API as a hosted model. Every chapter works against it
with no account, no key, and no bill. Then, with two environment
variables, the same code can talk to a real provider when you are ready.
You need the basics of JavaScript, including async/await, from
JavaScript & TypeScript
Fundamentals, and the
terminal from Command Line Basics. It
helps to have read How LLMs Work (for
Developers), especially the chapters on
tokens and context
windows, because
this series is where those ideas become code. You need
Node.js (the LTS version) and a code editor such
as Visual Studio Code.
Every chapter ends with a Quick Review: Common Questions section: short, honest answers to the questions students and developers most often ask about that chapter's topic.