From c262ec97d79f9d1540d354dd8b1e79babd84672d Mon Sep 17 00:00:00 2001 From: Aditya Vardhan Date: Thu, 16 Apr 2026 09:08:46 +0530 Subject: [PATCH 1/3] Docs mentioning genai-prices --- docs/guides/web-ui/llm-panels.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/guides/web-ui/llm-panels.md b/docs/guides/web-ui/llm-panels.md index 8e5c42e43..6f548d9f3 100644 --- a/docs/guides/web-ui/llm-panels.md +++ b/docs/guides/web-ui/llm-panels.md @@ -77,6 +77,12 @@ logfire.info( We are actively engaged with the OpenTelemetry community to improve the GenAI specification, so expect more instrumentations to be fully supported in the future. +### How costs are calculated + +Costs are calculated from [`genai-prices`](https://github.com/pydantic/genai-prices), an open dataset of provider and model pricing. Logfire looks up each LLM span's model and token counts in `genai-prices` to produce the USD values shown on the token badge and in the details panel. + +If a model isn't in the dataset, cost is omitted and token counts are still recorded. This is common for very new model releases, and for custom or fine-tuned models. Upgrading `genai-prices` (for example, `pip install -U genai-prices`) usually adds coverage for recently-released models. + ## Example LLM panel views ### Single‑prompt calls From dbc33d83ac017c039213e9d7273caa20dd57efdc Mon Sep 17 00:00:00 2001 From: Aditya Vardhan Date: Thu, 16 Apr 2026 09:12:49 +0530 Subject: [PATCH 2/3] no need of pip install here lol --- docs/guides/web-ui/llm-panels.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/guides/web-ui/llm-panels.md b/docs/guides/web-ui/llm-panels.md index 6f548d9f3..abe0c98e0 100644 --- a/docs/guides/web-ui/llm-panels.md +++ b/docs/guides/web-ui/llm-panels.md @@ -81,7 +81,7 @@ We are actively engaged with the OpenTelemetry community to improve the GenAI sp Costs are calculated from [`genai-prices`](https://github.com/pydantic/genai-prices), an open dataset of provider and model pricing. Logfire looks up each LLM span's model and token counts in `genai-prices` to produce the USD values shown on the token badge and in the details panel. -If a model isn't in the dataset, cost is omitted and token counts are still recorded. This is common for very new model releases, and for custom or fine-tuned models. Upgrading `genai-prices` (for example, `pip install -U genai-prices`) usually adds coverage for recently-released models. +If a model isn't in the dataset, cost is omitted and token counts are still recorded. This is common for very new model releases, and for custom or fine-tuned models. Upgrading `genai-prices` usually adds coverage for recently-released models. ## Example LLM panel views From 16012f8d4e4445a678b1b84858fe6d3d842e2e15 Mon Sep 17 00:00:00 2001 From: Alex Hall Date: Wed, 22 Apr 2026 15:10:54 +0200 Subject: [PATCH 3/3] update --- docs/guides/web-ui/llm-panels.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/guides/web-ui/llm-panels.md b/docs/guides/web-ui/llm-panels.md index abe0c98e0..259a964d5 100644 --- a/docs/guides/web-ui/llm-panels.md +++ b/docs/guides/web-ui/llm-panels.md @@ -79,9 +79,11 @@ We are actively engaged with the OpenTelemetry community to improve the GenAI sp ### How costs are calculated -Costs are calculated from [`genai-prices`](https://github.com/pydantic/genai-prices), an open dataset of provider and model pricing. Logfire looks up each LLM span's model and token counts in `genai-prices` to produce the USD values shown on the token badge and in the details panel. +Costs are calculated from [`genai-prices`](https://github.com/pydantic/genai-prices), an open dataset of provider and model pricing. -If a model isn't in the dataset, cost is omitted and token counts are still recorded. This is common for very new model releases, and for custom or fine-tuned models. Upgrading `genai-prices` usually adds coverage for recently-released models. +For the Pydantic AI, OpenAI, and Anthropic instrumentations, if `genai-prices` is installed locally, it will try to use it to calculate a cost. If it succeeds, it will be attached to the span as the attribute `operation.cost`. This attribute is always used in the Logfire UI when present. This is typically more accurate because it takes into account details like cached tokens. If you're using one of these instrumentations, make sure that `genai-prices` is installed (it's only installed automatically by Pydantic AI) and either update it regularly or use [`UpdatePrices`](https://github.com/pydantic/genai-prices/tree/main/packages/python#updateprices) to ensure you have prices for the latest models. + +If `operation.cost` isn't present on the span, then the Logfire UI will use `genai-prices` to calculate a cost based on the other span attributes, particularly the input and output tokens. This may be less accurate because it doesn't have access to details like cached tokens, but it will still give you a rough estimate of the cost. The UI automatically uses the latest data in `genai-prices`, even if it hasn't been released, but there might be some delay due to browser caching. The calculated cost will only be visible in the UI and can't be queried with SQL. ## Example LLM panel views