gen_ai.usage.cost) and an OpenTelemetry metric. No configuration is needed for standard models — cost tracking is on by default.
How it works
When your instrumented code calls an LLM, OpenLIT:- Reads the token usage from the API response (
prompt_tokens,completion_tokens). - Looks up the per-token price for that model from the built-in pricing database.
- Calculates the cost in USD and attaches it to the span and metric.
Default pricing source
By default, OpenLIT fetches pricing from:Custom pricing for fine-tuned or private models
If you use a fine-tuned model or a model not in the default pricing database, specify a custom pricing file via thepricing_json parameter:
Pricing JSON format
Your custom pricing file must follow the same schema as the default pricing file. The structure groups models by provider and specifies costs in USD per 1,000 tokens:If a model is not found in your custom pricing file, OpenLIT falls back to the default pricing database. If the model is not found there either, the
gen_ai.usage.cost attribute is omitted from the span.Disable cost tracking
To disable all metrics collection, including cost tracking:Cost in traces
Cost appears as thegen_ai.usage.cost span attribute on every instrumented LLM call. You can filter, group, and aggregate this attribute in any OTel-compatible backend to build cost dashboards, set alerts, or attribute costs to specific users or features.
Configuration
Full openlit.init() parameter reference including pricing_json
Tracing
All span attributes captured per LLM call
Destinations
Send cost metrics to Datadog, Grafana, New Relic, and more
