agents/api
Core concepts

Agent resources, relationships & task state

Map configuration, sessions, turns, events, items, environments, and artifacts to their owners and lifetimes.

Input accepted
Turn runs
Tool or environment needed
Work continues
Outcome checked

Read the resource relationships

These connections describe ownership and use, not a single linear request. One reusable agent configuration can serve multiple independent sessions; each session can perform multiple turns.

Track outcomes independently

This is an application interpretation of signals, not a replacement for the API's state schema. Waiting for a dependency, completing a turn, and closing a browser connection are different facts.

Track outcomes independently
SignalMeaning for your application
New input while idleStarts another turn in the session
New input while activeCan steer the active turn
requires_actionInspect and satisfy the current dependency
idleNot proof of successful task completion
Root turn completedCheck output and tool outcomes
Root failed or cancelledShow failure/cancellation; preserve diagnostic IDs
Stream closedTransport ended; inspect state if no terminal event arrived

Do not equate IDs with authorization

Store your authenticated user's ownership mapping separately from the session ID. A tool call belongs to a turn and call identifier; a business operation needs its own stable identity for idempotency. Do not let an untrusted request choose an arbitrary session, tool result, or approval record.

Keep compute lifetime separate

Self-hosted compute may disconnect while its session still exists. A replacement machine does not recover files merely by reusing an environment ID. Persist files through the provider and coordinate reconnection. Delete the session and release self-hosted compute separately after preserving needed output.

Read the official reference

Check the source for current API fields, account requirements, and service limits.

OpenAI: sessions Environment lifecycle Events and items