> ## Documentation Index
> Fetch the complete documentation index at: /docs/llms.txt
> Use this file to discover all available pages before exploring further.

# How Cost Tracking Works

> How Arize AX prices an LLM span: model lookup order, config matching rules, supported token count fields, and the cost attributes it writes.

Arize AX prices every LLM span when it ingests it, then adds the spans up per trace, so you can filter, monitor, and build dashboards on what each request costs. Default cost configs cover common models from OpenAI, Anthropic, Google, Mistral, and others. A [custom cost config](/docs/ax/instrument/track-costs.md) sets the price for a model that has no default or replaces a default price.

> [!WARNING]
>
> Cost is calculated at ingestion and is not recomputed later. Set up custom pricing before you send the traces you want priced.

## How Arize AX calculates cost

1. If the span already carries `llm.cost.total`, `llm.cost.prompt`, or `llm.cost.completion`, Arize AX keeps those values and skips the lookup.
2. Otherwise it reads the model name from the first of these that is set: `llm.model_name`, the `model_name` key in `llm.invocation_parameters`, or the `model_name` key in `metadata`.
3. It picks the cost config for that model. A config scoped to the span's space wins over one scoped to its organization, which wins over an Arize default. Within a scope, an exact model name match beats a regex match, and a config whose provider matches `llm.provider` beats one with no provider.
4. It multiplies each token count on the span by the matching token type's price per 1M tokens in the config. Tiered pricing applies a different price once the token count passes a threshold.

Cost configs are cached for 10 minutes, so a new or edited config can take up to 10 minutes to apply to incoming spans.

## Supported token count fields

Arize AX reads token counts from the [OpenInference semantic conventions](https://github.com/Arize-ai/openinference/blob/main/spec/semantic_conventions.md). Auto-instrumentation sets them. With [manual instrumentation](/docs/ax/instrument/manual-instrumentation.md), set them yourself.

| Token type | Field name |
| :- | :- |
| Prompt (all input subtypes) | `llm.token_count.prompt` |
| Prompt audio | `llm.token_count.prompt_details.audio` |
| Prompt image | `llm.token_count.prompt_details.image` |
| Cache input | `llm.token_count.prompt_details.cache_input` |
| Cache read | `llm.token_count.prompt_details.cache_read` |
| Cache write | `llm.token_count.prompt_details.cache_write` |
| Completion (all output subtypes) | `llm.token_count.completion` |
| Completion audio | `llm.token_count.completion_details.audio` |
| Reasoning | `llm.token_count.completion_details.reasoning` |
| Completion image | `llm.token_count.completion_details.image` |
| Total (optional) | `llm.token_count.total` |

You can add your own token types under `prompt_details` or `completion_details`. Arize AX prices any token count whose name matches a token type in the cost config.

## Cost attributes on spans

Arize AX writes the result back to the span. Set these yourself to supply your own cost instead.

| Attribute | Description |
| :- | :- |
| `llm.cost.prompt` | Prompt cost |
| `llm.cost.completion` | Completion cost |
| `llm.cost.total` | Total cost |
| `llm.cost.prompt_details.*` | Prompt cost by token type |
| `llm.cost.completion_details.*` | Completion cost by token type |

## Use cost data

Cost attributes work anywhere span attributes do: filter traces or spans above a cost threshold, create monitors on high-cost traces, and build dashboards on specific token types. The trace view shows the summed cost of every LLM span in the request.

![Trace-level cost aggregated across all LLM spans in a request in Arize AX](https://storage.googleapis.com/arize-phoenix-assets/assets/images/arize-docs-images/instrument/trace_cost.png)

Each LLM span's Attributes tab breaks the cost down by token type, which shows how much reasoning, cache, or image tokens contribute to an expensive step.

![LLM span Attributes tab in Arize AX showing the llm.cost breakdown with prompt, completion, prompt\_details, completion\_details, and total](https://storage.googleapis.com/arize-phoenix-assets/assets/images/arize-docs-images/instrument/session_cost.png)

## Next steps

> [card] [Custom Cost Config](/docs/ax/instrument/track-costs.md)
>
> Set the price per token for a model that has no default, or replace a default price.

> [card] [Customize your traces](/docs/ax/instrument/customize-your-traces.md)
>
> Add the semantic conventions, including token counts, that Arize AX reads from your spans.
