Skip to content
OpenAI Prompting Best Practices
On Trove · from OpenAI

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

What is OpenAI Prompting Best Practices?

A comprehensive guide to prompting and building with OpenAI's models and APIs, covering model selection, prompt engineering techniques, GPT-4.1 best practices, reasoning models (o3/o4-mini), Responses API, function calling, structured outputs, multimodal capabilities, advanced features, and the Agents SDK. Sourced from official OpenAI documentation.

Read more

OpenAI · markdown · Listed Feb 22, 2026

  • open-ai
  • best-practices
  • agents
  • llms

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

  1. 01OpenAI Prompting Best Practicesp.1
    1. Chapter 1: Introduction & Model Overviewp.1
    2. Chapter 2: Universal Prompting Techniquesp.1
  2. 02Personalityp.2
  3. 03Goalp.3
  4. 04Success criteriap.4
  5. 05Constraintsp.5
  6. 06Outputp.6
  7. 07Stop rulesp.7
    1. Chapter 3: GPT-5.5 Best Practicesp.7
  8. 08Retrieval rulesp.8
    1. Chapter 4: GPT-5.4 Family Best Practicesp.8
    2. Chapter 5: GPT-5.3-Codex Best Practicesp.8
See all 62 parts
  1. 09Good: batch readsp.9
  2. 10Bad: sequential readsp.10
    1. Planning Strategyp.10
    2. Compaction for Long Sessionsp.10
    3. Tool Preferencesp.10
    4. Personality Variantsp.10
    5. Practical Example: Codex System Promptp.10
  3. 11Autonomyp.11
  4. 12Explorationp.12
  5. 13Qualityp.13
  6. 14Planningp.14
    1. Chapter 6: Reasoning Models -- o3p.14
  7. 15Decision framework for reasoning effortp.15
    1. Chapter 7: Responses API & Conversation Managementp.15
  8. 16Turn 1p.16
  9. 17Turn 2 -- chains automaticallyp.17
    1. Strategy 2: Conversations API (Server-Managed, Named)p.17
  10. 18Create a named conversationp.18
  11. 19Turn 1p.19
  12. 20Turn 2 -- same conversation, full history availablep.20
    1. Strategy 3: Client-Side Historyp.20
  13. 21Turn 1p.21
  14. 22Turn 2p.22
    1. 7.5 Compaction: Managing Long Conversationsp.22
    2. 7.6 Streaming and WebSocket Modep.22
  15. 23Enable WebSocket transport globallyp.23
    1. 7.7 Phase Parameter (February 24, 2026)p.23
    2. 7.8 Expanded File Inputs (February 24, 2026)p.23
    3. 7.9 Skills and Hosted Shell (February 10, 2026)p.23
    4. 7.10 Batch APIp.23
  16. 24Submit a batch of requestsp.24
  17. 25Check status laterp.25
    1. Chapter 8: Function Calling, Tools & MCPp.25
  18. 26Check if the model wants to call a functionp.26
    1. 8.2 Tool Choicep.26
    2. 8.3 Parallel Function Callsp.26
  19. 27The model might call both get_weather("Paris") and get_weather("London")p.27
  20. 28in a single response. Handle each call and return all results.p.28
    1. 8.4 Strict Mode for Functionsp.28
    2. 8.5 Built-in Tools (GPT-5.4+)p.28
    3. 8.6 Connectors (August 21, 2025)p.28
    4. 8.7 Model Context Protocol (MCP)p.28
  21. 29Same pattern as Streamable HTTP but uses SSE transportp.29
    1. MCP Configuration Optionsp.29
  22. 30Only expose specific toolsp.30
    1. Chapter 9: Structured Outputsp.30
  23. 31response.output_parsed is a typed EntityExtraction objectp.31
    1. Chapter 10: Multimodal Capabilitiesp.31
  24. 32The model is available in the gpt-image-2 family.p.32
  25. 33Verify the exact model ID string against the current API reference.p.33
    1. Multi-Turn Editingp.33
  26. 34Generate initial imagep.34
  27. 35Edit in a follow-up turnp.35
    1. 10.2 Realtime Audio APIp.35
  28. 36Pipeline handles: audio input -> STT -> agent -> TTS -> audio outputp.36
    1. 10.3 Sora 2: Video Generation APIp.36
  29. 37Illustrative -- confirm exact model ID and method signaturep.37
    1. Chapter 11: Agentic Patterns & the Agents SDKp.37
  30. 38Asyncp.38
  31. 39Synchronousp.39
  32. 40Streamingp.40
    1. 11.4 Orchestration Patternsp.40
  33. 41Manager coordinates the workflowp.41
    1. Pattern 2: Handoffs (Peer Delegation)p.41
  34. 42result.last_agent == shipping_agent (control transferred)p.42
    1. Note on Codex CLI subagentsp.42
    2. 11.5 Guardrailsp.42
    3. 11.6 Function Toolsp.42
    4. 11.7 Sessions: Persistent Memoryp.42
  35. 43Create a persistent sessionp.43
  36. 44Turn 1p.44
  37. 45Turn 2 -- agent remembers the namep.45
  38. 46-> "Your name is Alex."p.46
    1. 11.8 Sandbox Agentsp.46
  39. 47Default: Filesystem + Shell + Compactionp.47
  40. 48Custom: add skills and memoryp.48
    1. Sandbox Clientsp.48
    2. Lifecycle Modesp.48
    3. Resuming from Snapshotsp.48
  41. 49Save state after a runp.49
  42. 50Later: resume from saved statep.50
    1. 11.9 Tracing and Observabilityp.50
  43. 51Environment variablep.51
  44. 52OPENAI_AGENTS_DISABLE_TRACING=1p.52
  45. 53Codep.53
  46. 54Per-runp.54
    1. 11.10 Model Configurationp.54
  47. 55Global default (currently gpt-4.1, overridable)p.55
  48. 56Per-agentp.56
    1. Model Settingsp.56
    2. Non-OpenAI Providersp.56
  49. 57pip install openai-agents[litellm]p.57
    1. 11.11 Putting It All Together: A Complete Examplep.57
  50. 58--- Tools ---p.58
  51. 59--- Guardrails ---p.59
  52. 60--- Specialist Agents ---p.60
  53. 61--- Triage Agent ---p.61
  54. 62--- Run with persistent session ---p.62
    1. Chapter 12: Codex CLI — On-Disk Conventions and Authoringp.62
    2. Working agreementsp.62