Free Crash Course · Agentic AI

Building Agents With OpenAI's Agents API

OpenAI's Agents API went to public beta on September 10, 2026, giving developers managed access to the same Codex agent harness that powers Codex and ChatGPT's cloud agents. This course walks through the core concepts, your first session, tools, and sandbox options.

Free crash course
Everything on this page
No signup
Self-paced
5
Lessons
9
Sandbox Partners
4
Core Concepts
$0
Forever Free

What this course covers.

5 lessons, everything on this page.

Read top to bottom. No signup, no drip — it's all here.

1

Lesson 1: What the Agents API actually is

OpenAI's Agents API gives applications managed access to the same Codex agent harness that powers Codex and cloud agents in ChatGPT, exposed through an OpenAI-managed API rather than a framework you run yourself. Per OpenAI's official documentation, OpenAI handles session orchestration, context compaction across long tasks, sub-agent coordination, and crash recovery. Your application supplies the task, the tools, and the execution environment.

This sits alongside, not instead of, the code-first Agents SDK — OpenAI's other path for building agents directly in Python or JavaScript. The Agents API is the managed option: you send a task to an OpenAI-hosted session and get back structured events, rather than owning the orchestration loop yourself.

When to reach for this: if you want long-running, stateful agent sessions without building your own retry, compaction, and sub-agent logic, the Agents API is built for exactly that. If you need full control over the execution loop, the Agents SDK is the better starting point.
2

Lesson 2: The four core concepts

Everything in the Agents API is built from four objects, per OpenAI's overview docs:

  • Agent — the model, instructions, tools, and MCP servers available to the agent.
  • Environment — an optional sandbox or compute resource where the agent accesses files, loads skills, and executes commands. Set type to openai_hosted for a managed sandbox, or none for a tool-only agent with no local file access.
  • Session — a durable instance of an agent working on tasks and responding to input; sessions persist state across multiple turns so you don't reconstruct conversation context yourself.
  • Events and Items — the inputs sent to the agent and the outputs it streams back as it works, including status events like agent.session.turn.completed, turn.failed, and session.idle.
3

Lesson 3: Your first session

Sessions are created with client.beta.agents.sessions.create(). Per the Agents API quickstart, a minimal Python call looks like this:

client.beta.agents.sessions.create(
    agent={"model": "gpt-6-astra", "instructions": "..."},
    environment={"type": "openai_hosted"},
    input="Create tree.py that prints a directory tree",
    stream=True
)

Requests need the header OpenAI-Beta: agents=v1 and an application API key granting the api.agents.read, api.agents.write, and api.responses.write permissions. The docs show working examples in Python, JavaScript, Go, Java, Ruby, and cURL. Once a session starts, grab its session_id from the initial events to send follow-up prompts to the same running session, and call client.beta.agents.sessions.delete(session_id) once you've saved whatever artifacts the agent produced.

Note on data residency: per OpenAI's docs, the Agents API currently supports US data residency only, and does not support Zero Data Retention (ZDR) regardless of which sandbox you choose — factor that into any regulated-data use case before you build on it.
4

Lesson 4: Giving agents tools

Per OpenAI's documentation, agents built on the Agents API can use MCP (Model Context Protocol) server connections, custom functions, web search, and programmatic tool calling, and can delegate work to up to four concurrent sub-agents for parallel work on a larger task. If you've already built MCP servers for another client, the same servers plug directly into an Agents API agent's tool list.

The sandboxed environment itself is also a tool surface: an agent with environment.type set to openai_hosted can execute code, edit files, and produce artifacts inside that sandbox as part of completing a task, not just call out to external APIs.

5

Lesson 5: Choosing where the agent runs

Beyond OpenAI's own managed sandbox, OpenAI has partnered with a set of third-party compute providers for the Agents API: Blaxel, Cloudflare, Daytona, DigitalOcean, E2B, Modal, Oracle, Runloop, and Vercel, according to reporting on the public beta launch. Each offers first-class integrations covering fully managed environments or deployment inside your own VPC, with different CPU, GPU, memory, cold-start, and cost profiles — you can generally swap providers by changing which sandbox client class you instantiate, without rewriting your agent logic.

On pricing: there's no separate platform fee for the Agents API itself. You pay standard token rates for whichever model you select, plus standard rates for any tools, MCP connections, or hosted sandbox compute the agent actually uses — the same reporting confirms this is usage-based, not a flat subscription on top of the API.

Starter move: begin with environment.type: "openai_hosted" for your first build. It requires zero third-party setup, and you can migrate to a dedicated sandbox provider later once you know your workload's actual compute shape.

Build these to make it stick.

Starter

Directory-tree agent

Build the quickstart example into a small CLI: an agent that takes a folder path and writes a tree.py-style summary, using the OpenAI-hosted sandbox.

Starter

Session-state tester

Create a session, send a first task, capture the session_id, then send two follow-up prompts to confirm state persists across turns without you resending context.

Intermediate

MCP-connected research agent

Connect an existing MCP server (or build a minimal one) and give an Agents API agent a research task that requires it to call the MCP tool mid-session.

Intermediate

Sandbox swap

Run the same agent task against the OpenAI-hosted sandbox and one third-party provider (E2B or Modal), and compare cold-start time and cost for your workload.

Advanced

Multi-agent delegation pipeline

Build a lead agent that delegates to up to four concurrent sub-agents for a task with independent sub-parts (e.g., researching four competitors in parallel), then merges their outputs.

Advanced

Webhook-driven long-running agent

Kick off a long session, use webhooks instead of polling to catch session.idle and turn.completed events, and handle a turn.failed event with a retry.

Sources: OpenAI — Agents API overview; OpenAI — Agents API quickstart; Phemex — OpenAI Agents API Enters Public Beta. Grounded in the official docs and specs above — not invented API details.

Where to head next.

Free, and staying that way.

This crash course is one of the free courses at Precision AI Academy. No signup, no upsell — just the material.

See all free courses