Lesson 15 OpenAI GPT Series
Theme:
Lesson 15 · Slide 1

OpenAI GPT Series

Understanding the GPT model family is essential for any AI engineer. This lesson covers GPT-4o, the o-series reasoning models, the OpenAI API, and how to choose between GPT and Claude for different tasks.

Learning Objectives

Lesson 15 · Slide 2

GPT-4o Capabilities & Pricing

GPT-4o is OpenAI’s flagship multimodal model, processing text, images, and audio natively.

ModelInput (per MTok)Output (per MTok)Context
GPT-4o$2.50$10128K
GPT-4o-mini$0.15$0.60128K
GPT-4.1$2.00$8.001M
GPT-4.1-mini$0.40$1.601M

Key strengths: Strong at coding, broad knowledge, fast inference, mature ecosystem with large third-party library support, extensive fine-tuning options.

Lesson 15 · Slide 3

o1 / o3 Reasoning Models

OpenAI’s o-series models use reasoning tokens — hidden chain-of-thought tokens the model generates internally before producing its visible response.

Reasoning Token Billing

You pay for reasoning tokens at the output token rate, even though you never see them. A simple question might use 500 reasoning tokens internally before producing a 50-token answer. This means o-series models can be significantly more expensive per request than GPT-4o for simple tasks.

Note: Claude’s extended thinking is the equivalent feature, where you can actually see the thinking tokens.
Lesson 15 · Slide 4

OpenAI API vs Anthropic API

Both APIs follow similar patterns but have important structural differences.

FeatureOpenAIAnthropic
System promptmessages array (role: system)Separate system parameter
Tool callingfunction_calling / toolstool_use content blocks
StreamingServer-sent eventsServer-sent events
Response formatchoices[0].messagecontent[0].text
Stop reasonfinish_reasonstop_reason
VisionImage URLs or base64 in messagesImage blocks in content array
CachingAutomatic (no user control)Explicit cache_control
Lesson 15 · Slide 5

Assistants API & Threads

OpenAI’s Assistants API provides server-side conversation state, code execution, and file handling — a managed stateful layer on top of the chat completions API.

from openai import OpenAI
client = OpenAI()

assistant = client.beta.assistants.create(
    name="Data Analyst",
    instructions="You are a data analyst. Use code interpreter to analyze data.",
    model="gpt-4o",
    tools=[{"type": "code_interpreter"}],
)
thread = client.beta.threads.create()
client.beta.threads.messages.create(thread_id=thread.id,
    role="user", content="Analyze this CSV...")
run = client.beta.threads.runs.create(
    thread_id=thread.id, assistant_id=assistant.id)
Note: Anthropic does not have an equivalent managed Assistants API. With Claude, you manage conversation state client-side, which gives you more control but requires more code.
Lesson 15 · Slide 6

GPT vs Claude — Choosing the Right Model

Neither model family is universally better. The choice depends on the task.

Task TypeGPT-4o EdgeClaude Edge
CodingBroader language coverageLonger code reasoning, fewer hallucinations
Creative writingMore varied styleBetter instruction following, less refusal
AnalysisCode Interpreter for data200K context, prompt caching
Safety-criticalEstablished safety toolingConstitutional AI, less sycophancy
MultimodalAudio input/output, DALL-EPDF/document understanding
Cost-sensitiveGPT-4o-mini is very cheapHaiku 3.5 competitive on price

Best practice: Prototype with both. Run your specific tasks on each and measure quality, latency, and cost. The benchmarks tell you averages; your use case may differ significantly.

Lesson 15 · Slide 7

Demo: Side-by-Side Comparison

Live demonstration: send the same prompt to both GPT-4o and Claude Sonnet, then compare outputs.

Demo Steps

  1. Set up both clients (openai.OpenAI() and anthropic.Anthropic())
  2. Define 3 test prompts: a coding task, a creative writing task, a reasoning task
  3. Send each to both models
  4. Compare: response quality, token usage, latency, cost
  5. Discuss where each model excelled
from openai import OpenAI
import anthropic

openai_client = OpenAI()
claude_client = anthropic.Anthropic()

prompt = "Explain the CAP theorem in distributed systems."

gpt_resp = openai_client.chat.completions.create(
    model="gpt-4o", messages=[{"role": "user", "content": prompt}], max_tokens=300)

claude_resp = claude_client.messages.create(
    model="claude-sonnet-4-20250514",
    messages=[{"role": "user", "content": prompt}], max_tokens=300)

print("GPT-4o:", gpt_resp.choices[0].message.content[:200])
print("Claude:", claude_resp.content[0].text[:200])
Lesson 15 · Slide 8

Lab & Homework

Lab Exercises

  1. GPT-4o Basics — port a Claude prompt to GPT-4o using the openai SDK
  2. Side-by-Side — run 5 prompts on both models, compare in a table
  3. GPT Vision — describe an image using GPT-4o vision

Homework Tasks

  1. Build a model-agnostic LLMClient class
  2. Find 3 tasks where each model wins
  3. GPT vision product description generator
1 / ?