# RunCost

> Tracon documentation. Tracon is a .NET package family that adds a control
> plane on Microsoft Agent Framework, published as NuGet packages that run
> inside your own ASP.NET Core application.
>
> Page: https://tracon.dev/api/tracon.runcost/
> Summary: RunCost: Cost of a run. It is computed and written once when the run ends (a price snapshot) — a later change to the price list does not change past values.

<div class="api-provenance">Namespace Tracon · Assembly <code>Tracon.Abstractions.dll</code></div>

Cost of a run. It is computed and written once when the run ends (a price
snapshot) — a later change to the price list does not change past values.

```csharp
public sealed record RunCost : IEquatable<RunCost>
```

<dl class="api-relations"><dt>Inheritance</dt><dd><a href="https://learn.microsoft.com/dotnet/api/system.object">object</a> ← <a href="/api/tracon.runcost/">RunCost</a></dd><dt>Implements</dt><dd><a href="https://learn.microsoft.com/dotnet/api/system.iequatable-1">IEquatable&lt;RunCost&gt;</a></dd><dt>Inherited Members</dt><dd><a href="https://learn.microsoft.com/dotnet/api/system.object.gettype">object.GetType()</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.tostring">object.ToString()</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object)">object.Equals(object?)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object-system-object)">object.Equals(object?, object?)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.referenceequals">object.ReferenceEquals(object?, object?)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.gethashcode">object.GetHashCode()</a></dd></dl>

## Remarks

