Skip to main content
The Pricing feature recalculates the gen_ai.usage.cost attribute on existing LLM traces using the per-model pricing stored in Manage Models. This is useful when:
  • Your SDK didn’t send cost data (or sent 0).
  • Model pricing has changed and you want historical traces to reflect the new prices.
  • You added a custom model after traces were already ingested.

How it works

For each trace, OpenLIT:
  1. Reads gen_ai.system (provider) and gen_ai.request.model from the span attributes.
  2. Looks up the matching model in the openlit_provider_models ClickHouse table.
  3. Computes the cost:
    cost = (input_tokens / 1,000,000) × input_price_per_m_token
         + (output_tokens / 1,000,000) × output_price_per_m_token
    
  4. Writes the result back to the trace:
    ALTER TABLE otel_traces
    UPDATE SpanAttributes = mapUpdate(SpanAttributes, map('gen_ai.usage.cost', '<cost>'))
    WHERE SpanId = '<span_id>'
    
Traces with missing provider, model, or zero tokens are skipped — they are not counted as errors. If the model is not found in Manage Models, the trace is also skipped. Add the model first, then recalculate.

Manual recalculation

Recalculate the cost for a single trace directly from the trace detail panel.
1

Open a trace

Navigate to Requests and click on any LLM trace to open the detail panel.
2

Click the recalculate icon

In the Cost metric card at the top of the panel, click the refresh icon (↻).
  • If the cost is missing or zero, a pinging dot draws attention to the icon.
  • If the cost already exists, clicking recalculates it using the latest pricing.
3

See the result

A toast notification shows the updated cost. The panel refreshes automatically to display the new value.
API: POST /api/pricing/{spanId} — returns { success, data: { spanId, cost } } or { success: false, err: "..." }.

Auto recalculation (cron-based)

Automatically recompute pricing on a schedule for all newly ingested LLM traces.
1

Open the Pricing page

Navigate to Pricing in the sidebar under the Configuration section.
2

Enable Auto Pricing

Toggle the Enable Auto Pricing switch.
3

Set the cron schedule

Enter a standard cron expression. For example:
  • */15 * * * * — every 15 minutes
  • 0 * * * * — every hour
  • 0 0 * * * — once a day at midnight
4

Save

Click Save (or Update if editing). OpenLIT installs a cron job that runs the pricing recalculation on the schedule you defined.

How auto pricing selects traces

On each cron tick:
StepWhat happens
1. Select LLM spansQueries otel_traces for spans whose gen_ai.operation.name matches supported LLM operations (e.g. chat).
2. Incremental windowOnly spans with Timestamp >= last successful cron run are processed. The first run processes all historical LLM spans.
3. Look up modelFor each span, reads gen_ai.system (provider) and gen_ai.request.model, then finds the matching row in openlit_provider_models.
4. Compute cost(input_tokens / 1M) × input_price + (output_tokens / 1M) × output_price.
5. Write backUpdates SpanAttributes['gen_ai.usage.cost'] on the trace via ALTER TABLE otel_traces UPDATE.
6. Log runRecords totalSpans, totalUpdated, totalFailed, totalSkipped in the cron log with a status of SUCCESS, PARTIAL_SUCCESS, or FAILURE.
Spans with missing provider/model/tokens or an unknown model are skipped (not counted as errors). Add the model to Manage Models and the next cron run will pick it up.

Cron restoration on restart

When the OpenLIT server restarts (e.g. after a container redeployment), all active auto-pricing cron jobs are automatically restored from the database. No manual re-setup is needed.

API reference

EndpointMethodDescription
/api/pricing/configGETGet the current pricing config (auto flag, cron schedule)
/api/pricing/configPOSTCreate or update pricing config
/api/pricing/{spanId}POSTManually recalculate cost for a single trace
/api/pricing/autoPOSTTrigger auto pricing run (called by cron; allowlisted in middleware)
/api/openground/models/exportGETExport all model pricing as downloadable JSON (authenticated)
/api/pricing/export/{dbConfigId}GETPublic pricing URL for SDK pricing_json (no auth)
/api/openground/models/importPOSTBulk-import models from JSON, skipping duplicates

Configuration

The pricing config is stored in the SQLite PricingConfigs table (managed by Prisma):
FieldTypeDescription
idStringConfig ID (auto-generated)
databaseConfigIdStringLinks to the ClickHouse database config
autoBooleanWhether auto pricing is enabled
recurringTimeStringCron schedule (e.g. */15 * * * *)
metaString (JSON)Internal metadata including cronJobId