Configuring Model Responses with Instructions and Sampling Parameters
This lesson explains how request parameters control the way a deployed model responds. The same model can produce terse factual answers or varied creative text depending on its instructions and sampling settings.
Learning outcomes
After completing this lesson, you will be able to:
- Describe how instructions and maximum output tokens shape a response.
- Explain how temperature and top_p affect randomness.
- Describe how the reasoning effort setting works for reasoning models.
- Identify where parameters are set in the playground and in code.
Instructions and output length
The system message, called instructions in the Responses API and the Foundry playground, sets the model's role, rules and output format for the conversation, as explained in the prompt engineering module. Maximum output tokens (max_output_tokens in the Responses API) caps the length of the response, which controls cost and latency; if the limit is too low, responses are cut off. Stop sequences end generation when the model produces a specified string, which is useful for structured formats.
Sampling parameters
Temperature, usually between 0 and 2, controls randomness. Values near 0 suit extraction, classification and factual answers that should be consistent; values around 0.7 to 1 suit creative writing and brainstorming. Top_p limits sampling to the most likely tokens whose probabilities add up to p; a value of 0.1 restricts the model to the top 10% of probability mass. Adjust temperature or top_p, not both.
Some APIs also offer frequency and presence penalties, which discourage repeating the same tokens or topics, and a seed that makes outputs more repeatable for testing.
Set the temperature
Reasoning models
Reasoning models such as the GPT-5 family accept a reasoning effort setting (for example minimal or none, low, medium or high) that trades answer quality on hard problems against latency and cost. They restrict sampling parameters: temperature and top_p are not supported or are supported only at the lowest reasoning effort, depending on the model. The model card lists the parameters each model supports.
Pick the parameter
Where parameters are set
In the Foundry portal playground, parameters appear as controls next to the chat. In code, they are arguments of the request, as in this Responses API call.
response = openai.responses.create(
model="chat-model", # deployment name
instructions="You write short, friendly product descriptions.",
input="Describe a waterproof hiking jacket.",
max_output_tokens=200,
temperature=0.9, # creative variety (non-reasoning models)
)
print(response.output_text)Tuning for consistency
An application extracts the order number and complaint category from customer emails. Testing shows that the same email sometimes produces different categories, and responses occasionally include an unwanted explanation.
The task needs consistency and a fixed format.
Lowering the temperature towards 0 reduces variation, an instruction that defines the exact output format and lists the allowed categories removes ambiguity, and a structured output schema guarantees parseable JSON. Raising maximum output tokens would allow longer explanations, the opposite of what is needed.
What happens if max_output_tokens is set too low?
Show answer
Responses are cut off before they are complete. The setting limits response length and cost.
Exam Tips
Remember for the exam
- Low temperature for consistent, factual output; higher temperature for creative variety.
- max_output_tokens limits response length and cost; too low a value truncates responses.
- Adjust temperature or top_p, not both.
- Reasoning models use reasoning effort and restrict sampling parameters.