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.
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.
Individual spans show the computed costs (in USD) for each LLM spans of your traces:

If you are using one of Opik’s integrations, we automatically aggregates costs from all spans within a trace to compute total trace costs:

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:

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.
If you are not using one of Opik’s integration, Opik can still compute the cost. For you will need to ensure the
span type is llm and you will need to pass:
provider: The name of the provider, typically openai, anthropic or google_ai for example (the most recent providers list can be found in opik.LLMProvider enum object)model: The name of the modelusage: The input, output and total tokens for this LLM call.You can then update your code to log traces and spans:
If you are using function decorators, you will need to use the update_current_span method:
When you need to set a custom cost or use an unsupported model, you can manually set the cost of a span. There are two approaches depending on your use case:
If you’re manually creating spans, you can set the cost directly when creating the span:
With Opik integrations, spans are automatically created and closed, preventing updates while they’re open. However, you can update the cost afterward using the update_span method. This works well for implementing periodic cost estimation jobs:
This approach is particularly useful when:
You can run the cost update function as a CRON job to automatically update costs for spans created without cost information. This is especially valuable in production environments where accurate cost data for all spans is essential.
Opik currently calculates costs automatically for all LLM calls in the following Python SDK integrations:
Cost tracking is supported for the following LLM providers (as defined in opik.LLMProvider enum):
openai) - Models hosted by OpenAI (https://platform.openai.com)anthropic) - Models hosted by Anthropic (https://www.anthropic.com)anthropic_vertexai) - Anthropic models hosted by Google Vertex AIgoogle_ai) - Gemini models hosted in Google AI Studio (https://ai.google.dev/aistudio)google_vertexai) - Gemini models hosted in Google Vertex AI (https://cloud.google.com/vertex-ai)bedrock) - Models hosted by AWS Bedrock (https://aws.amazon.com/bedrock)groq) - Models hosted by Groq (https://groq.com)You can find a complete list of supported models for these providers in the model_prices_and_context_window.json file.
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.