
OpenAI Prompting Best Practices
A comprehensive guide to prompting and building with OpenAI's models and APIs.
You can read the contents and the first 2,000 characters.
Free accounts get the whole book.
- By OpenAI
- 62 chapters
- Updated Nov 1, 2026
- 73 readers
What’s inside
- Personality
- Goal
- Success criteria
- Constraints
- Output
- Stop rules
From the first page
A comprehensive guide to prompting, model selection, and API usage for the July 2026 OpenAI model lineup.
OpenAI's model lineup has consolidated into a clear hierarchy. The GPT-5.x family now dominates both the consumer product (ChatGPT) and the developer API, with earlier generations on a deprecation glide path toward shutdown. The flagship models share a common architecture that supports function calling, web search, file search, computer use, and reasoning at adjustable effort levels (none / low / medium / high / xhigh / max / ultra). Meanwhile, a set of specialized models handles image generation, real-time audio, autonomous coding, and video.
The GPT-5.6 family (GA July 9, 2026). The headline change since the spring is the GPT-5.6 generation, which reached general availability on July 9, 2026 (following a limited preview on June 26). GPT-5.6 introduces a naming convention worth internalizing: the number identifies the generation, while the names — Sol, Terra, Luna — identify durable capability tiers that can advance on their own cadence. Sol is the flagship for the hardest problems (deep coding sessions, complex agentic work, security research); Terra is the everyday workhorse, competitive with GPT-5.5 at roughly half the cost; Luna delivers strong capability at OpenAI's lowest cost. All three opened to everyone — via both the API and Codex, with API-key authentication — on the July 9 GA date. The launch also introduced two new reasoning-effort tiers (max and ultra, described below) and ChatGPT Work, an agent built to carry out whole jobs rather than answer single questions.
Preview · 2,000 of 124,087 characters
Contents
- 01OpenAI Prompting Best Practicesp.1
- Chapter 1: Introduction & Model Overviewp.1
- Chapter 2: Universal Prompting Techniquesp.1
- 02Personalityp.2
- 03Goalp.3
- 04Success criteriap.4
- 05Constraintsp.5
- 06Outputp.6
- 07Stop rulesp.7
- Chapter 3: GPT-5.5 Best Practicesp.7
- 08Retrieval rulesp.8
- Chapter 4: GPT-5.4 Family Best Practicesp.8
- Chapter 5: GPT-5.3-Codex Best Practicesp.8
See all 62 parts
- 09Good: batch readsp.9
- 10Bad: sequential readsp.10
- Planning Strategyp.10
- Compaction for Long Sessionsp.10
- Tool Preferencesp.10
- Personality Variantsp.10
- Practical Example: Codex System Promptp.10
- 11Autonomyp.11
- 12Explorationp.12
- 13Qualityp.13
- 14Planningp.14
- Chapter 6: Reasoning Models -- o3p.14
- 15Decision framework for reasoning effortp.15
- Chapter 7: Responses API & Conversation Managementp.15
- 16Turn 1p.16
- 17Turn 2 -- chains automaticallyp.17
- Strategy 2: Conversations API (Server-Managed, Named)p.17
- 18Create a named conversationp.18
- 19Turn 1p.19
- 20Turn 2 -- same conversation, full history availablep.20
- Strategy 3: Client-Side Historyp.20
- 21Turn 1p.21
- 22Turn 2p.22
- 7.5 Compaction: Managing Long Conversationsp.22
- 7.6 Streaming and WebSocket Modep.22
- 23Enable WebSocket transport globallyp.23
- 7.7 Phase Parameter (February 24, 2026)p.23
- 7.8 Expanded File Inputs (February 24, 2026)p.23
- 7.9 Skills and Hosted Shell (February 10, 2026)p.23
- 7.10 Batch APIp.23
- 24Submit a batch of requestsp.24
- 25Check status laterp.25
- Chapter 8: Function Calling, Tools & MCPp.25
- 26Check if the model wants to call a functionp.26
- 8.2 Tool Choicep.26
- 8.3 Parallel Function Callsp.26
- 27The model might call both get_weather("Paris") and get_weather("London")p.27
- 28in a single response. Handle each call and return all results.p.28
- 8.4 Strict Mode for Functionsp.28
- 8.5 Built-in Tools (GPT-5.4+)p.28
- 8.6 Connectors (August 21, 2025)p.28
- 8.7 Model Context Protocol (MCP)p.28
- 29Same pattern as Streamable HTTP but uses SSE transportp.29
- MCP Configuration Optionsp.29
- 30Only expose specific toolsp.30
- Chapter 9: Structured Outputsp.30
- 31response.output_parsed is a typed EntityExtraction objectp.31
- Chapter 10: Multimodal Capabilitiesp.31
- 32The model is available in the gpt-image-2 family.p.32
- 33Verify the exact model ID string against the current API reference.p.33
- Multi-Turn Editingp.33
- 34Generate initial imagep.34
- 35Edit in a follow-up turnp.35
- 10.2 Realtime Audio APIp.35
- 36Pipeline handles: audio input -> STT -> agent -> TTS -> audio outputp.36
- 10.3 Sora 2: Video Generation APIp.36
- 37Illustrative -- confirm exact model ID and method signaturep.37
- Chapter 11: Agentic Patterns & the Agents SDKp.37
- 38Asyncp.38
- 39Synchronousp.39
- 40Streamingp.40
- 11.4 Orchestration Patternsp.40
- 41Manager coordinates the workflowp.41
- Pattern 2: Handoffs (Peer Delegation)p.41
- 42result.last_agent == shipping_agent (control transferred)p.42
- Note on Codex CLI subagentsp.42
- 11.5 Guardrailsp.42
- 11.6 Function Toolsp.42
- 11.7 Sessions: Persistent Memoryp.42
- 43Create a persistent sessionp.43
- 44Turn 1p.44
- 45Turn 2 -- agent remembers the namep.45
- 46-> "Your name is Alex."p.46
- 11.8 Sandbox Agentsp.46
- 47Default: Filesystem + Shell + Compactionp.47
- 48Custom: add skills and memoryp.48
- Sandbox Clientsp.48
- Lifecycle Modesp.48
- Resuming from Snapshotsp.48
- 49Save state after a runp.49
- 50Later: resume from saved statep.50
- 11.9 Tracing and Observabilityp.50
- 51Environment variablep.51
- 52OPENAI_AGENTS_DISABLE_TRACING=1p.52
- 53Codep.53
- 54Per-runp.54
- 11.10 Model Configurationp.54
- 55Global default (currently gpt-4.1, overridable)p.55
- 56Per-agentp.56
- Model Settingsp.56
- Non-OpenAI Providersp.56
- 57pip install openai-agents[litellm]p.57
- 11.11 Putting It All Together: A Complete Examplep.57
- 58--- Tools ---p.58
- 59--- Guardrails ---p.59
- 60--- Specialist Agents ---p.60
- 61--- Triage Agent ---p.61
- 62--- Run with persistent session ---p.62
- Chapter 12: Codex CLI — On-Disk Conventions and Authoringp.62
- Working agreementsp.62



