# PreparedOperationCost

> **Class** in `deepagents_code`

📖 [View in docs](https://reference.langchain.com/python/deepagents-code/cost_tracking/PreparedOperationCost)

A priced side-operation delta pending checkpoint persistence.

Use exactly once: every prepare must be either committed (its `update`
persisted) or rolled back. `_drain_recorded_costs` is destructive, so a
prepare that is neither deletes that spend from the thread's lifetime total
permanently, and nothing can detect the loss afterwards.

`_settled` is `init=False` so a caller cannot construct a pre-neutralized
instance whose `rollback` is already a no-op. The class stays unfrozen only
because marking settlement on a frozen dataclass needs
`object.__setattr__`, which this project's lint rules reject.

## Signature

```python
PreparedOperationCost(
    self,
    thread_id: str,
    records: list[_ModelCallRecord],
    delta_usd: float,
    breakdown: CostBreakdown,
)
```

## Constructors

```python
__init__(
    self,
    thread_id: str,
    records: list[_ModelCallRecord],
    delta_usd: float,
    breakdown: CostBreakdown,
) -> None
```

| Name | Type |
|------|------|
| `thread_id` | `str` |
| `records` | `list[_ModelCallRecord]` |
| `delta_usd` | `float` |
| `breakdown` | `CostBreakdown` |


## Properties

- `thread_id`
- `records`
- `delta_usd`
- `breakdown`
- `update`

## Methods

- [`rollback()`](https://reference.langchain.com/python/deepagents-code/cost_tracking/PreparedOperationCost/rollback)
- [`commit()`](https://reference.langchain.com/python/deepagents-code/cost_tracking/PreparedOperationCost/commit)

---

[View source on GitHub](https://github.com/langchain-ai/deepagents/blob/4bfa52000ef65ac623d8ada0cb67f67cbdd663ea/libs/code/deepagents_code/cost_tracking.py#L2562)