A run can spend tokens on more than one model: the context compaction
summarizer and the `aiJudge` loop criterion's judge can run on models
of their own. Each model's share is then priced at that model and the cost
terms are the sum of the shares. The three `*PricePerMillionTokens`
rate fields are [null](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null) on such a cost — one rate cannot
describe a total that several rates produced. A share whose model has no
price adds nothing; [RunCost.Source](/api/tracon.runcost/#Tracon_RunCost_Source) is [PricingSource.Unknown](/api/tracon.pricingsource/)
only when no share is priced.

## Constructors

### <a id="Tracon_RunCost__ctor"></a> RunCost\(\)

```csharp
public RunCost()
```

## Properties

### <a id="Tracon_RunCost_CachedInputCost"></a> CachedInputCost

Gets the cost of the input tokens that were served from the prompt
cache, or [null](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null) when no cache read was priced.

```csharp
public decimal? CachedInputCost { get; init; }
```

#### Property Value

 [decimal](https://learn.microsoft.com/dotnet/api/system.decimal)?

#### Remarks

The cached tokens are **subtracted** from
[RunCost.InputCost](/api/tracon.runcost/#Tracon_RunCost_InputCost) and charged here instead, so the two fields
still add up to the run's input spend and must not be double counted.

An undefined cache rate does not push the run to
[PricingSource.Unknown](/api/tracon.pricingsource/): the cached tokens are then priced
at the normal input rate and the total stays exactly what it was before
this field existed. [PricingSource.Unknown](/api/tracon.pricingsource/) means the MODEL
price is missing, which is a different fault.

### <a id="Tracon_RunCost_CachedInputPricePerMillionTokens"></a> CachedInputPricePerMillionTokens

Gets the cache-read price, per million tokens, that produced
`CachedInputCost`. [null](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null) when no cache rate
was applied — either the cache rate is undefined, or the provider
reported no cache read at all — or when the run's tokens were priced at
more than one model.

```csharp
public decimal? CachedInputPricePerMillionTokens { get; init; }
```

#### Property Value

 [decimal](https://learn.microsoft.com/dotnet/api/system.decimal)?

#### Remarks

Not a cost addend — see [RunCost.InputPricePerMillionTokens](/api/tracon.runcost/#Tracon_RunCost_InputPricePerMillionTokens).

### <a id="Tracon_RunCost_Currency"></a> Currency

Gets the currency, taken from `Tracon:Pricing:Currency`.

```csharp
public string? Currency { get; init; }
```

#### Property Value

 [string](https://learn.microsoft.com/dotnet/api/system.string)?

#### Remarks

Required whenever [RunCost.Source](/api/tracon.runcost/#Tracon_RunCost_Source) is not [PricingSource.Unknown](/api/tracon.pricingsource/):
a known price with no currency label is a resolver defect, not a legitimate state.

### <a id="Tracon_RunCost_InputCost"></a> InputCost

Gets the input token cost, or [null](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null) when the price is unknown.

```csharp
public decimal? InputCost { get; init; }
```

#### Property Value

 [decimal](https://learn.microsoft.com/dotnet/api/system.decimal)?

### <a id="Tracon_RunCost_InputPricePerMillionTokens"></a> InputPricePerMillionTokens

Gets the input price, per million tokens, that produced
`InputCost`. [null](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null) when the price is unknown, or
when the run's tokens were priced at more than one model.

```csharp
public decimal? InputPricePerMillionTokens { get; init; }
```

#### Property Value

 [decimal](https://learn.microsoft.com/dotnet/api/system.decimal)?

#### Remarks

This is not a fourth addend of [RunCost.Total](/api/tracon.runcost/#Tracon_RunCost_Total): it is the rate, not
an amount. Adding it to the cost total would double-count the same charge
on a different scale — [RunCost.Total](/api/tracon.runcost/#Tracon_RunCost_Total) sums only [RunCost.InputCost](/api/tracon.runcost/#Tracon_RunCost_InputCost),
[RunCost.OutputCost](/api/tracon.runcost/#Tracon_RunCost_OutputCost) and [RunCost.CachedInputCost](/api/tracon.runcost/#Tracon_RunCost_CachedInputCost).

### <a id="Tracon_RunCost_OutputCost"></a> OutputCost

Gets the output token cost, or [null](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null) when the price is unknown.

```csharp
public decimal? OutputCost { get; init; }
```

#### Property Value

 [decimal](https://learn.microsoft.com/dotnet/api/system.decimal)?

### <a id="Tracon_RunCost_OutputPricePerMillionTokens"></a> OutputPricePerMillionTokens

Gets the output price, per million tokens, that produced
`OutputCost`. [null](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null) when the price is unknown, or
when the run's tokens were priced at more than one model.

```csharp
public decimal? OutputPricePerMillionTokens { get; init; }
```

#### Property Value

 [decimal](https://learn.microsoft.com/dotnet/api/system.decimal)?

#### Remarks

Not a cost addend — see [RunCost.InputPricePerMillionTokens](/api/tracon.runcost/#Tracon_RunCost_InputPricePerMillionTokens).

### <a id="Tracon_RunCost_Source"></a> Source

Gets where the price came from.

```csharp
public required PricingSource Source { get; init; }
```

#### Property Value

 [PricingSource](/api/tracon.pricingsource/)

## Methods

### <a id="Tracon_RunCost_Equals_System_Object_"></a> Equals\(object?\)

```csharp
public override bool Equals(object? obj)
```

#### Parameters

`obj` [object](https://learn.microsoft.com/dotnet/api/system.object)?

#### Returns

 [bool](https://learn.microsoft.com/dotnet/api/system.boolean)

### <a id="Tracon_RunCost_Equals_Tracon_RunCost_"></a> Equals\(RunCost?\)

```csharp
public bool Equals(RunCost? other)
```

#### Parameters

`other` [RunCost](/api/tracon.runcost/)?

#### Returns

 [bool](https://learn.microsoft.com/dotnet/api/system.boolean)

### <a id="Tracon_RunCost_GetHashCode"></a> GetHashCode\(\)

```csharp
public override int GetHashCode()
```

#### Returns

 [int](https://learn.microsoft.com/dotnet/api/system.int32)

### <a id="Tracon_RunCost_ToString"></a> ToString\(\)

```csharp
public override string ToString()
```

#### Returns

 [string](https://learn.microsoft.com/dotnet/api/system.string)

### <a id="Tracon_RunCost_Total"></a> Total\(\)

Gets the run's total cost — input, output and cache read together.

```csharp
public decimal? Total()
```

#### Returns

 [decimal](https://learn.microsoft.com/dotnet/api/system.decimal)?

[null](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null) when the run was never priced at all. Zero would
say "it cost nothing", which is a different claim.

#### Remarks

Every caller that needs "what did this run cost" must use THIS, never
`InputCost + OutputCost`. [RunCost.CachedInputCost](/api/tracon.runcost/#Tracon_RunCost_CachedInputCost) is a third
addend, not a subset of [RunCost.InputCost](/api/tracon.runcost/#Tracon_RunCost_InputCost): the resolver subtracts
the cached tokens out of the input charge and bills them here. A hand
written two-term sum under-reports every run that hit the prompt cache —
and a quota ceiling computed that way can be exceeded.
[RunCost.InputPricePerMillionTokens](/api/tracon.runcost/#Tracon_RunCost_InputPricePerMillionTokens), [RunCost.OutputPricePerMillionTokens](/api/tracon.runcost/#Tracon_RunCost_OutputPricePerMillionTokens)
and [RunCost.CachedInputPricePerMillionTokens](/api/tracon.runcost/#Tracon_RunCost_CachedInputPricePerMillionTokens) are rates, not amounts —
they must never be added here.

## Operators

### <a id="Tracon_RunCost_op_Equality_Tracon_RunCost_Tracon_RunCost_"></a> operator ==\(RunCost?, RunCost?\)

```csharp
public static bool operator ==(RunCost? left, RunCost? right)
```

#### Parameters

`left` [RunCost](/api/tracon.runcost/)?

`right` [RunCost](/api/tracon.runcost/)?

#### Returns

 [bool](https://learn.microsoft.com/dotnet/api/system.boolean)

### <a id="Tracon_RunCost_op_Inequality_Tracon_RunCost_Tracon_RunCost_"></a> operator \!=\(RunCost?, RunCost?\)

```csharp
public static bool operator !=(RunCost? left, RunCost? right)
```

#### Parameters

`left` [RunCost](/api/tracon.runcost/)?

`right` [RunCost](/api/tracon.runcost/)?

#### Returns

 [bool](https://learn.microsoft.com/dotnet/api/system.boolean)
