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

# Calculate the cost of one LLM request

> Price recorded or estimated token usage with Pricing API and understand what the returned USD total does and does not include.

Calculate a request's cost when you have its model, provider, and token usage. You can use estimated counts for planning or recorded usage to price a completed call. Pricing API calculates a catalog-based dollar amount; this endpoint does not execute inference, charge a customer, or reconstruct a historical invoice.

## Request body

First [find the model and provider pair](https://www.narev.ai/docs/guides/search-model-prices.md) that matches the service you used. The example below prices 1,200 prompt tokens and 340 completion tokens for `gpt-4o` on `openai`. These are illustrative usage counts, not the expected length of a particular prompt.

```bash theme={null}
curl --fail-with-body -X POST 'https://api.narev.ai/v1/traces/cost' \
  -H 'Content-Type: application/json' \
  -d '{
    "model_id": "gpt-4o",
    "provider_id": "openai",
    "usage": {
      "prompt_tokens": 1200,
      "completion_tokens": 340
    }
  }'
```

Use counts reported by your inference provider when available. Character counts and word counts are not token counts. For a multi-call agent workflow, price every call, including retries and follow-up generations, before adding them into a workflow total.

## Response

The response identifies the priced pair and exposes `cost_breakdown.total` in USD. At the rates checked on September 9, 2026, the example returned:

```json theme={null}
{
  "model_id": "gpt-4o",
  "provider_id": "openai",
  "cost_breakdown": {
    "total": 0.0064
  }
}
```

That snapshot follows `1200 × 0.0000025 + 340 × 0.00001 = 0.0064`. Re-run the request for a current estimate. Preserve full precision when summing many calls and round for display afterward. The published response schema guarantees the total, so avoid depending on undocumented itemized response fields.

## Optional usage fields

The request also accepts `cache_read_tokens`, `cache_write_tokens`, `reasoning_tokens`, and `web_search_count`. The cache and reasoning fields default to zero. Supply the provider's usage breakdown rather than inferring cache hits from repeated prompt text.

Token totals and their subcategories must follow the selected provider's accounting. For direct DeepSeek, verified calls use total prompt tokens including cache hits and total completion tokens including reasoning. Do not subtract those subcategories before sending the totals; the [DeepSeek example](https://www.narev.ai/docs/guides/deepseek-v4-pricing.md) demonstrates the arithmetic. If your tracing system stores disjoint buckets, reconstruct totals before calling the endpoint. Do not assume that an unfamiliar provider or modality follows the same mapping without checking its usage contract.

## Check the result before using it

Check the HTTP response before reading the total. The [API reference](https://www.narev.ai/docs/pricing-api/reference/v1/traces/cost.md) documents validation failures, unavailable public pricing, and missing model/provider prices. Do not convert a failed lookup into a zero-cost request. Resolve the identifiers or pricing availability first.

This calculation uses the rates available at lookup time. A backfill over older usage is a current-rate estimate unless you separately retain the historical prices. Negotiated discounts and charges outside the supplied usage are also reasons your invoice can differ. For customer billing, define your sell price separately from this inference cost.

## Compare models fairly

Reusing this usage object across model pairs isolates rate differences. It does not predict how many tokens another model will consume: tokenization, reasoning, and output length can change. Follow [Compare cost between two models](https://www.narev.ai/docs/guides/compare-two-models.md) to turn the estimate into a workload evaluation.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.