Cost Tracking
Opik has been designed to track and monitor costs for your LLM applications by measuring token usage across all traces. Using the Opik dashboard, you can analyze spending patterns and quickly identify cost anomalies. All costs across Opik are estimated and displayed in USD.
Monitoring Costs in the Dashboard
You can use the Opik dashboard to review costs at three levels: spans, traces, and projects. Each level provides different insights into your application's cost structure.
Span-Level Costs
Individual spans show the computed costs (in USD) for each LLM spans of your traces:
Trace-Level Costs
Opik automatically aggregates costs from all spans within a trace to compute total trace costs:
Project-Level Analytics
Track your overall project costs in:
-
The main project view, through the Estimated Cost column:
-
The project Metrics tab, which shows cost trends over time:
Retrieving Costs Programmatically
You can retrieve the estimated cost programmatically for both spans and traces. Note that the cost will be None
if the span or trace used an unsupported model. See Exporting Traces and Spans for more ways of exporting traces and spans.
Retrieving Span Costs
import opik
client = opik.Client()
span = client.get_span_content(SPAN_ID)
# Returns estimated cost in USD, or None for unsupported models
print(span.total_estimated_cost)
Retrieving Trace Costs
import opik
client = opik.Client()
trace = client.get_trace_content(TRACE_ID)
# Returns estimated cost in USD, or None for unsupported models
print(trace.total_estimated_cost)
Supported Models and Integrations
Opik currently calculates costs automatically when you use the OpenAI Integration with a Text Models hosted on openai.com.
We are actively expanding our cost tracking support. Need support for additional models or providers? Please open a feature request to help us prioritize development.