New YorkGet in touch

Agents

OpenAI Agents API vs Responses API agent loop: what the Codex harness takes over

OpenAI's Agents API exposes the Codex harness as a managed service that runs sessions, orchestration, context compaction and recovery - leaving your application to provide tools and choose the execution environment.

Published
September 11, 2026
Read
7 min
Author
Samir Sengupta
Diagram of a managed Codex agent session: tools and sandbox on your side, loop and compaction on OpenAI's

the short version

  • The Agents API moves sessions, orchestration, context compaction and recovery onto OpenAI's servers; your application provides tools and chooses its execution environment.
  • The same capabilities exist as ten separate Responses-side core-concept pages - Conversation state, Background mode, Streaming, WebSocket mode, Mid-turn steering, Multi-agent, Webhooks, File inputs, Compaction, Counting tokens - and composing them yourself is exactly the control you hand over.
  • Billing has three components: model usage at the selected model's API rates, OpenAI tools at standard rates, OpenAI-hosted sandboxes at standard container rates. The overview gives no figures for compaction thresholds, subagent limits or per-session token overhead.
  • A commenter on Hacker News quotes three sandbox network settings from the environments page - enabled (the default unless you inherit a template policy), disabled, and restricted with allowed_domains - and the thread is already probing whether restricted holds up against an agent editing /etc/hosts.

OpenAI's Agents API documentation went up on 2026-09-10. It gives your application access to the Codex harness through an OpenAI-managed API: OpenAI manages sessions, orchestration, context compaction and recovery, while your application provides tools and chooses its execution environment. That sentence is the whole trade - you keep tool definitions and the environment choice, and you hand over the loop. Pricing has three components: model usage at the selected model's API rates, OpenAI tools at their standard rates, and OpenAI-hosted sandboxes at standard container rates.

The individual pieces are not new. The docs nav lists ten Responses-side core concepts you can already assemble yourself: Conversation state, Background mode, Streaming, WebSocket mode, Mid-turn steering, Multi-agent, Webhooks, File inputs, Compaction and Counting tokens. What the Agents API adds on top is a durable server-side session that holds them together and keeps running when your process is not.

The docs are built around four main concepts. An Agent is the model, instructions, tools and MCP servers available to it. An Environment is an optional sandbox or computer where the agent accesses files, loads skills and runs commands. A Session is a durable instance of an agent that works on tasks and responds to input, and events and items are the inputs sent to the agent and the output produced during that session.

What the managed harness takes over

The overview enumerates seven things the managed Codex harness supports. Each is a piece of a hand-rolled loop you would otherwise write and maintain yourself.

  • Running commands and code in a sandbox.
  • Applying relevant skills and instructions.
  • Connecting to external data through tools or MCP.
  • Steering the agent while it works.
  • Summarizing previous work to manage its context window.
  • Breaking work into subtasks and delegating to subagents.
  • Resuming a session where it left off.

The session lifecycle is four steps: create a session, at which point OpenAI provisions its environment; give it a task, which starts a turn of work once the environment is ready; follow progress by streaming output or using webhooks to learn when the agent finishes or needs input; then continue or steer, by sending another task to the same session or guiding the agent during its current turn. For an OpenAI-hosted session the docs are explicit that your application sends input and receives events while OpenAI runs the agent and provisions and manages its sandbox. The calling pattern inverts: you stop driving a model turn by turn and start consuming an event stream.

OpenAI Agents API vs Responses API agent loop

Running the loop yourself means composing those ten Responses primitives by hand. You decide when conversation state is persisted, when compaction fires, how a failed turn is retried, and how a subagent result is folded back into the parent context. Under the Agents API those decisions move server-side, where the overview describes them as managed rather than configured - with the caveat that the docs also say to configure these capabilities when you create a session, and carry separate Configuring Agents and Architecture pages the overview does not summarise.

Two of the seven matter most for cost and correctness. Compaction, described here as summarizing previous work to manage its context window, is what decides which tokens survive into the next turn; a summariser you cannot inspect is a quality variable you cannot ablate. Delegation is the other - the overview's own example is comparing release notes with subagents and combining their findings into one answer, a fan-out whose token consumption you observe afterwards through the Observability and usage and Tracing pages rather than bounding in advance. The overview publishes no figures for compaction thresholds, subagent limits or per-session token overhead.

The environment is still your choice

Environments are the part the docs leave to you. There are separate pages for OpenAI-hosted sandboxes and self-hosted sandboxes, plus sandbox lifecycle, sandbox security, and files and artifacts, and the overview points to environment options for setup and limitations. Inside a sandbox, agents can execute code, edit files, connect to MCP servers and produce artifacts. Tools attach through their own set of pages - Web search, Functions, MCP connections, Plugins and Vaults - which is where your application's code actually plugs in.

