# format_cost_estimate

> **Function** in `deepagents_code`

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

Format a speculative USD cost as a rounded, approximate upper bound.

Used where the figure is a worst-case estimate rather than recorded spend
(e.g. the cold-cache warning modal, whose cache may be partially warm):
rounds so the display does not imply false precision, and prefixes with `~`
to signal "approximately". Do not use for recorded session spend --
`format_cost` renders actuals exactly.

Rounding is upward to two significant figures at or above a dime so it can
safely appear in an upper-bound estimate. Between one cent and a dime the
figure keeps cent-level precision instead (`0.062` renders `~$0.07`); a
second digit there would be sub-cent noise.

## Signature

```python
format_cost_estimate(
    cost_usd: float,
) -> str
```

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `cost_usd` | `float` | Yes | Estimated cost in US dollars. |

## Returns

`str`

A string such as `'~$0.62'` or `'~$12'`; non-positive values use

---

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