Lesson 15 OpenAI GPT Series
Theme:

Theory: OpenAI GPT Series

Understanding the GPT model family, API differences, and when to choose GPT over Claude.

GPT Model Families

OpenAI offers several model families, each optimised for different use cases. The GPT-4o family is the general-purpose workhorse, while the o-series models specialise in multi-step reasoning. Understanding the trade-offs between these families is key to choosing the right model for a task.

GPT-4o (“omni”) is a natively multimodal model that processes text, images, and audio in a single architecture. It replaced GPT-4 Turbo as OpenAI’s primary model and offers better performance at lower cost. GPT-4o-mini is a smaller, cheaper variant designed for high-volume applications where cost matters more than peak capability.

The GPT-4.1 family introduced a 1M-token context window and improved instruction following, particularly for coding tasks. GPT-4.1-mini and GPT-4.1-nano provide progressively cheaper alternatives with smaller capability trade-offs.

o1 / o3 Reasoning Models

The o-series models represent a fundamentally different approach to LLM inference. Instead of generating a response in a single forward pass, these models allocate additional compute at inference time by generating internal “reasoning tokens” before producing the visible output.

When you send a prompt to o1 or o3, the model first generates a chain of thought internally. These reasoning tokens are not returned to you, but you are billed for them at the output token rate. This means a request that produces a 100-token visible response might actually generate 2,000 tokens total (1,900 reasoning + 100 visible), and you pay for all 2,000 at the output price.

The o3-mini model offers a reasoning_effort parameter that lets you control this trade-off. Setting it to “low” produces faster, cheaper responses with less reasoning depth. Setting it to “high” gives the model more thinking time for complex problems.

from openai import OpenAI
client = OpenAI()

# o3-mini with configurable reasoning effort
response = client.chat.completions.create(
    model="o3-mini",
    reasoning_effort="high",       # low | medium | high
    messages=[{"role": "user", "content": "Prove that sqrt(2) is irrational."}],
)
# Note: usage.completion_tokens includes hidden reasoning tokens
print(f"Total output tokens: {response.usage.completion_tokens}")
print(f"Visible response: {response.choices[0].message.content[:200]}")

Cost trap: o-series models can be 10–50x more expensive per request than GPT-4o for simple tasks, because they still allocate reasoning tokens even when the task does not require deep reasoning. Only use o-series when you need multi-step reasoning (math proofs, complex coding, scientific analysis).

API Differences: OpenAI vs Anthropic

Both APIs use HTTP POST requests with JSON bodies and return JSON responses. However, the structure differs in several important ways that affect how you write code.

Message Roles

OpenAI includes the system prompt as a message with role: "system" in the messages array. Anthropic uses a separate top-level system parameter. This distinction matters for caching: Anthropic lets you explicitly cache the system prompt, while OpenAI handles caching automatically.

# OpenAI
response = openai_client.chat.completions.create(
    model="gpt-4o",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Hello!"},
    ],
)
text = response.choices[0].message.content

# Anthropic
response = anthropic_client.messages.create(
    model="claude-sonnet-4-20250514",
    system="You are a helpful assistant.",
    messages=[{"role": "user", "content": "Hello!"}],
    max_tokens=1024,
)
text = response.content[0].text

Tool Calling / Function Calling

OpenAI uses tools with type: "function" and returns tool calls in the message object. Anthropic uses tools with input_schema and returns tool use as content blocks. The tool definition format is similar (JSON Schema for parameters), but the invocation and response handling differ.

Streaming

Both APIs support server-sent events for streaming. OpenAI streams delta objects within choices, while Anthropic streams typed events (content_block_delta, message_delta, etc.). Anthropic’s event types are more granular, making it easier to track token usage during streaming.

Assistants API

OpenAI’s Assistants API is a managed service that handles conversation state, file storage, and tool execution on the server side. It is conceptually similar to building an agent with Claude, but with infrastructure managed by OpenAI rather than your own code.

The key entities are Assistants (persistent configurations with instructions and tools), Threads (conversation histories stored server-side), and Runs (executions of an assistant on a thread). The Assistants API includes built-in Code Interpreter (sandboxed Python execution) and File Search (vector store over uploaded files).

The main advantage is reduced infrastructure: you do not need to manage conversation history, implement RAG, or sandbox code execution. The main disadvantage is vendor lock-in and less control over the internals. If you need to understand why the model made a particular decision, the Assistants API provides less visibility than building your own pipeline.

Vision and Multimodal

GPT-4o handles images natively within the chat completions API. You can pass images as URLs or base64-encoded data within message content. The model can describe images, extract text (OCR), analyse charts, and answer questions about visual content.

response = client.chat.completions.create(
    model="gpt-4o",
    messages=[{
        "role": "user",
        "content": [
            {"type": "text", "text": "What's in this image?"},
            {"type": "image_url", "image_url": {
                "url": "https://example.com/photo.jpg",
                "detail": "high"    # low | high | auto
            }},
        ],
    }],
)
print(response.choices[0].message.content)

The detail parameter controls image resolution and cost. “Low” uses fewer tokens (fixed 85 tokens), while “high” processes the image at full resolution (up to 1,445 tokens depending on size). For most use cases, “auto” is a good default.

When to Choose GPT

There is no universally superior model. The right choice depends on your specific requirements:

Pro tip: The best approach is to build a model-agnostic abstraction layer, then benchmark both providers on your actual tasks. Models improve rapidly, and the winner changes with each release. Avoid hard-coding assumptions about which model is “better.”

Further Reading