Track live agent activity, inspect completed work, and review detailed turn traces:
- You can view the session logs in the Platform dashboard.
- You can follow the session through its events and saved history.
- You can inspect turns and identify delegated command execution.
- You can inspect recorded token usage for root-agent and subagent turns.
View the session in the dashboard
Go to platform.openai.com/logs?api=agents and open the Agents tab.
Search for a session by ID to inspect its turns, tool calls, and subagents.
Use the Tracing guide to inspect recorded model responses, tool calls, and subagent activity in the dashboard. Trace retrieval and external trace exporters are not part of the public beta API.
Follow events and inspect session history
Every session exposes an event stream that shows what the agent is doing in real time. Set OPENAI_API_KEY and SESSION_ID before running these examples:
import OpenAI from "openai";
const client = new OpenAI();
const events = await client.beta.agents.sessions.events.stream(
process.env.SESSION_ID
);
try {
for await (const event of events) {
if (
[
"agent.session.turn.failed",
"agent.session.turn.cancelled",
"agent.session.failed",
"agent.session.environment.failed",
"error",
].includes(event.type)
) {
throw new Error(`Agent lifecycle failure: ${event.type}`);
}
console.log(JSON.stringify(event));
}
} finally {
events.controller.abort();
}The stream stays open across idle events so you don’t miss queued work. Press Ctrl+C to stop watching.
As the session runs, you’ll see events such as:
agent.session.environment.connected
agent.session.turn.created
agent.session.turn.in_progress
agent.session.turn.item.added
agent.session.turn.output_text.delta
agent.session.turn.completed
agent.session.idle
To inspect work that has already happened, retrieve the session’s saved items:
import OpenAI from "openai";
const client = new OpenAI();
const sessionId = process.env.SESSION_ID;
const items = await client.beta.agents.sessions.items.list(sessionId, {
order: "asc",
limit: 100,
});
console.log(items.data);Inspect turns and identify delegated commands
Session turns are available through the public API. Set TURN_ID from a command item in addition to OPENAI_API_KEY and SESSION_ID. The cURL example requires jq:
import OpenAI from "openai";
const client = new OpenAI();
const sessionId = process.env.SESSION_ID;
const turns = await client.beta.agents.sessions.turns.list(sessionId, {
limit: 20,
order: "desc",
});
console.log(turns.data);
const turnId = process.env.TURN_ID;
const turn = await client.beta.agents.sessions.turns.retrieve(turnId, {
session_id: sessionId,
});
console.log(turn.subagent_id);Use the returned last_id as the next page’s after value when has_more is true.
Command items contain turn_id. Retrieve that turn and read subagent_id to identify the delegated agent that ran the command. A null subagent ID identifies root-agent work. Command-output truncation is not reported.
Inspect a turn trace
Use the Platform dashboard to inspect a completed turn and its agent activity. Detailed trace retrieval is not available through an ordinary project API key. Dashboard trace endpoints require separate access and are not a supported customer API.
Turn resources include best-effort usage and a subagent_id that identifies delegated work. Usage can be null when unknown and may change. See Inspect subagent token usage.
To attribute a shell command, retrieve the turn identified by its command item’s
turn_id, then inspect turn.subagent_id. The customer API does not indicate
whether command output was truncated.
Model usage and cost
An agent may make several model calls while completing a task. Each call follows the model’s token pricing and prompt-caching rules, as in the Responses API. Estimate cost across all calls needed to complete the task.
What contributes to cost?
Each model call can consume:
- Input tokens: agent instructions, tool definitions, conversation history, user input, files or images, and tool results.
- Cached input tokens: input reused from a matching prompt prefix, billed at the model’s cached-input rate.
- Output tokens: generated text, tool-call arguments, and reasoning.
Reasoning tokens are billed as output tokens.
Subagents can also make model calls. Inspect their recorded turn usage alongside root-agent work when investigating model costs.
Account for root-agent and subagent work, including retries, plus any applicable tool, sandbox compute, and third-party service charges. For models with cache-write pricing, writing input to the cache also has a cost. The Agents API usage fields below do not expose a separate cache-write count, so they cannot determine the exact model charge when that pricing applies.
Prompt caching
Agents carry context forward within a session. When successive model calls share the same prompt prefix, prompt caching can reuse its earlier processing. The model generates a new response; caching does not replay an old answer. Maintaining a session does not guarantee a cache hit. Reuse depends on a matching prefix and the model’s cache eligibility and lifetime rules.
Keep initial instructions and tool definitions stable where practical, and put new task details in follow-up messages. With tool search, discovered definitions are added at the end of the conversation, preserving earlier content for cache reuse. See Prompt caching for model-specific rules.
A high cached-input percentage does not measure savings on the total task cost. Cached input is still billed, and repeated calls can process a large history. Compare the cost of completing the same task at the quality and latency your application needs.
Understand token usage
Session and turn resources expose best-effort usage. It can be null when unknown, and recorded counts may change as accounting arrives. Missing usage does not mean zero usage. These counts are not a final bill.
A recorded usage object contains these token categories:
{
"input_tokens": 5000,
"input_tokens_details": {
"cached_tokens": 1500
},
"output_tokens": 900,
"output_tokens_details": {
"reasoning_tokens": 200
},
"total_tokens": 5900
}
In this example, the agent processed 5,000 input tokens and generated 900 output tokens. Of the input tokens, 1,500 were cached. Of the output tokens, 200 were reasoning tokens.
Cached tokens are included in input_tokens, and reasoning tokens are included in output_tokens.
Inspect subagent token usage
List or retrieve session turns and inspect each turn’s usage. The subagent_id identifies the subagent; it is null for root-agent turns. When has_more is true, pass last_id as after with the same order to read the remaining turns.
Usage is best-effort: it can be null when unknown, and recorded values may change. You can also inspect each agent’s recorded usage in the tracing dashboard.