OpenAI prompting guide

PromptsDocsLevel: IntermediateFree
Logo OpenAI prompting guide

OpenAI prompting guide

4.0/52dm rating

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

01

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.

02

Message roles

The instructions parameter and developer messages hold the application's rules and take priority over user input.

03

Markdown and XML formatting

Use Markdown headings and lists to divide sections and XML tags to mark reference documents.

04

Few-shot learning

Provide a varied set of input and output examples to steer the model without fine-tuning.

05

Context and RAG

Add the business's own data to the prompt, watching the context window limit measured in tokens.

06

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. 1

    Choose a suitable model

    Weigh reasoning models against GPT according to the task's difficulty, speed and cost.

  2. 2

    Write the developer message

    Arrange in the order identity, instructions, examples and context, using Markdown and XML to separate them.

  3. 3

    Add examples and data

    Add a few sample examples and the business's relevant documents to the prompt.

  4. 4

    Try it in the Playground

    Test and adjust the prompt in OpenAI's Playground before putting it into the application.

  5. 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

Illustrative scenario

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.

Book a call
Zalo