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

Inspect session results and artifacts

If a user leaves while an agent is working, your app can show them the results when they return, even if it missed the live events. The session ID identifies the conversation. The turn ID identifies one round of work in that conversation.

The Agents API saves messages and tool calls as items. If the agent writes a file under /workspace/outputs in an OpenAI-hosted environment, OpenAI publishes a copy called an artifact when the turn completes. The turn ID lets you match the agent’s reply to the right copy, even if a later turn writes to the same path.

Step 1 of 8Retrieve the turnHTTP request from Your app to OpenAI Agents API.
Your app
Requests the turn by session ID and turn ID.
HTTP request
OpenAI Agents API
Looks up the turn in the specified session.

Retrieve the turn

Request body · GET /v1/agents/sessions/sess_a/turns/turn_export

Retrieve a reply and its files

If you have only the session ID, list its turns and use their timestamps to find the one you need. Retrieve the turn to check its status. If the status is failed, inspect the error. For a completed turn, the reply and files come from different API resources.

Result Where to find it
Agent’s reply List the turn’s items for the main agent. Look for a message with role: "assistant". When present, phase: "final_answer" marks the final reply. Read the text of its output_text parts.
Output file List the session’s artifacts. Match both turn_id and path, then download the file by artifact ID.

You can download artifacts after the environment expires. Save any files you need to keep before deleting the session.

Example: Show a customer the results of its pagination test

Herringbone uses a separate session for each customer. In both sessions, the agent writes to /workspace/outputs/result.json. Each time a report is ready, Herringbone saves the session_id and turn_id from the completion event with the customer’s test run.

For Customer A, Herringbone’s app looks up the session (sess_a) and turn (turn_export). The saved reply names the report’s path. The app matches that path and turn ID to the artifact artifact_export, downloads it, and reads its summary field.

Retrieve Customer A’s reply and report

Here, sessions is OpenAI().beta.agents.sessions. Herringbone reads the completed turn’s items, newest first, and skips progress messages marked commentary. In the Python SDK, item.output_text joins the text parts of one message.

Read the assistant’s final reply
def read_reply(sessions, session_id, turn_id):
    turn = sessions.turns.retrieve(turn_id, session_id=session_id)
    if turn.status != "completed":
        raise RuntimeError(f"Turn is {turn.status}")

    items = sessions.turns.items.list(turn_id, session_id=session_id, order="desc")
    for item in items:
        if item.type == "message" and item.role == "assistant":
            if item.phase != "commentary" and item.output_text:
                return item.output_text
    raise ValueError("No final reply in this turn.")

The app notifies Customer A’s finance team and checks each user’s access when they open the review. Here’s what the FDE might tell them.

Herringbone now returns payments one page at a time. Your nightly export makes only one request, so your report will miss any payments after the first page. Update the export to send each next_cursor value back as cursor until there are no more pages. In a test of this change, all three sample payments appeared exactly once. Your live export hasn’t changed.

The app uses Customer C’s session and turn IDs to retrieve a different report at the same path. The FDE advises the reseller to fetch all pages and combine the payments into one array before responding to merchants. The report shows whether merchants can keep using the API as before.

If a report conflicts with the test log, Herringbone can inspect the trace for that turn to see what information the agent used.

Ask your coding agent
Check the user’s access to the requested test run, then look up its Agents API session and turn IDs. Check the turn’s status and read all pages of items in order to find the assistant’s final reply. Find the artifact with the same turn ID and expected report path. Download it by artifact ID and display the report alongside the reply. Read this lesson for context: https://developers.openai.com/api/training/agents-api/5-inspect-session-results-and-artifacts.md