Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Remove metabase.llm.costs (#69043)

appleby8824365c61dc
diff --git a/src/metabase/llm/api.clj b/src/metabase/llm/api.clj
index 7af29149197..8e1336ef653 100644
--- a/src/metabase/llm/api.clj
+++ b/src/metabase/llm/api.clj
@@ -15,7 +15,6 @@
[metabase.driver :as driver]
[metabase.llm.anthropic :as llm.anthropic]
[metabase.llm.context :as llm.context]
- [metabase.llm.costs :as llm.costs]
[metabase.llm.settings :as llm.settings]
[metabase.premium-features.core :as premium-features]
[metabase.request.core :as request]
@@ -92,9 +91,8 @@
codecs/bytes->hex)
token-or-uuid (or hashed-token
(str "oss__" (analytics/analytics-uuid)))
- estimated-costs (llm.costs/estimate {:model model
- :prompt prompt
- :completion completion})]
+ ;; Just report 0.0 as estimated cost rather than providing an estimate that is guaranteed to get stale.
+ estimated-costs 0.0]
(snowplow/track-event! :snowplow/token_usage
{:hashed-metabase-license-token token-or-uuid
:request-id request-id
diff --git a/src/metabase/llm/costs.clj b/src/metabase/llm/costs.clj
deleted file mode 100644
index c8577c0bdba..00000000000
--- a/src/metabase/llm/costs.clj
+++ /dev/null
@@ -1,62 +0,0 @@
-(ns metabase.llm.costs
- "LLM cost estimation utils."
- (:require
- [clojure.string :as str]))
-
-(def ^:private model-pricing
- "Model pricing by model family. Prices are in USD. :input and :output are per :scale tokens."
- {"anthropic/claude-3-5-haiku" {:input 0.80, :output 4.00, :scale 1000000},
- "anthropic/claude-3-7-sonnet" {:input 3.00, :output 15.00, :scale 1000000},
- "anthropic/claude-3-haiku" {:input 0.25, :output 1.25, :scale 1000000},
- "anthropic/claude-haiku-3" {:input 0.25, :output 1.25, :scale 1000000},
- "anthropic/claude-haiku-3-5" {:input 0.80, :output 4.00, :scale 1000000},
- "anthropic/claude-haiku-4-5" {:input 1.00, :output 5.00, :scale 1000000},
- "anthropic/claude-opus-4" {:input 15.00, :output 75.00, :scale 1000000},
- "anthropic/claude-opus-4-1" {:input 15.00, :output 75.00, :scale 1000000},
- "anthropic/claude-opus-4-5" {:input 5.00, :output 25.00, :scale 1000000},
- "anthropic/claude-sonnet-4" {:input 3.00, :output 15.00, :scale 1000000},
- "anthropic/claude-sonnet-4-5" {:input 3.00, :output 15.00, :scale 1000000}})
-
-(comment
- ;; Eval the following forms to get an updated model-pricing table with keys for new anthropic models. Unfortunately,
- ;; model prices don't seem to be fetchable via an API at time of writing, so you have have to look them up for any
- ;; new models at the following URL (we could scrape it, but seems fragile):
- ;;
- ;; https://platform.claude.com/docs/en/about-claude/pricing
-
- ;; First configure metabase.llm.settings/llm-anthropic-api-key with a valid key
- ((requiring-resolve 'metabase.llm.settings/llm-anthropic-api-key!) "<api-key>")
-
- (defn- merge-pricing [new-models]
- (merge new-models model-pricing))
-
- (->> ((requiring-resolve 'metabase.llm.anthropic/list-models))
- :models
- (map (fn [{:keys [id]}]
- [(normalize-model-name id) {:input nil :output nil :scale 1000000}]))
- (into {})
- merge-pricing
- (into (sorted-map))))
-
-(defn- normalize-model-name
- "Normalize a raw model name to the `provider/family` format used in the pricing table.
- Strips the date suffix (e.g. -20250514) and adds the anthropic/ prefix if missing.
-
- E.g. \"claude-sonnet-4-5-20250929\" -> \"anthropic/claude-sonnet-4-5\""
- [model]
- (when model
- (let [stripped (str/replace model #"-\d{8}$" "")]
- (if (str/starts-with? stripped "anthropic/")
- stripped
- (str "anthropic/" stripped)))))
-
-(defn estimate
- "Estimate the cost in USD for token usage.
-
- Accepts raw model names (e.g. \"claude-sonnet-4-5-20250929\") and normalizes
- them to match the pricing table. Returns 0.0 for unknown models."
- [{:keys [model prompt completion]}]
- (if-let [{:keys [input output scale]} (get model-pricing (normalize-model-name model))]
- (+ (* (/ (double prompt) scale) input)
- (* (/ (double completion) scale) output))
- 0.0))
diff --git a/test/metabase/llm/api_test.clj b/test/metabase/llm/api_test.clj
index a45c8818710..8cad9f5e305 100644
--- a/test/metabase/llm/api_test.clj
+++ b/test/metabase/llm/api_test.clj
@@ -183,7 +183,7 @@
"prompt_tokens" 1000
"completion_tokens" 200
"total_tokens" 1200
- "estimated_costs_usd" #(and (number? %) (pos? %))
+ "estimated_costs_usd" 0.0
"duration_ms" 500
"source" "oss_metabot"
"tag" "oss-sqlgen"}}]
@@ -241,7 +241,7 @@
"total_tokens" 1500
"prompt_tokens" 1000
"completion_tokens" 500
- "estimated_costs_usd" #(and (number? %) (pos? %))
+ "estimated_costs_usd" 0.0
"duration_ms" 1234
"source" "oss_metabot"
"tag" "oss-sqlgen"}}]
diff --git a/test/metabase/llm/costs_test.clj b/test/metabase/llm/costs_test.clj
deleted file mode 100644
index 732f6ebb2f4..00000000000
--- a/test/metabase/llm/costs_test.clj
+++ /dev/null
@@ -1,68 +0,0 @@
-(ns metabase.llm.costs-test
- (:require
- [clojure.test :refer :all]
- [mb.hawk.assert-exprs.approximately-equal :as =?]
- [metabase.llm.costs :as costs]))
-
-(set! *warn-on-reflection* true)
-
-(deftest ^:parallel estimate-simplified-models-test
- (testing "known models calculate correct costs"
- (is (=? (=?/approx [0.030 0.0001])
- (costs/estimate {:model "anthropic/claude-opus-4-5"
- :prompt 1000
- :completion 1000})))
- (is (=? (=?/approx [0.018 0.0001])
- (costs/estimate {:model "anthropic/claude-sonnet-4-5"
- :prompt 1000
- :completion 1000})))))
-
-(deftest ^:parallel estimate-raw-model-names-test
- (testing "raw model names with date suffixes are normalized correctly"
- (is (=? (=?/approx [0.030 0.0001])
- (costs/estimate {:model "claude-opus-4-5-20251101"
- :prompt 1000
- :completion 1000})))
- (is (=? (=?/approx [0.018 0.0001])
- (costs/estimate {:model "claude-sonnet-4-5-20250929"
- :prompt 1000
- :completion 1000}))))
- (testing "raw model names without date suffixes are normalized correctly"
- (is (=? (=?/approx [0.018 0.0001])
- (costs/estimate {:model "claude-sonnet-4"
- :prompt 1000
- :completion 1000})))))
-
-(deftest ^:parallel estimate-zero-tokens-test
- (testing "zero tokens returns zero cost"
- (is (= 0.0
- (costs/estimate {:model "claude-sonnet-4-5-20250929"
- :prompt 0
- :completion 0})))))
-
-(deftest ^:parallel estimate-unknown-model-test
- (testing "unknown model returns 0.0"
- (is (= 0.0
- (costs/estimate {:model "unknown-model-xyz"
- :prompt 1000
- :completion 1000})))))
-
-(deftest ^:parallel estimate-nil-model-test
- (testing "nil model returns 0.0"
- (is (= 0.0
- (costs/estimate {:model nil
- :prompt 1000
- :completion 1000})))))
-
-(deftest ^:parallel estimate-all-models-test
- (testing "all known models have valid pricing"
- (doseq [model (keys @#'costs/model-pricing)]
- (testing (str "model: " model)
- (is (pos? (costs/estimate {:model model
- :prompt 1000
- :completion 1000}))
- "should have positive cost for non-zero tokens")
- (is (= 0.0 (costs/estimate {:model model
- :prompt 0
- :completion 0}))
- "should have zero cost for zero tokens")))))