Get your API key

Lesson 2 of 5

Your first chat, with the key on the server

A key with a spend limit, .env.local, a curl test, a server route plus chat page, and a system prompt with a clear job.

9 min Log in to open
One step at a time, like flipping pages.

By the end of this lesson you will have a working chat page on your laptop that talks to a real model through your own server route, with the key safely in .env.local and a system prompt that gives your bot a clear job.

You need: VS Code, Node.js and a coding agent (set up in First web MVP), an AllModelAPI account with some credit or a plan (Pricing), your 5 lines from lesson 1 · Time: 9 minutes

  1. Use a new key for every app. If it leaks, you revoke one key and nothing else breaks.

    1. Open API keys and click Create API key.
    2. Key name: exam-buddy-dev (use your bot's name).
    3. Model access: if you can choose models, pick only the ones this app will use, for example glm-5.3-flash. If it only offers All models, keep that; your server's allow-list in lesson 3 does this job too.
    4. Tick Allow streaming responses. You need it in lesson 3.
    5. Under Safety controls: set an Expiry date a few months away, a Spend limit of $5 Per month, and tick Notify me at 80% usage. Requests stop automatically when the limit is reached.
    6. Copy the key and keep it in your password manager. Do not paste it into WhatsApp, a screenshot or a chat with your AI agent.
    Why?

    A spend limit decides how bad a bad day can be. With $5 per month, even a leaked key cannot cost you more than about ₹450 before it stops.

Log in free to read the rest of this lesson

Every lesson is free. A free account unlocks all of them and saves your progress.

Still to come in this lesson:

  1. Start the project and add the key
  2. Test the key from the terminal
  3. Let the agent build the route and the chat page
  4. Give your bot a job: the system prompt
  5. Test it like a student
  6. Recap