Typorithm · easy

System & User Prompts

prompt-basicsllmsystem-promptmessagesmodel
Saved on this device
Full lesson · 8 learning steps Open any exercise for focused practice
1

Step 1 of 8 · intro card

Learn System & User Prompts

0%

Prompt Engineering

A Claude request sets a system prompt to define the model's role, passes a messages list of alternating user/assistant turns, picks a model id, and caps the reply length with max_tokens.

The system prompt is separate from the conversation: it sets the model's persona, tone, and rules. "You are a terse expert." steers every reply without being part of the visible chat.

messages is a list of turns that alternate between user and assistant. The first turn is always a user turn; the model produces the next assistant turn as its response.

You choose the model per request (claude-opus-4-8 is the most capable) and bound the output with max_tokens so a reply can't run on indefinitely.

01

system sets the model's role and behavior.

02

messages holds alternating user/assistant turns.

03

model picks the model; max_tokens caps the reply.

import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic();
const msg = await client.messages.create({
  model: "claude-opus-4-8",
  max_tokens: 1024,
  system: "You are a terse expert.",
  messages: [{ role: "user", content: "Explain TLS." }],
});

Read the implementation

Connect each part of the code to the concept before you type.

1. Import the SDK

The official @anthropic-ai/sdk package gives you the typed Anthropic client used to call Claude.

import Anthropic from "@anthropic-ai/sdk";

2. Choose the model

claude-opus-4-8 is the most capable model; you pick the model per request by its id.

model: "claude-opus-4-8",

3. Cap the output

max_tokens caps how many tokens the model may generate in its reply.

max_tokens: 1024,

4. System prompt

The system prompt sets the model's role and behavior for the whole conversation.

system: "You are a terse expert.",

5. User turn

messages is the list of alternating user/assistant turns; here it holds a single user question.

messages: [{ role: "user", content: "Explain TLS." }],

A complete learning loop

01

Understand

Read the concept map and follow the code breakdown.

02

Reconstruct

Type the implementation, repair mistakes and work through every recall exercise.

03

Verify

Use the final check without hints; revisit weak concepts in short practice sessions.

System & User Prompts: Lesson & Practice · Typorithm | ApplyDjinn