# OpenAI Cookbook

Canonical: https://cqbase.net/en/entry/openai-cookbook
Chinese: https://cqbase.net/zh/entry/openai-cookbook
English: https://cqbase.net/en/entry/openai-cookbook

> OpenAI’s own API examples and guides, published at cookbook.openai.com.

openai/openai-cookbook is MIT licensed. It collects examples and guides for the OpenAI API, with the site at cookbook.openai.com. Use it when you have already chosen that API and want the vendor’s recommended shape, not a pile of detached prompts.

Pick a notebook that matches how you call the API, then check the model name and parameters against what you run. Official examples move. Check the date before copying one.

## What problem it solves

[openai/openai-cookbook](https://github.com/openai/openai-cookbook) is OpenAI’s official collection of API examples and guides. The companion site is [cookbook.openai.com](https://cookbook.openai.com). Use it when you have already chosen that API and want the vendor’s recommended shape—not a pile of detached prompts. The repository is MIT licensed and is not archived.

Verified on 2026-11-16 (Asia/Shanghai). The most recent repository push was at 03:45 UTC on 14 November 2026, which is 11:45 Asia/Shanghai the same day. The root README is short. The real catalog is the website and the repository’s `registry.yaml`. Runnable notebooks and scripts live under `examples/`; longer guides live under `articles/`. On 2026-11-16 the site listed recent material on Agents, Codex, Responses, and gpt-oss, and it can also still contain older examples. Check the date on any page before you copy it, and compare the model names and parameters with the current API docs.

## Who it is for

It is for developers who already have an OpenAI account and an API key, and who want to adapt an official example to their own calling style. Most code examples are in Python, though official docs say the ideas can be applied in other languages. Request a key through an official entrance such as [platform.openai.com](https://platform.openai.com/signup); follow the console that is current when you sign up.

If you do not use the OpenAI API, or you only want generic prompts to paste elsewhere, this repository is not the best starting point. Billing, account, and quota questions belong in the [OpenAI Help Center](https://help.openai.com/). The Cookbook issue tracker is for problems with Cookbook content, as [CONTRIBUTING.md](https://github.com/openai/openai-cookbook/blob/main/CONTRIBUTING.md) states.

## How to use it

The steps below come from the repository [README](https://github.com/openai/openai-cookbook/blob/main/README.md) and [CONTRIBUTING.md](https://github.com/openai/openai-cookbook/blob/main/CONTRIBUTING.md), checked on 2026-11-16. You do not need to clone the whole repository just to read. Start at [cookbook.openai.com](https://cookbook.openai.com), pick a recipe by topic, and use the Markdown twin when useful (append `.md` to the page URL). The repository is large; clone it only when you need to run several examples locally.

To run one recipe, set an environment variable, or use a `.env` file at the repo root (the README says most IDEs will pick up `OPENAI_API_KEY` from that file):

```bash
export OPENAI_API_KEY="YOUR_API_KEY"
```

Do not commit the key or paste it into a chat. CONTRIBUTING says each example should list its own dependencies, such as a `requirements.txt` in that example’s directory, and that you should install them in a virtual environment. There is no single root dependency file that covers every example. After installing, run that notebook from top to bottom, and check the model names and API surface (for example Responses, versus an older Completions-style call) against the current [API documentation](https://developers.openai.com/api/docs).

If you are changing an existing example and preparing a contribution, CONTRIBUTING also mentions:

```bash
python .github/scripts/check_notebooks.py
```

That is a structure check for contributors, not a required step for simply running a recipe.

## A worked example

This path is: pick a recent guide that matches how you call the API, then reproduce it on a small piece of your own data. This guide did not run any notebook, so it does not invent an API response or a cost figure.

1. Open [cookbook.openai.com](https://cookbook.openai.com) and filter by what you actually need, such as tool use, structured outputs, Agents, or retrieval. Prefer an entry with a recent date and an interface that matches what you use, not an older page that is merely familiar.
2. Read the model names, prerequisites, and dependency notes on that page, then compare them with the current API docs. If the page still names a model your account cannot call, change it to a current name from the docs before running anything.
3. In a separate virtual environment, install the dependencies listed by that example, set `OPENAI_API_KEY`, replace the sample input with a small piece of your own data, and run it. Expected effect: the call should complete and demonstrate the step the recipe is teaching (for example one tool call, or one structured output). Inspect the result yourself.
4. Confirm that the key and any third-party credentials were not written into the notebook. If the example also depends on an external service, read the cost and permission notes before you continue.

## Common pitfalls

- Treating the root README as a complete catalog. It mostly points at the website; the full index is the site and `registry.yaml`.
- Copying an old notebook without checking its date. Newer and older entries sit side by side, and both model names and APIs can have changed.
- Assuming there is a root `requirements.txt` that runs every example. CONTRIBUTING tells you to install the dependencies for the example you are actually running or changing.
- Writing the key into a notebook or committing `.env`. Official docs say to read it from the environment.
- Filing billing or account questions on the Cookbook GitHub issue tracker. Official guidance sends those to the Help Center.
- Cloning the entire large repository just to read one short article. Use the website first, and clone or download a single path only when you need to run it locally.

## FAQ

### Can I start reading without cloning the repository?

Yes. The official README treats [cookbook.openai.com](https://cookbook.openai.com) as the main entrance. Clone or download a path only when you need to run an example locally or compare it with the source file.

### How do I configure the API key?

The README says to set the `OPENAI_API_KEY` environment variable, or to use a `.env` file at the repository root that contains that variable. Do not write the key into source files or commit it. Get the key from the official OpenAI console.

### Are the examples guaranteed to be current?

No. The repository is still updated, but older articles remain in the catalog. Before you run one, check the date on that entry and confirm that the model names and API it uses still appear in the current official docs.

### Where is the complete catalog?

For browsing, use [cookbook.openai.com](https://cookbook.openai.com). In the repository, the index that corresponds to the site is [registry.yaml](https://github.com/openai/openai-cookbook/blob/main/registry.yaml). CONTRIBUTING says new published content should go under `examples/<topic>/` or `articles/`.

### What is the license?

The repository is MIT licensed; see [LICENSE](https://github.com/openai/openai-cookbook/blob/main/LICENSE). Read the full text before commercial use or redistribution. API charges from running an example follow your account’s official billing. This page does not invent prices.

## Sources and license

The [openai/openai-cookbook](https://github.com/openai/openai-cookbook) repository is licensed under MIT. This page is a paraphrase, for CQBase — Context & Query Base, of the README, [CONTRIBUTING.md](https://github.com/openai/openai-cookbook/blob/main/CONTRIBUTING.md), [cookbook.openai.com](https://cookbook.openai.com), and the `registry.yaml` layout, all checked on 2026-11-16. If the catalog, dependencies, or API shapes change, the website and the official API docs win.

## Catalog record

- Author: openai
- License: MIT
- Source: https://github.com/openai/openai-cookbook
- Added: 2026-11-15
- GitHub stars: 77132 (captured 2026-11-15)

