---
title: "Usage and cost"
description: "Track requests, tokens and cost of translation calls."
canonical_url: "https://diglot.sh/machine-translation/usage-and-cost"
---
# Usage and cost

> Track requests, tokens and cost of translation calls.

Machine translation costs money, and a first run over a large documentation set can cost a lot. Every result of `translateSegments` and `updateTranslation` has a `usage` field so you can measure it.

```ts
const usage = {
  requests: 12,
  inputTokens: 48210,
  outputTokens: 9120,
  costUsd: 0.31,
}
```

The values above show the shape. `costUsd` is the cost reported by the provider, which the Vercel AI Gateway does for every request, or a figure computed from `pricing`. Pass `pricing: { input, output }` in USD per million tokens for providers that don't report a cost. When neither is available, `costUsd` is absent.

## Summing

`emptyUsage()` returns a zeroed usage record and `addUsage(a, b)` adds `b` into `a` and returns `a`. Use them to total several calls:

```ts
import { addUsage, emptyUsage } from '@diglot/mt'

const total = emptyUsage()
addUsage(total, first.usage)
addUsage(total, second.usage)
```

The Action does this per locale and exposes the total as the `costUsd` output.


## Sitemap

See the full [sitemap](https://diglot.sh/sitemap.md) for all pages.
