For the complete documentation index, see llms.txt. Markdown versions of documentation pages are available by appending .md to the page URL.
Agents API

Use environments and artifacts

To give an agent a file to work on, create a session with an OpenAI-hosted environment. The environment gives the agent a workspace where it can read and edit files and run commands.

To get a file back, ask the agent to write it under /workspace/outputs. When the turn (one round of work) completes, OpenAI publishes a downloadable copy called an artifact. That copy stays the same even if the agent edits the working file later.

Step 1 of 10Upload an input fileHTTP request from Your app to OpenAI Agents API.
Your app
Uploads the file by environment ID once the environment is connected.
HTTP request
OpenAI Agents API
Writes the decoded file to the connected environment.

Upload an input file

Request JSON · POST /v1/agents/environments/env_a/files

Workspace files and published copies

Use the environment ID for files in the live workspace. You can supply initial files in environment.files when you create the session. To upload a file later, wait until the environment reports connected. If the supplied files are all the agent needs, you can disable network access.

Use the session ID to tell the agent what to do with the files and to find the artifacts it publishes. A later turn can overwrite a workspace file. Each published copy has its own artifact ID and identifies the turn that produced it.

Example: Report whether a payment export passed its test

Herringbone uses two IDs from the session creation response to get the log to the agent.

  • With environment.id (env_a), Herringbone uploads the log to /workspace/test-results.txt once the workspace is ready.
  • With the session id (sess_a), Herringbone asks the agent to read that path and write a summary to /workspace/outputs/result.json.

The agent reads the log and writes “All three payments appeared once in the export” in the report’s summary field. Once the turn completes, Herringbone can retrieve the agent’s reply and the published report, even after the workspace expires.

Create a report from Customer A’s test log

The log lists the payment IDs on each page and the IDs the job exported. Here, environments is OpenAI().beta.agents.environments. Once the environment reports connected, Herringbone encodes the log as a base64 string and uploads it to /workspace/test-results.txt.

Write the test log to the workspace
def upload_log(environments, environment_id, log):
    deadline = time.monotonic() + 120
    while True:
        status = environments.retrieve(environment_id).status
        if status == "connected":
            break
        if status not in {"pending", "ready"}:
            raise RuntimeError(f"Workspace is {status}")
        if time.monotonic() >= deadline:
            raise TimeoutError("Workspace did not connect in time.")
        time.sleep(2)

    return environments.files.create(
        environment_id,
        path="/workspace/test-results.txt",
        type="inline",
        data=base64.b64encode(log).decode("ascii"),
    )
Ask your coding agent
Create an Agents API session with an OpenAI-hosted environment. Check that the customer authorized access to the test log. Once the environment reports connected, use its ID to upload the log to /workspace/test-results.txt. Use the session ID to ask the agent to summarize that log in /workspace/outputs/result.json. When the turn completes, find the artifact by turn ID and path, then download it by artifact ID. Read this lesson for context: https://developers.openai.com/api/training/agents-api/4-use-environments-and-artifacts.md