One commenter on Hacker News went straight to the environments page and quoted its network access configuration: enabled allows outbound access and is the default unless you inherit a template policy, disabled blocks outbound access, and restricted allows only the hosts listed in allowed_domains. The same thread reports trying to talk the agent around restricted mode: a curl to example.com exited with code 0 and returned the text Domain forbidden, and the agent declined to edit /etc/hosts and retry with an alternate hostname and a spoofed Host header. That is one anecdote from one commenter, not an evaluation. The sources contain no published security analysis of restricted mode; the docs list a Sandbox security page that the overview does not quote.

What you pay for and what you stop counting

Pricing is stated in a single line with three components: model usage at the selected model's API rates, OpenAI tools at their standard rates, and OpenAI-hosted sandboxes at standard container rates. The orchestration is managed but not invisible on the bill - compaction summaries and subagent turns are model calls, billed at the same rates as any other. The container meter is the new line item relative to a loop you run on your own machine; the overview does not state how self-hosted sandboxes are billed.

The Responses side of the docs has a dedicated Counting tokens page. The Agents API side routes you instead to Observability and usage and Tracing. If your cost model depends on predicting spend before a run rather than attributing it after, that is the first difference to check.

Hacker News is worried about lock-in and metering

Lock-in dominates the thread. Commenters read the Agents API as a more durable moat than the many agentic harnesses that run on your own machine, and one argues that the point of a locally-running agent is that the artifacts and work in progress sit on your disk to inspect, not just the final artifact. Another says this does not need to exist beyond the existing Responses or Chat Completions APIs, reporting that their company already scripts entire persistent workflows with a simple SDK. A fourth frames the whole release as an attempt to answer how OpenAI earns more money.


Instead of this push for more vendor lock-in, give us the reasoning tokens we pay for.
a commenter on Hacker News

Metering is the second theme, and it is about Codex rather than the Agents API itself. One commenter reports that for about a week every request, no matter how small, has used at least 1% of their weekly limit and around 5% of their five-hour limit; a reply puts it at 5 to 10% of the five-hour limit whether the task is a code review over a significant code base or a single config value change. A third says a newly created account burned far less for the same work while the old account chews through 20%. Another asserts you cannot use a subscription with this at all. None of that is in the docs, which state only the three billing components.

The most concrete unanswered question in the thread is operational: does each execution of an agent session create a new environment, is that environment then billed for at least a full hour despite prices being quoted per 20 minutes, and is there a way to deliberately shut one down rather than waiting for it to expire. The overview does not answer any part of it. The docs nav lists a Sandbox lifecycle page, which is where that answer would live.

What is unresolved before you migrate

Three things the overview does not settle. First, sandbox billing granularity and explicit teardown, which is the difference between a cheap event-driven agent and an idle container you are paying for. Second, how much harness behaviour is configurable versus fixed - the retrieved page's sample block is titled Configure managed-harness capabilities and labelled Python while the code shown is the TypeScript OpenAI SDK, so read the quickstart prerequisites for API-key permissions and SDK setup rather than trusting the label. Third, the stability of the abstraction: the nav files Agent Builder, its migration guide and its Node reference under Legacy APIs, and carries a separate Assistants API migration guide.

A related release landed the next day, GPT-Live-1 in the API on 2026-09-11, but no body text was retrievable for it, so nothing here depends on what it contains. The practical test for anyone weighing the move is narrow: run the same task twice, once through an Agents API session and once through your own Responses loop, and compare total billed tokens plus container time. Until compaction and subagent behaviour are documented with numbers, that measurement is the only way to price the managed harness.

Questions this raises

What is the difference between the OpenAI Agents API and the Responses API?

The Responses API gives you ten primitives (conversation state, background mode, streaming, compaction, counting tokens and more) that you compose into an agent loop yourself. The Agents API wraps those in a durable server-side session where OpenAI runs sessions, orchestration, context compaction and recovery. Your application still supplies tools and picks the execution environment.

How much does the OpenAI Agents API cost?

Pricing is stated as three components: model usage at the selected model's API rates, OpenAI tools at their standard rates, and OpenAI-hosted sandboxes at standard container rates. Compaction summaries and subagent turns are model calls billed like any other, so managed orchestration still shows on the bill. The overview does not state how self-hosted sandboxes are billed.

Can you restrict network access in an OpenAI Agents API sandbox?

The environments page documents three network settings: enabled allows outbound access and is the default unless you inherit a template policy, disabled blocks outbound access, and restricted allows only the hosts in allowed_domains. One Hacker News commenter reported a curl to example.com returning 'Domain forbidden' under restricted mode. There is no published security analysis of restricted mode in the sources.

These daily notes are drafted by a model I run and operate myself - the same kind of pipeline this site is about - from sources published in the previous 24 hours, and every one lists what it read. The longer essays, the talks and the preprint are mine, written by hand.

More notes

Building something on this?

I ship production LLM, RAG and agentic systems for a living - the infrastructure behind the things these notes are about. Open to roles, contract work and research collaboration.