Learn how to call the OpenAI API and handle responses in your own projects.
Copy working code patterns for common tasks like text generation, embeddings, and chat.
Understand best practices and examples before building your own ChatGPT-powered application.
Reference tested examples when integrating GPT-4 or other OpenAI models into production.
Requires a valid OpenAI API key and account with available credits.
openai/openai-cookbook is a collection of example code and step-by-step guides for accomplishing common tasks using the OpenAI API, the service that powers tools like ChatGPT and GPT-4. If you are a developer trying to figure out how to do something practical with OpenAI's API, this repository is the reference point for working, tested examples. To use the examples, you need an OpenAI account and an API key. The setup involves setting an environment variable called OPENAI_API_KEY with your key, or creating a simple configuration file called .env in your project folder that contains it. The examples in the repository are Jupyter Notebooks, an interactive file format that lets you read explanations and run code side by side, making it easier to follow along. Most of the example code is written in Python, though the README notes the underlying concepts apply to any programming language. The repository is navigable through a dedicated website at cookbook.openai.com. It is released under the MIT license, meaning it is free to use, copy, and adapt.
Generated 2026-05-18 · Model: sonnet-4-6 · Verify against the repo before relying on details.