Prompts2026年3月29日·1 分钟阅读

OpenAI Cookbook — Official Prompting Guides

Official prompting guides from OpenAI: GPT-5.2, Codex, Meta Prompting, and Realtime API guides. The definitive reference for OpenAI model optimization.

Agent 就绪

Agent 可直接安装

这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。

Native · 96/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Prompt
安装
Single
信任
信任等级:Community
入口
OpenAI Cookbook — Official Prompting Guides
直接安装命令
npx -y tokrepo@latest install 26b9b7dd-dbe6-41e3-a093-17db5409d739 --target codex

先 dry-run 确认安装计划,再运行此命令。

TL;DR
Official prompting guides from OpenAI covering GPT models, Codex, Meta Prompting, and Realtime API.
§01

What it is

OpenAI Cookbook is the official collection of prompting guides and code examples maintained by OpenAI. It covers GPT-5.2, Codex, Meta Prompting, and the Realtime API, serving as the definitive reference for anyone working with OpenAI models.

This resource is aimed at developers, prompt engineers, and AI practitioners who want to move beyond trial-and-error prompting and adopt patterns validated by OpenAI themselves.

§02

How it saves time or tokens

By following official best practices, you avoid common anti-patterns that waste tokens on retries and poorly structured prompts. The cookbook demonstrates techniques like system message structuring, few-shot formatting, and output constraining that reduce token consumption per request. Each guide distills lessons from OpenAI's internal testing, saving you hours of experimentation.

§03

How to use

  1. Browse the OpenAI Cookbook repository on GitHub to find the guide relevant to your model or use case.
  2. Follow the step-by-step code examples, adapting them to your application's language and framework.
  3. Apply the prompting patterns (few-shot, chain-of-thought, meta prompting) to your production prompts and measure the improvement in output quality.
§04

Example

# Meta Prompting pattern from OpenAI Cookbook
system_prompt = '''
You are an expert prompt engineer.
Given a task description, generate an optimized prompt
that maximizes accuracy and minimizes token usage.
'''

response = client.chat.completions.create(
    model='gpt-4o',
    messages=[
        {'role': 'system', 'content': system_prompt},
        {'role': 'user', 'content': 'Write a prompt for summarizing legal documents'}
    ]
)
print(response.choices[0].message.content)
§05

Related on TokRepo

  • Prompt Library — Browse community-contributed prompts across models and use cases
  • AI Tools for Coding — Developer tools that integrate LLM prompting into workflows
§06

Common pitfalls

  • Copying prompts verbatim without adapting them to your specific model version or API endpoint.
  • Ignoring the distinction between system, user, and assistant roles when structuring multi-turn conversations.
  • Over-engineering prompts with excessive instructions when a concise few-shot example would perform better.

常见问题

What models does the OpenAI Cookbook cover?+

The cookbook covers GPT-5.2, Codex, and earlier GPT-4 variants. It also includes guides for the Realtime API and Meta Prompting techniques that apply across models.

Is the OpenAI Cookbook free to access?+

Yes. The entire cookbook is open source and hosted on GitHub under the OpenAI organization. All code examples and guides are freely available.

How often is the cookbook updated?+

OpenAI updates the cookbook as new models and API features are released. Contributors also submit pull requests with community-tested patterns and examples.

Can I use the cookbook examples in production?+

Yes. The code examples are designed as starting points for production applications. You should adapt parameters like temperature, max tokens, and system prompts to your specific requirements.

What is Meta Prompting in the cookbook?+

Meta Prompting is a technique where you use an LLM to generate or refine prompts for another task. The cookbook provides patterns for building prompt-generation pipelines that improve output quality iteratively.

引用来源 (3)
🙏

来源与感谢

Created by OpenAI. Licensed under MIT. openai-cookbook cookbook.openai.com

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产