costUsd on the session, and use costState to tell a final cost from one that can still grow. An automation coordinator’s cost covers the subagents linked to it now: when a coordinator is replaced, its independent subagents still running or waiting on a person, and everything they have spent, move to the coordinator that takes them over.
Any organization role that can read sessions can read their cost: user, developer, or admin. The billing role cannot see sessions. See Organizations and roles and API keys. Credits are bought separately on the Billing screen; see Billing.
Read one session’s cost
getSession returns costUsd and costState with the rest of the session, in both the full and summary views.
- Console
- cURL
The console shows one figure for the whole session tree: the session and every subagent and teammate under it.
- Open Advanced in the sidebar, choose Sessions, and read the Cost column.
- Open the session. The session header and the Session tab of its details show the same Cost.
- While the figure can still change, it reads so far. Session costs can take up to an hour to settle, and a subagent, teammate, the advisor or the supervisor waiting to be called on again can keep its conversation cached for up to six hours while the session that calls on it is still working, each cache read charged.
costUsd once costState is final (see Know when a figure is final).
Cost fields
Cost fields
A subagent or teammate session returns the cost of its whole tree, the same figure as its root.
costUsd is one total; to split it by model and kind of charge, or to read what was spent in a time window, see Break a run’s cost down. Read the root session to learn when a cost is final: a subagent or teammate session can still report so_far after its tree has settled.A so_far cost can be behind what the session has cost. When the cost can’t be read again in time, costUsd is the last amount that was read. When running compute can’t be priced right now, costUsd leaves it out until it can be.Both fields are absent when there is no cost to return yet or when the cost is withheld in the session’s current state. An absent cost is not zero. Read the session again later if no cost has been read yet; retrying alone does not resolve a withheld cost.Compare many sessions
Rows fromlistSessions carry costUsd and costState too. Send root_only=true to get one row per run. A child session repeats its tree’s cost, so adding child rows counts the same cost twice.
- cURL
listSessionUsage takes session_ids, a comma-separated list of up to 1000 ids.
- cURL
Usage rows
Usage rows
listSessionUsagereturnssession_usage: the event count and token counts for each session’s own events. Children are not included. Unknown ids and sessions with no events are left out, so compare the number of rows with the number of ids you sent.cost_microsis the cost the session’s own model events reported, in millionths of a US dollar. It is for diagnostics, not what your balance is charged: it leaves out child sessions, sandbox compute, and the requests that keep a waiting session’s cache alive, which add no event. UsecostUsdon the session for what you are charged.- In v2 (
listSessionUsageV2), each row also hasmodels: the same totals split by public model id, one item per model, which add up to the row. They cover the same own events, so they also leave out context-compaction summaries, cache keep-alives, memory digests, sessions your key can’t see such as the agent’s oversight advisor or supervisor, and sandbox compute. For the billed cost by model, use the breakdown below.
Break a run’s cost down
getSessionCostV2 returns a root session’s billed cost split by where it was spent, kind of charge, and model. It covers exactly what the root’s costUsd counts: its own tree, plus the subagent, oversight and grader runs costUsd includes, which are reported by role and never identified. source is self, subagent, oversight (the advisor or supervisor configured under the agent’s oversight settings) or grader. Every amount is read at one moment, readAt.
- cURL
Breakdown fields and the time window
Breakdown fields and the time window
- Send a root session’s id. A child session inside a tree is refused with
400, naming its root. A subagent that runs as its own root reports its own tree. - Without a window,
totalUsdisbookedUsdpluscomputeEstimateUsd, the estimate for sandbox compute still running, and equals the root’scostUsdread at the same moment. bookedAtGteandbookedAtLtselect the half-open window[bookedAtGte, bookedAtLt). A charge counts by when it was booked and a correction by when it was made, so a window can hold a correction to an earlier charge and total less than zero. A windowed read has nocomputeEstimateUsd, because running compute has no booking time yet.costStateis the root’scostState.unsettledAttempts.indeterminatecounts requests lost in flight that the provider may still bill. These counts cover requests only, not running compute: a finished run whose compute has stopped can stayso_farwhile indeterminate requests remain, but the counts alone don’t show that spending has stopped.- To total a campaign, list its roots with
listSessionsV2filtered bymetadataAll(it lists root sessions only), then read the breakdown of each root, at most two at a time. Each serving process admits two breakdowns at once for your organization and waits up to two seconds for a slot; when your organization’s slot doesn’t free in time the read answers429 session_cost_breakdown_limit(withdetails.limit), and when the service’s shared capacity doesn’t it answers503 session_cost_unavailable. Both carryRetry-After. If any root answers409 session_cost_withheld, its cost is unknown: report the total as incomplete rather than counting it as zero.
Know when a figure is final
Why a cost can still grow
Why a cost can still grow
- The session is still running. The session or one of its subagents or teammates is working or waiting for you.
- The session is waiting on a timer, its subagents, its grader or a long-running command. On models that keep a conversation cached for an hour, the cache is read again about every 50 minutes while the session waits, for up to six hours; on models that keep it for 30 minutes, about every 20 minutes for up to two hours. That way the session doesn’t pay to send the whole conversation again when it resumes. Each read is a model charge, normally a small fraction of sending the conversation again. If the cache is gone by then, that one request is charged as the full conversation and the reads stop. A read adds no event to the session, so usage rows don’t count it.
- A subagent, teammate, the advisor or the supervisor is waiting to be called on again. A subagent that reported and waits for the session that started it to message it again, a teammate waiting for work on its team’s board, the advisor between consultations and the supervisor between detector firings have their cache read the same way, and each read is charged. Their cache is kept only while the session that calls on them is still working, running or waiting on a timer, its subagents or its grader: the session that started the subagent, the team’s leader, or the session the advisor or the supervisor oversees. Once that session finishes, waits on you, is cancelled or fails, the reads stop until it next calls on them; cancelling it stops them sooner. A subagent that reported, the advisor between consultations and the supervisor between detector firings show
completed, so their cost, and the session’s cost, readsso_faruntil about an hour after their last model call or cache read, whether or not their cache is kept. - The sandbox is still running. A sandbox can keep running after the session ends, until the environment’s idle stop. Its compute is included as an estimate until it stops.
- Charges are still settling. Session costs can take up to an hour to settle.
- You resumed the session. A message that starts a new turn makes a
finalcostso_faragain.
costUsd is an exact decimal string, such as "1.234567". Add costs with a decimal type, such as Decimal in Python or a decimal library in TypeScript. Floating-point sums drift.
Amount format
Amount format
- All amounts are in US dollars. No other currency is used.
costUsdhas up to nine decimal places and no trailing zeros. A zero cost is"0".cost_microsin usage rows is an integer in millionths of a dollar.
What can go wrong
The most common problems:- The cost changed after you recorded it.
costStatewasso_far. Record the cost once it isfinal. - A list adds up to more than the runs cost. Child rows repeat their tree’s cost. Send
root_only=true. - Usage
cost_microsandcostUsddiffer.cost_microscovers only the session’s own model events and is for diagnostics. UsecostUsd.
Every usage and cost error
Every usage and cost error
The full list of codes is in Errors.
Limits
Every other limit is on Limits.
Next steps
Billing
Buy the credits that session costs are charged to.
Teams
See why a team costs more than one agent.
Multi-agent
Understand the session trees behind one session cost.
Limits
Check quotas and request limits.