OpenAI prompting guide

OpenAI prompting guide
Concise and on point; geared toward API users.
Prompt-writing tactics for GPT models, with examples for each technique.
Overview
This is OpenAI's official guide to writing prompts when using models through the API, part of its developer documentation. It covers choosing a model, the role of each message type, prompt formatting, example shots, bringing your own data into context and prompt caching.
The guide clearly distinguishes two groups of models: reasoning models suit multi-step work and only need a general goal, while GPT models are faster and cheaper but need detailed instructions. It also advises pinning the model version and building an evaluation suite (evals) for real applications.
For businesses building chatbots or automation with the OpenAI API, this is a foundational document for making prompts stable, cost-efficient and easy to maintain.
Highlights
Choose the right model
Reasoning models for complex work but slower and pricier; GPT is fast and economical; the mini and nano versions are even faster and cheaper.
Message roles
The instructions parameter and developer messages hold the application's rules and take priority over user input.
Markdown and XML formatting
Use Markdown headings and lists to divide sections and XML tags to mark reference documents.
Few-shot learning
Provide a varied set of input and output examples to steer the model without fine-tuning.
Context and RAG
Add the business's own data to the prompt, watching the context window limit measured in tokens.
Prompt caching
Put reusable content at the start of the prompt to reduce cost and latency.
What it's for
Sales advisory chatbot
Set answer rules, tone and policies in the developer message so customers can't steer the chatbot off course.
Answering from internal documents
Put the product catalog or return policy into context so the AI answers with the company's correct information.
Structured data output
Use Structured Outputs so the AI returns JSON in the right shape, easy to feed into Google Sheets or a CRM.
Cost optimization
Pick a small model for simple tasks and order the prompt to take advantage of caching.
Prompt version management
Keep prompts in source code with tests so each edit doesn't break earlier results.
How to use it
- 1
Choose a suitable model
Weigh reasoning models against GPT according to the task's difficulty, speed and cost.
- 2
Write the developer message
Arrange in the order identity, instructions, examples and context, using Markdown and XML to separate them.
- 3
Add examples and data
Add a few sample examples and the business's relevant documents to the prompt.
- 4
Try it in the Playground
Test and adjust the prompt in OpenAI's Playground before putting it into the application.
- 5
Pin the version and test
Pin a specific model version, keep prompts in source code and build evals to track quality.
Video guides
Build Hour: GPT-5
OpenAI
Real-world example
A hypothetical example: an online furniture shop wants an assistant to answer questions about dimensions and delivery policy. The shop's developer writes a developer message containing the role, a rule to answer only from the provided data, a few sample Q&A pairs and a product information table inside XML tags. The fixed information is placed at the start of the prompt to benefit from caching, while the customer's question goes at the end. Before going live, the team tests it on questions customers have actually sent to check accuracy.
Tips & notes
Don't assume where the result is
The docs note that the output array may contain several elements, so extract the text appropriately instead of always reading the first element.
GPT models need clear instructions
With GPT, describe each step precisely; with reasoning models, stating the goal is enough.
Mind reusable prompts
The reusable prompt object is being deprecated; OpenAI recommends managing prompts in source code.
Instructions are not saved automatically
When chaining a conversation with previous_response_id, the instructions from the previous turn do not carry over automatically.
FAQ
Who is the guide for?
Mainly for people building applications through the OpenAI API, but principles such as clarity, examples and context also help when chatting with ChatGPT.
Does it cost anything?
Reading the docs is free; API calls are billed according to OpenAI's pricing. See the terms on the official site.
Do I need to know programming?
The prompt-writing principles are easy to follow; the parts on API parameters, caching and structured outputs need technical knowledge.
Is there a Vietnamese version?
The documentation is in English.
Useful links
Want to apply this in your business?
2dm looks at your workflows, picks the right tools and sets them up with your team. The first call is free.
Same topic

2dm Prompt Library
Prompts for marketing, sales, operations and learning. Fill in a few fields, then copy or open directly in ChatGPT or Claude.

Tailor-made sales landing page prompt
A prompt for Claude Code or a coding agent: build a sales landing page with its own identity for each product, honest about figures, with a lead form, stopping at a draft.

Claude prompting guide
4.5
Anthropic's official guide: how to write clear requests, give examples, break down tasks and let Claude think step by step.


