The fastest path to working with the OpenAI API is a single Python script — no framework, no boilerplate. This guide walks you through getting an API key, installing the SDK, and making your first request, so you have a working baseline before you dive into any cookbook example.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/openai/openai-cookbook/llms.txt
Use this file to discover all available pages before exploring further.
Prerequisites
- An OpenAI account (free to create)
- Python 3.9+ or Node.js 18+ installed locally
- A terminal
Get your API key
Sign in to the OpenAI platform and navigate to API keys in the left sidebar. Click Create new secret key, give it a name, and copy the value — you won’t be able to see it again.
Make your first API call
Run the snippet below. If you see a greeting in the output, your setup is working.Expected output:
Explore cookbook examples
With a working connection to the API, you’re ready to explore any notebook in the cookbook. Clone the repository and open it in Jupyter.Each notebook installs its own dependencies from a local
requirements.txt. Check the notebook’s first cell for any additional setup steps.Understanding the response object
Thecreate call returns a ChatCompletion object. The fields you’ll use most often are:
| Field | Description |
|---|---|
response.choices[0].message.content | The model’s reply as a plain string |
response.choices[0].finish_reason | Why the model stopped: stop, length, or tool_calls |
response.usage.prompt_tokens | Number of tokens in your input |
response.usage.completion_tokens | Number of tokens in the model’s reply |
response.model | The exact model version that handled the request |
Common parameters
The
messages parameter is a list, so you can pass a full conversation history — not just a single user message. Include a system message at the start to set the model’s behavior and persona.Next steps
Agents & Automation
Go beyond single-turn calls: build agents that use tools, hand off tasks, and maintain state across many steps.
Embeddings & Search
Convert text to vectors for semantic search, clustering, and recommendation systems.
Fine-tuning
Train a model on your own examples to improve accuracy for a specific task.
Contribute an example
Found a useful pattern? Share a notebook with the community.