0PricingLogin
AI Agents · Lesson

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 env

All lessons in this course

  1. Calling OpenAI API: chat.completions
  2. Calling Anthropic API: messages
  3. Streaming Responses (SSE)
  4. Cost Awareness: Token Counting and Budgets
← Back to AI Agents