Messages, System Prompts and Parameters

Updated · 6 min read
mediumPython 3.13aiapipythonsystem-promptsparameters

Request parameters are the settings in a model API call that control what the model sees and how it replies. The messages carry the conversation, the system prompt sets the rules, and settings such as max_tokens limit the reply. Getting these right is most of the work of a reliable AI feature.

Messages Carry the Whole Conversation

A model API is stateless: it doesn't remember earlier calls. To continue a conversation, your code sends every earlier turn again, in order, as a list of messages.

Rules, conversation and settings
RoleDescription
userIt is used for what the person said, or for results your code sends back
assistantIt is used for what the model said earlier in the conversation
system (the helper's system argument)It is used for rules and facts that apply to the whole conversation; the helper sends it as the first message

Example: Continuing a Conversation

Python
from model_api import ModelClient
 
client = ModelClient()
 
SYSTEM = (
    "You are Campus Helper, a school assistant. Use only these facts. "
    "Fees: lab $45, due September 30; field trip $30, due October 15. "
    "If the facts don't answer the question, say so and suggest the school office."
)
messages = [
    {"role": "user", "content": "How much is the field trip fee?"},
    {"role": "assistant", "content": "The field trip fee is $30, due October 15."},
    {"role": "user", "content": "Can I pay it in two parts?"},
]
 
reply = client.chat(messages, system=SYSTEM, max_tokens=300)
print(reply.text)

Example output. Produced by an AI model on November 16, 2026, to show the shape; not captured from a live call.

Output
The fee information doesn't say whether the $30 field trip fee can be split into two payments. Please ask the school office; they can tell you what's allowed.

Explanation: The messages list holds the first question, the model's earlier answer and the new question, so the model knows "it" means the field trip fee. The system prompt's last rule makes it admit what the facts don't cover instead of guessing.

Settings That Shape the Reply

ParameterDescriptionExample
max_tokensIt is used to cap reply length; a cut-off reply has finish_reason lengthmax_tokens=300
stopIt is used to end the reply when the model writes a chosen textstop=["END"]
temperatureIt is used to set how varied the wording is: low for steady answers, higher for variety. Some models don't accept it, so check your provider's documentationtemperature=0.2

The helper passes any extra setting straight into the request, so client.chat(messages, temperature=0.2) works with providers that support it. Some providers also offer a setting for how much the model reasons before answering; its name differs between providers.

Example: A Reply Cut Off by the Length Limit

Python
from model_api import ModelClient
 
client = ModelClient()
reply = client.chat(
    [{"role": "user", "content": "Explain how school fee waivers usually work."}],
    max_tokens=20,
)
print(reply.text)
print("Finish reason:", reply.finish_reason)

Example output. Produced by an AI model on November 16, 2026; not captured from a live call.

Output
A fee waiver lets a family skip or reduce a school fee when paying it would be a
Finish reason: length

Explanation: With only 20 tokens allowed, the reply stops mid-sentence and finish_reason is length. Check for this in your code: a cut-off answer can mislead, so raise the limit or ask for a shorter answer in the prompt.

Common Mistakes

Forgetting earlier turns. Without them, "Can I pay it in two parts?" has no meaning.

Putting rules in the user message. Standing rules belong in the system prompt, where they apply to every turn.

Sending a setting the model doesn't support. Some models reject temperature or other settings, and the request fails with an error. Check your provider's documentation, and control style through the prompt where you can.

Interview Corner

Why must you resend the conversation on every call?

Model APIs are stateless: each request is independent, so the model only knows what that request contains. Your code stores the history and sends it each time.

What is the difference between max_tokens and asking for a short answer?

max_tokens is a hard cutoff that can stop the reply mid-sentence; asking for brevity in the prompt makes the model plan a short, complete answer. Use both: a clear instruction, and a limit with room to spare.

Practice

Exercise: a three-turn chat. Write a loop that reads questions from the keyboard, appends each question and each reply to messages, and prints the reply. Ask about the lab fee, then "when is it due?", and check that the second answer knows what "it" means.

Check your understanding:

  1. What does a stateless API mean for your code?
  2. Where do standing rules belong?
  3. What happens when max_tokens is too small?

Quick check: messages and parameters

4 questions
1Why does the example send the earlier question and answer again?
2Where should "use only these facts" go?
3What was the finish reason when max_tokens was 20?
4What does temperature control, on models that accept it?

Key Takeaways

Quick reference

NeedParameter
Continue a chatResend messages with every turn
Set rulessystem=...
Cap lengthmax_tokens=...
End at a markerstop=[...]
Steadier or more varied wordingtemperature=... (if the model accepts it)

Was this tutorial helpful?

Lesson 84 of 186