Get your API key

Lesson 1 of 5

How an AI chat app works

Browser, your server and the model API; why the key stays on the server; messages and roles; what a chat really costs in tokens.

8 min Free
One step at a time, like flipping pages.

By the end of this lesson you will know the three parts of every AI chat app, why the API key must stay on the server, what one request to a model contains, and what a chat really costs.

You need: nothing installed yet, only a notebook or notes app for your bot idea · Time: 8 minutes

  1. In this course you build your own AI chat web app. Two examples we use: Exam Buddy, a study helper for a coaching class's Class 10 students, and Rangrez Crafts Helper, a FAQ bot for a Jaipur handicraft shop that answers "Do you ship to Pune?" at 11 pm.

    Every chat app like these has three boxes:

    1. The browser. The chat page: a text box, a Send button, the messages. It runs on the user's phone or laptop.
    2. Your server. A small piece of code you own, called a route (an address like /api/chat that runs code on a server instead of in the browser). It receives the message, adds your secret API key and your instructions, and calls the model.
    3. The model API. The LLM (large language model, the AI that writes text) runs at a provider. In this course that is AllModelAPI, at https://api.allmodelapi.com/v1. It writes the answer and bills the key that called it.
    Three boxes in a row: the browser with the chat page, your server with the API key inside, and the model API that writes the answer. Arrows go both ways. A dashed note under the browser says no key here.
    The browser talks only to your server. Only your server talks to the model, with the key.
    Why?

    When something breaks later, the first question is always "which box?". A blank page is the browser, a 401 error is the key on your server, a slow answer is usually the model. Knowing the boxes turns panic into a short search.