DevHubTools Robot Mascot
DevHubTools
Back to AI Agent Engineering
AI Agent EngineeringDifficulty: Beginner 5 min read

Your First LLM API Call: Messages, Tokens and Limits

Make one model call from Node.js with any provider and understand every part of it: the messages list, the system prompt, tokens, output limits and why answers vary.

By Avnish Yadav

Prerequisites: Node.js 20 or later An API key from any LLM provider
Published · Updated

Every AI agent, chatbot and "AI feature" is built from one small thing: an API call that sends text to a model and gets text back. In this lesson you'll make that call yourself and learn what each part does, so the later lessons (structured output, tool calling, guardrails) make sense.

You'll need: Node.js 20 or later and an API key from any LLM provider. You'll write one small function, askModel, with an adapter for your provider. The rest of this track only talks to that function, so you can switch providers later by changing one file.

STEP 1 OF 9
STEP 01

What a model call actually sends

A chat model does not remember anything between calls. Each request carries the whole conversation:

  • a system prompt: standing instructions such as "You are a code reviewer. Answer in short bullet points.";
  • a list of messages, each with a role (user or assistant) and content;
  • settings such as the model name and the maximum length of the answer.

The model reads all of it and writes the next assistant message. To continue a conversation, you append its answer and your next question, and send the whole list again. Every major provider works this way; only the field names differ.