Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/openai/openai-cookbook/llms.txt

Use this file to discover all available pages before exploring further.

GPT-5 is OpenAI’s newest flagship model, representing a substantial leap forward in agentic task performance, coding, raw intelligence, and steerability. While it performs strongly out of the box, getting the most from GPT-5 — especially in production — requires understanding how the model differs from its predecessors and how to tune prompts accordingly.

What’s new in GPT-5

GPT-5 introduces several capabilities and API parameters that did not exist in GPT-4o or GPT-4.1:

Reasoning effort

A reasoning_effort parameter (low, medium, high) controls how deeply the model thinks before responding. Higher effort improves accuracy on complex tasks; lower effort reduces latency and cost.

Verbosity control

A new verbosity parameter influences the length of the model’s final answer independently of its thinking depth. Useful when you want terse status updates but verbose code output.

Responses API

GPT-5 integrates with the Responses API, which persists reasoning across tool calls. This unlocks more efficient and intelligent agentic flows compared to Chat Completions.

Agentic eagerness

GPT-5 is trained to be thorough when gathering context in agentic settings. Its proactivity is configurable via prompt and reasoning_effort.

Making your first GPT-5 API call

The API surface is the same as earlier models. Start with gpt-4o as the model ID in existing code and swap it for gpt-5 when you are ready to adopt the new model:
from openai import OpenAI

client = OpenAI()

response = client.chat.completions.create(
    model="gpt-4o",  # swap to "gpt-5" when ready
    messages=[
        {
            "role": "system",
            "content": "You are a helpful assistant. Answer concisely and accurately.",
        },
        {
            "role": "user",
            "content": "Explain the difference between a mutex and a semaphore.",
        },
    ],
)

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

Writing effective system prompts

GPT-5 follows instructions with high precision — which is a strength, but also means that vague or contradictory prompts have more impact than with earlier models. A prompt that seemed to work well enough with GPT-4o may produce inconsistent or unexpected behavior with GPT-5 because the model takes every instruction literally.

Resolve contradictions before they reach the model

The following system prompt contains two contradictions that impair GPT-5 performance:
# Bad — contradictory instructions

Always look up the patient profile before taking any other actions.

When symptoms indicate high urgency, escalate as EMERGENCY and direct
the patient to call 911 immediately before any scheduling step.

For high-acuity cases, auto-assign the earliest same-day slot without
contacting the patient as the first action to reduce risk.

Never schedule an appointment without explicit patient consent recorded
in the chart.
The model spends reasoning tokens trying to reconcile “look up profile first” with “call 911 before any scheduling step”, and “never schedule without consent” with “auto-assign without contacting the patient”. These contradictions degrade both latency and accuracy. Fixing it:
# Better — explicit priority ordering

Always look up the patient profile before taking any other actions,
EXCEPT in emergency cases (see below).

When symptoms indicate high urgency:
1. Direct the patient to call 911 immediately.
2. Do NOT perform a profile lookup — skip straight to emergency guidance.

For high-acuity (Red/Orange) non-emergency cases:
- Inform the patient of your intended action first.
- Auto-assign the earliest available same-day slot only after informing them.
- Tentatively hold a slot if consent status is unknown and request confirmation.

Never schedule an appointment without explicit patient consent, except
in the emergency case above.
Use OpenAI’s prompt optimizer tool to identify contradictions and vague instructions in existing prompts before migrating to GPT-5.

Structure with XML tags

GPT-5 responds well to prompts that use XML-style tags to separate distinct categories of instruction:
<persistence>
You are an agent. Keep going until the user's query is completely resolved
before yielding back to the user. Only terminate your turn when you are
sure the problem is solved.
</persistence>

<tool_use>
If you are unsure about file content or codebase structure, use your tools
to read files and gather relevant information. Do NOT guess or make up an answer.
</tool_use>

<planning>
Plan extensively before each function call. Reflect on the outcomes of
previous calls before proceeding.
</planning>

Controlling reasoning effort

Use reasoning_effort to trade latency for accuracy. The default is medium.
from openai import OpenAI

client = OpenAI()

