Agents API quickstart OpenAI published an Agents API quickstart showing developers how to build a coding assistant that writes a Python script, runs it, and reports the output, with the agent, its conversation, and its sandbox managed by OpenAI. The guide requires an application API key with the api.agents.read, api.agents.write, and api.responses.write scopes and the OpenAI-Beta: agents=v1 header, and provides streaming examples in Python, JavaScript, Go, and Java (openai-java 4.69.2) using the beta.agents namespace with the gpt-6-astra model and an openai_hosted environment. Build a coding assistant that writes tree.py , runs it, and shows a directory tree. OpenAI manages the agent, its conversation, and the sandbox where it works. Prerequisites Create an application API key https://platform.openai.com/api-keys in your OpenAI Platform project. Grant api.agents.read and api.agents.write for session operations, plus api.responses.write for model inference, then export it: export OPENAI API KEY="your-api-key" Keep this key outside the agent’s sandbox. See OpenAI-hosted sandboxes https://developers.openai.com/api/docs/guides/agents-api/environments/openai-hosted configure-the-sandbox for sandbox configuration and limits. Requests require the OpenAI-Beta: agents=v1 header. The OpenAI SDKs add it automatically; include it explicitly when using cURL. 1. Run a task Choose a language, install the OpenAI SDK, and run the example. The SDK examples use the beta.agents namespace. The request creates a session, submits a task, and streams progress. Install or update the Python SDK: pip install --upgrade openai Save the example as quickstart.py : python 1 2 3 4 5 6 7 8 9 10 11 12 13 14from openai import OpenAI with OpenAI as client: with client.beta.agents.sessions.create agent={ "model": "gpt-6-astra", "instructions": "Write clean code, run it, and report the actual output.", }, environment={"type": "openai hosted"}, input="Create tree.py, a Python script that prints a readable tree of the files in the current directory. Run it and show me the output.", stream=True, as events: for event in events: print event.to json indent=None , flush=True Run it from your terminal: python quickstart.py Install the JavaScript SDK: npm install openai Save the example as quickstart.mjs : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20import OpenAI from "openai"; const client = new OpenAI ; const events = await client.beta.agents.sessions.create { agent: { model: "gpt-6-astra", instructions: "Write clean code, run it, and report the actual output.", }, environment: { type: "openai hosted" }, input: "Create tree.py, a Python script that prints a readable tree of the files in the current directory. Run it and show me the output.", stream: true, } ; try { for await const event of events { console.log JSON.stringify event ; } } finally { events.controller.abort ; } Run it from your terminal: node quickstart.mjs In a new directory, create a Go module and install the SDK: go mod init agents-quickstart go get github.com/openai/openai-go/v3@latest Save the example as main.go : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30import "context" "fmt" "github.com/openai/openai-go/v3" ctx := context.Background client := openai.NewClient events := client.Beta.Agents.Sessions.NewStreaming ctx, openai.BetaAgentSessionNewParams{ Agent: openai.BetaAgentSessionNewParamsAgent{ Model: openai.String "gpt-6-astra" , Instructions: openai.String "Write clean code, run it, and report the actual output." , }, Environment: openai.EnvironmentParamUnion{OfParamOpenAIHosted: &openai.EnvironmentParamOpenAIHosted{}}, Input: openai.BetaAgentSessionNewParamsInputUnion{ OfString: openai.String "Create tree.py, a Python script that prints a readable tree of the files in the current directory. Run it and show me the output." , }, } defer events.Close if events.Err = nil { panic events.Err } for events.Next { event := events.Current fmt.Println event.RawJSON } if err := events.Err ; err = nil { panic err } Run it from your terminal: go run . Add the OpenAI SDK to your Maven project’s pom.xml : 1 2 3 4 5