agents/apiTHE ENCYCLOPEDIA
Integration guides

Agents API with TypeScript & Next.js

Place the OpenAI client on the server and connect durable agent work to a React interface.

React interface
Authenticated server route
OpenAI SDK
Managed session
Progress UI

Use a server boundary

Install openai in your backend project. In Next.js, keep client creation in a server-only module or Route Handler. Read OPENAI_API_KEY from a non-public environment variable. The browser calls your authenticated application endpoint, not the privileged OpenAI API directly.

Create and track work

Use client.beta.agents.sessions.create with an agent, environment, and input. Store the session ID in application storage against the authenticated user. A browser-provided session ID is not authorization; check ownership before retrieving or continuing work.

Choose streaming or asynchronous delivery

A server route can forward live progress for interactive tasks. For longer work, persist a task record and process verified webhooks, then let the frontend retrieve status. Select execution timeouts appropriate to your hosting platform and avoid tying durable work to one browser request.

Design the UI around real states

Show submitted, working, waiting for input, completed, and failed states based on actual events. Provide reconnect behavior and artifact links. Do not show a success state merely because an HTTP connection ended.

Read the official reference

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

OpenAI: architecture

23 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 guides
K to open Esc to close