# High reasoning for complex multi-step problems
response = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Refactor this 500-line module to reduce cyclomatic complexity."}],
    # reasoning_effort="high",  # uncomment when using gpt-5
)

# Low reasoning for latency-sensitive tasks
fast_response = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Translate 'hello world' to Spanish."}],
    # reasoning_effort="low",  # uncomment when using gpt-5
)
Complex multi-step coding tasks, long-context analysis, agentic workflows with ambiguous goals, and tasks where correctness matters more than speed.
The default. Suitable for most production tasks including question answering, summarization, and structured output generation.
Latency-sensitive tasks, simple transformations, current users upgrading from GPT-4.1 who need similar speed characteristics. At minimal reasoning, use more explicit prompts — include planning instructions and persistence reminders that the model would otherwise handle internally.

Controlling agentic eagerness

GPT-5 is trained to be thorough in agentic contexts. You can steer how proactive it is. Reduce eagerness (faster, fewer tool calls):
<context_gathering>
Goal: Get enough context fast. Parallelize discovery and stop as soon as
you can act.

Early stop criteria:
- You can name exact content to change.
- Top hits converge (~70%) on one area or path.

Depth:
- Trace only symbols you will modify. Avoid transitive expansion unless necessary.

Loop:
- Batch search → minimal plan → complete task.
- Search again only if validation fails. Prefer acting over more searching.
</context_gathering>
Increase eagerness (more autonomous, fewer clarifying questions):
<persistence>
You are an agent. Keep going until the user's query is completely resolved
before ending your turn. Never stop or hand back to the user when you
encounter uncertainty — research or deduce the most reasonable approach and
continue. Document any assumptions you make for the user after you finish.
</persistence>

Using the Responses API for agentic tasks

For multi-turn agentic workflows, switch from Chat Completions to the Responses API. Reasoning is persisted between tool calls, improving both accuracy and efficiency:
from openai import OpenAI

client = OpenAI()

response = client.responses.create(
    model="gpt-4o",  # swap to "gpt-5" when ready
    input=[{"role": "user", "content": "Analyze this codebase and suggest optimizations."}],
    # Pass previous_response_id on subsequent turns to retain reasoning context:
    # previous_response_id=previous_response.id,
)

print(response.output_text)
Switching to the Responses API with previous_response_id has produced statistically significant accuracy improvements in internal evaluations (e.g., Tau-Bench Retail scores from 73.9% to 78.2%).

Migrating from GPT-4o or GPT-4.1

GPT-5 follows instructions more literally and precisely than earlier models. Prompts that worked with GPT-4o by relying on the model to “infer intent” may need to be made more explicit.
1

Audit for ambiguous instructions

Phrases like “do not include irrelevant information” are interpreted loosely by GPT-4o but may cause GPT-5 to omit details you want kept. Replace them with specific criteria: “Only include facts directly related to topic X. Exclude personal anecdotes and historical context.”
2

Remove contradictions

Review your prompt for instructions that conflict. GPT-5 expends reasoning tokens trying to reconcile them rather than picking one at random.
3

Add explicit stop and escalation conditions

For agentic prompts, state clearly when the model should stop, when it should ask the user, and when it should proceed under uncertainty.
4

Use reasoning effort to match previous latency

If GPT-4o speed was a requirement, start with reasoning_effort="low" on GPT-5 and increase only where accuracy requires it.
5

Test with structured outputs

GPT-5’s instruction adherence makes it excellent for structured output tasks. If you were using workarounds to enforce JSON or other formats, try simplifying them.

Verbosity and formatting

By default, GPT-5 in the API does not format output in Markdown. To enable it:
- Use Markdown only where semantically correct: inline code, code fences, lists, tables.
- Use backticks to format file, directory, function, and class names.
- Use \( and \) for inline math, \[ and \] for block math.
You can also set verbosity globally and override it per context:
Use low verbosity globally. When writing code or code tool output, use
high verbosity: prefer readable, maintainable solutions with clear names
and comments where needed.
If Markdown adherence degrades over a long conversation, appending a formatting reminder every three to five user messages reliably restores it.

Build docs developers (and LLMs) love