OpenAI API Basics
Your first API call and the request/response cycle
🔑 Key Concepts
- Installation — pip install openai. Set OPENAI_API_KEY environment variable.
- Chat Completions — The main endpoint: client.chat.completions.create(). Send messages with roles: system, user, assistant.
- Models — gpt-4.1 (best), gpt-4o-mini (cheap/fast), gpt-4o (capable). GPT-3.5 is deprecated — don't use it.
- Error handling — Rate limits (429), context exceeded, API downtime. Use exponential backoff with tenacity.
💡 Practice: Try implementing each concept yourself before moving on. Reading about RAG and building RAG are very different things.