Calling OpenAI API: chat.completions
Send messages to the OpenAI chat.completions endpoint, set temperature and max_tokens, and parse the response.
Why chat.completions?
OpenAI has two APIs:
- chat.completions — the standard, well-supported endpoint
- Responses API / Assistants — managed agents (more advanced)
This lesson covers chat.completions, which is the workhorse for 95% of agents.
Install the SDK
One package, one line:
# pip install openai
from openai import OpenAI
client = OpenAI() # reads OPENAI_API_KEY from envAll lessons in this course
- Calling OpenAI API: chat.completions
- Calling Anthropic API: messages
- Streaming Responses (SSE)
- Cost Awareness: Token Counting and Budgets