# prepare_operation_cost

> **Function** in `deepagents_code`

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

Price model calls made by a server operation without committing them.

The caller must persist `PreparedOperationCost.update` atomically with the
operation state, or call `rollback()` if that write fails or is abandoned.
A prepare with a zero delta still consumes its records, so an abandoned
prepare must roll back even when it has nothing to write.

## Signature

```python
prepare_operation_cost(
    state: CostState,
    thread_id: str,
) -> PreparedOperationCost
```

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `state` | `CostState` | Yes | Current thread state used for model/provider fallback metadata. |
| `thread_id` | `str` | Yes | Thread that owns the side-operation model calls. |

## Returns

`PreparedOperationCost`

Prepared additive cost delta and the claimed recorder entries.

---

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