Back to blog

AI for beginnersGuide

System prompt and temperature: what they do and how to set them

What the system message and temperature do in an OpenAI-compatible request, with Python and curl examples you can send to a CheapTokens model.

By CheapTokens TeamPublished Updated 6 min read

Chat request diagram: a system message with the rules, a user message with the task, and a temperature dial
On this page
  1. What is a system prompt?
  2. How to write a useful system prompt
  3. What does temperature do?
  4. Send a request with both
  5. See temperature at work
  6. Which model to try it on
  7. If it does not work
  8. Next step

A system prompt is a message with the role system that tells the model how to behave in every answer: who it is, which format to use, what to avoid. Temperature is a number, usually between 0 and 2 (the range depends on the model), that sets how much the wording may vary: low values give focused, repeatable answers, high values give more varied ones. Both go into the same Chat Completions request, which you send to https://api.cheaptokens.dev/v1.

Below: what each one is, which values to start with, and a request you can run in Python or curl. If you have not sent a request yet, start with your first API request with CheapTokens.

What is a system prompt?#

A chat request is a list of messages, and every message has a role. The Chat Completions reference lists four: system, user, assistant and tool (DeepSeek API reference, checked 22 October 2026). For a first request you need three:

  • system — standing instructions from you, the developer. The model treats them as the rules of the conversation.
  • user — what the person asks or provides in this turn.
  • assistant — the model's earlier answers. You add them yourself when you continue a conversation.

A system message needs role set to system and content as a string. The name field is optional.

json
"messages": [
  {"role": "system", "content": "You are an editor. Rewrite the user's text to be shorter and friendlier. Return only the rewritten text."},
  {"role": "user", "content": "Send me the report by tonight or I will be upset."}
]

The system message goes first. The user message is the actual task.

How to write a useful system prompt#

  • Say what the model is doing in one sentence: "You are an editor", "You classify support tickets".
  • State the output format: "Return only the rewritten text", "Answer in two sentences", "Reply with valid JSON".
  • Give rules as short, direct sentences. Several clear lines work better than one long paragraph.
  • Keep it short. The system prompt is sent with every request and counted as input tokens, so a long one is paid for every time. How input and output are billed is in input vs output tokens.

What does temperature do?#

A model picks each next token from a set of likely candidates. Temperature controls how strictly it sticks to the most likely one. According to the DeepSeek API reference (checked 22 October 2026), temperature accepts values from 0 to 2 with a default of 1: higher values give more random output, lower values give more focused, deterministic output. Ranges differ between models: DeepSeek documents 0 to 2, Z.ai documents 0 to 1 for GLM-5.3 (both checked 22 October 2026), so values from 0 to 1 are safe on both. Check the range for your model in the docs.

Starting points that work for most tasks. They are rules of thumb, not guarantees:

Task Start with
Extraction, classification, code, strict formats 0 to 0.3
Q&A, summaries, rewriting 0.3 to 0.7
Brainstorming, names, creative text 0.8 to 1

Three things to know:

  1. Low temperature is more repeatable, not identical. Do not rely on byte-for-byte equal answers.
  2. Change temperature or top_p, not both. This is the DeepSeek recommendation; top_p is a second sampling parameter with a default of 1. Leave it alone while you learn.
  3. Some modes ignore temperature. The DeepSeek reference says temperature has no effect in thinking mode, and that top_p is fixed at 1.0 in non-thinking mode. If you change a value and see no difference, check the mode of the model first.

Send a request with both#

Set the key as an environment variable, so it never ends up in code (see what is an API key and how to store it safely). Take the exact model id from the CheapTokens docs: different providers name the same model differently. This example uses MiniMax-M2.7.

python
import os
from openai import OpenAI

client = OpenAI(
    base_url="https://api.cheaptokens.dev/v1",
    api_key=os.environ["CHEAPTOKENS_API_KEY"],
)

response = client.chat.completions.create(
    model="MiniMaxAI/MiniMax-M2.7",
    messages=[
        {"role": "system", "content": "You are an editor. Rewrite the user's text to be shorter and friendlier. Return only the rewritten text."},
        {"role": "user", "content": "Send me the report by tonight or I will be upset."},
    ],
    temperature=0.3,
    max_tokens=1000,
)

print(response.choices[0].message.content)
print(response.choices[0].finish_reason)

The same request with curl:

bash
curl https://api.cheaptokens.dev/v1/chat/completions \
  -H "Authorization: Bearer $CHEAPTOKENS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "MiniMaxAI/MiniMax-M2.7",
    "messages": [
      {"role": "system", "content": "You are an editor. Rewrite the user'\''s text to be shorter and friendlier. Return only the rewritten text."},
      {"role": "user", "content": "Send me the report by tonight or I will be upset."}
    ],
    "temperature": 0.3,
    "max_tokens": 1000
  }'

What you should see: a short, friendlier version of the sentence and stop as the finish_reason. If the finish_reason is length, the answer hit the max_tokens limit; see why an AI answer stops mid-sentence.

See temperature at work#

The best way to understand temperature is to ask the same question several times. This loop sends one short request three times at 0 and three times at 1, using the client from the example above:

python
for temp in (0, 1):
    print("temperature", temp)
    for _ in range(3):
        r = client.chat.completions.create(
            model="MiniMaxAI/MiniMax-M2.7",
            messages=[
                {"role": "system", "content": "Answer with one word."},
                {"role": "user", "content": "Name a fruit."},
            ],
            temperature=temp,
            max_tokens=500,
        )
        print(" ", r.choices[0].message.content)

At 0 the three lines are usually the same word; at 1 you will usually see more different words. Models that reason before answering may spend part of max_tokens on that reasoning, so keep the limit generous even for a one-word answer. Then change only the system prompt (for example, "Answer with one word, in French") and run it again: the rules in the system message apply at every temperature.

Such experiments are small. For a rough idea, here is the cost of 100 requests of about 120 input and 80 output tokens each (an example workload; the token counts depend on your prompts):

Model Per request 100 requests OpenRouter, 100 requests
GLM-5.3-Flash $0.0000056 $0.00056 $0.0011
DeepSeek-V4-Flash $0.0000098 $0.00098 $0.0018
MiniMax-M2.7 $0.000018 $0.0018 $0.0132

120 input and 80 output tokens per request. Prices per 1M tokens are current and change together with our tariffs; the OpenRouter column shows reference prices for the same workload.

Which model to try it on#

  • MiniMax-M2.7 is a good first choice for many short test requests, and you can reuse the same system prompt on it to compare answers: 180K context, up to 8,192 output tokens, cheaper than OpenRouter's reference price on both sides. Current price: input $0.05, output $0.15 per 1M tokens.

One balance covers all of them, so switching the model is a one-line change of model. All current prices are on the pricing page.

If it does not work#

  • 401 or an authentication error: the key is missing, mistyped or the environment variable is not set in this terminal. Check echo $CHEAPTOKENS_API_KEY.
  • Model not found: copy the model id from the docs exactly, including the prefix.
  • An error about an invalid parameter: keep temperature inside the range your model supports (0 to 1 is safe) and pass numbers, not strings.
  • The model ignores your rule: make it one short, direct sentence, move it to the top of the system message, and repeat the exact format you want.
  • Changing temperature changes nothing: you may be using a mode that ignores it (see above), or the answer is so constrained ("one word", "valid JSON") that few variations exist.
  • Answer is cut off: raise max_tokens; the max_tokens guide explains how.

Next step#

Put one clear rule in the system message, pick a temperature from the table, and run the loop above on your own task. When the result is what you want, keep the system prompt short and reuse it. Get a key and check current prices in the docs.