agents/apiTHE ENCYCLOPEDIA
Integration guides

Agents API contract quick reference

Find the session methods, function-result envelope, event meanings, and retry boundaries for an Agents API integration.

Create session
Inspect action
Authorize tool
Submit result
Check root outcome

Choose the correct SDK surface

These examples use the OpenAI Python SDK's client.beta.agents.sessions namespace, not Responses or Agents SDK Runner. For raw HTTP, the session root is https://api.openai.com/v1/agents/sessions with server-side Bearer authorization and OpenAI-Beta: agents=v1. Keep the API key outside browser code.

Choose the correct SDK surface
TaskPython methodContract
Start worksessions.create(...)agent, environment, input; stream=True for events
Inspect dependenciessessions.retrieve(session_id)Read current required_actions
Send message or tool resultsessions.events.create(session_id, events=[...])Input event batch; not the final answer
Observe live changessessions.events.stream(session_id)Live events, not missed-event replay
Recover saved outputsessions.items.list(session_id, order='asc', limit=100)Paginated saved items; consume every needed page

Match the pending call

A function action carries type=function_call, name, arguments, turn_id, and call_id. Arguments are an object here. Validate them against your tool schema and authenticated ownership. Do not execute a historical function-call item merely because it appears in saved output.

Example
# action is a current required_actions entry converted with to_dict().
result = {
    'type': 'agent.session.input.tool_result',
    'turn_id': action['turn_id'],
    'call_id': action['call_id'],
    'success': True,
    'output': json.dumps({'order_id': 'ORDER-100', 'status': 'shipped'}),
}
client.beta.agents.sessions.events.create(session_id, events=[result])
# Failure uses success=False and error='Safe explanation', not output.

Map signals to application behavior

Stream events and webhook deliveries are different interfaces. Keep business status separate from transport and turn status.

Map signals to application behavior
SignalApplication behavior
agent.session.requires_actionInspect pending function or environment dependency
agent.session.turn.output_text.deltaAccumulate the matching item/content part
agent.session.turn.output_text.doneReplace partial text with complete text
agent.session.turn.completedFinish only the root turn; inspect business outcome
agent.session.turn.failed / cancelledDisplay terminal failure/cancellation for the root
agent.session.idle or closed streamDo not infer task success

Use three different identities

Store session ownership for access control, turn_id plus call_id for tool-result correlation, and a business-operation key for side effects. The event-create method also accepts idempotency_key in Python (idempotencyKey in TypeScript). Persist the same key and identical batch when retrying that submission. An event key does not deduplicate a payment performed by your own service.

Use three different identities
FailureSafe next step
Invalid arguments or denied accessReturn a safe tool failure; do not retry unchanged
Result submission times outRetrieve current action; resend stored result if still pending
Business write outcome is unknownReconcile with the downstream operation ID before repeating
Browser disconnectsKeep session ID; recover saved state, not a new task
Authentication or access errorCorrect credentials/project access before retrying

Verify the boundary before release

Record the SDK version in your lockfile. Exercise success, denied ownership, malformed arguments, duplicate calls, and interrupted result delivery. Confirm that logs contain correlation IDs but not secrets or unnecessary customer data. Use the linked API reference for optional fields and SDK-version-specific types.

Read the official reference

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

OpenAI: functions Events and saved items Session input event reference Run sessions

38 matching topics

What is the OpenAI Agents API?FoundationsAgents API vs Agents SDK vs Responses APIComparisonsAgents API quickstartGetting startedSessions, turns & durable stateCore conceptsHosted vs self-hosted sandboxesInfrastructureConnect MCP servers to Agents APITools & integrationsFunction calling & application toolsTools & integrationsMulti-agent orchestrationCore conceptsStreaming, webhooks & event handlingIntegration guidesFiles, outputs & published artifactsCore conceptsVaults & MCP authenticationTools & integrationsAgent security & credential boundariesProductionTracing, usage & debuggingProductionAgents API pricing & cost planningProductionOpenAI Agents API with PythonGetting startedAgents API with TypeScript & Next.jsIntegration guidesWhat is the OpenAI Agents SDK?FoundationsResponses API in the agent stackFoundationsAgent Skills & SKILL.mdTools & integrationsProgrammatic Tool CallingTools & integrationsRAG, file search & vector storesTools & integrationsWeb search & source citationsTools & integrationsChatKit & Agent BuilderIntegration guidesAgent configuration & reusable definitionsCore conceptsPlugins: connect skills and MCP toolsTools & integrationsSandbox lifecycle & executor connectionsInfrastructureWebhook verification, queues & deduplicationIntegration guidesAgent retries, timeouts & failure recoveryProductionAgent evaluations & regression testingProductionWhich parts of the agent stack do you need?FoundationsAgents API contract quick referenceIntegration guidesOrder agent reference: approval, recovery & evaluationIntegration guidesBuild a Next.js order agent: server, tools & streamingIntegration guidesPython Agents API example with a real tool loopGetting startedHuman approval & prompt injection defensesProductionAgents API troubleshooting: symptoms, checks & recoveryProductionAgent tool support & runtime ownership matrixComparisonsAgent resources, relationships & task stateCore concepts
K to open Esc to close