Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

Price current Claude and OpenAI models, and future releases by family (#4638)

Artem Danilovc53b154a473a
diff --git a/app/models/llm_usage.rb b/app/models/llm_usage.rb
index 2f5e437126..a5efa10d59 100644
--- a/app/models/llm_usage.rb
+++ b/app/models/llm_usage.rb
@@ -18,6 +18,20 @@ class LlmUsage < ApplicationRecord
# Source: https://developers.openai.com/api/docs/pricing
PRICING = {
"openai" => {
+ # GPT-6 Astra, GPT-6.1 Terra and GPT-6 Luna Standard pricing, November 2026.
+ # Source: https://developers.openai.com/api/docs/models/gpt-6-astra (and -6.1-terra, -6-luna)
+ "gpt-6-astra" => {
+ prompt: 10.00, completion: 50.00,
+ long_context: { threshold: 272_000, prompt: 20.00, completion: 75.00 }
+ },
+ "gpt-6.1-terra" => {
+ prompt: 1.00, completion: 5.00,
+ long_context: { threshold: 272_000, prompt: 2.00, completion: 7.50 }
+ },
+ "gpt-6-luna" => {
+ prompt: 0.10, completion: 0.50,
+ long_context: { threshold: 272_000, prompt: 0.20, completion: 0.75 }
+ },
# GPT-6.1 Sol Standard pricing, September 2026.
# Source: https://developers.openai.com/api/docs/models/gpt-6.1-sol
"gpt-6.1-sol" => {
@@ -36,13 +50,25 @@ class LlmUsage < ApplicationRecord
"gpt-4.1-nano" => { prompt: 0.10, completion: 0.40 },
# 4o
"gpt-4o" => { prompt: 2.50, completion: 10.00 },
+ "gpt-4o-2024-05-13" => { prompt: 5.00, completion: 15.00 },
"gpt-4o-mini" => { prompt: 0.15, completion: 0.60 },
+ # Specialized models
+ "chat-latest" => { prompt: 5.00, completion: 30.00 },
+ "gpt-5.3-codex" => { prompt: 1.75, completion: 14.00 },
# GPT-5 models
# Sol promotion effective 2026-08-21, available at least through 2026-11-21.
"gpt-5.6-sol" => {
prompt: 4.00, completion: 20.00,
long_context: { threshold: 272_000, prompt: 8.00, completion: 30.00 }
},
+ # OpenAI routes the gpt-5.6 alias to GPT-5.6 Sol.
+ "gpt-5.6" => {
+ prompt: 4.00, completion: 20.00,
+ long_context: { threshold: 272_000, prompt: 8.00, completion: 30.00 }
+ },
+ # Trusted-access cyber models; listed so they don't match the rows above.
+ "gpt-5.6-cyber" => { prompt: 12.50, completion: 75.00 },
+ "gpt-5.5-cyber" => { prompt: 12.50, completion: 75.00 },
# Terra and Luna price reductions effective 2026-07-30.
"gpt-5.6-terra" => {
prompt: 2.00, completion: 12.00,
@@ -82,12 +108,31 @@ class LlmUsage < ApplicationRecord
"gpt-5-pro" => { prompt: 15.00, completion: 120.00 },
# o1 models
"o1-mini" => { prompt: 1.10, completion: 4.40 },
+ "o1-pro" => { prompt: 150.00, completion: 600.00 },
"o1" => { prompt: 15.00, completion: 60.00 },
# o-series models
"o3" => { prompt: 2.00, completion: 8.00 },
"o4-mini" => { prompt: 1.10, completion: 4.40 },
"o3-mini" => { prompt: 1.10, completion: 4.40 },
- "o3-pro" => { prompt: 20.00, completion: 80.00 }
+ "o3-pro" => { prompt: 20.00, completion: 80.00 },
+ # Tier fallbacks: an unlisted release of a tier (e.g. "gpt-6.2-sol",
+ # "gpt-7-astra") is estimated at that tier's newest listed rate.
+ "gpt-astra" => {
+ prompt: 10.00, completion: 50.00,
+ long_context: { threshold: 272_000, prompt: 20.00, completion: 75.00 }
+ },
+ "gpt-sol" => {
+ prompt: 2.00, completion: 10.00,
+ long_context: { threshold: 272_000, prompt: 4.00, completion: 15.00 }
+ },
+ "gpt-terra" => {
+ prompt: 1.00, completion: 5.00,
+ long_context: { threshold: 272_000, prompt: 2.00, completion: 7.50 }
+ },
+ "gpt-luna" => {
+ prompt: 0.10, completion: 0.50,
+ long_context: { threshold: 272_000, prompt: 0.20, completion: 0.75 }
+ }
},
# Source: https://ai.google.dev/gemini-api/docs/pricing
"google" => {
@@ -120,12 +165,37 @@ class LlmUsage < ApplicationRecord
"gemini-2.5-flash" => { prompt: 0.30, completion: 2.50 }
},
# Source: https://platform.claude.com/docs/en/about-claude/pricing
+ # cache_read is set only where Anthropic lists a rate other than 0.1x input.
"anthropic" => {
+ "claude-fable-5-1" => { prompt: 10.00, completion: 50.00, cache_read: 0.25 },
+ "claude-fable-5" => { prompt: 10.00, completion: 50.00 },
+ "claude-opus-5-5" => { prompt: 4.00, completion: 20.00, cache_read: 0.20 },
+ "claude-opus-5" => { prompt: 5.00, completion: 25.00 },
+ "claude-opus-4-8" => { prompt: 5.00, completion: 25.00 },
"claude-opus-4-7" => { prompt: 5.00, completion: 25.00 },
"claude-opus-4-6" => { prompt: 5.00, completion: 25.00 },
+ "claude-opus-4-5" => { prompt: 5.00, completion: 25.00 },
+ "claude-opus-4-1" => { prompt: 15.00, completion: 75.00 },
+ "claude-opus-4" => { prompt: 15.00, completion: 75.00 },
+ "claude-sonnet-5-5" => { prompt: 2.00, completion: 10.00, cache_read: 0.10 },
+ "claude-sonnet-5" => { prompt: 2.00, completion: 10.00 },
"claude-sonnet-4-6" => { prompt: 3.00, completion: 15.00 },
"claude-sonnet-4-5" => { prompt: 3.00, completion: 15.00 },
- "claude-haiku-4-5" => { prompt: 1.00, completion: 5.00 }
+ "claude-sonnet-4" => { prompt: 3.00, completion: 15.00 },
+ "claude-haiku-5-5" => {
+ prompt: 0.10, completion: 0.50,
+ long_context: { threshold: 100_000, prompt: 0.50, completion: 2.50 }
+ },
+ "claude-haiku-4-5" => { prompt: 1.00, completion: 5.00 },
+ # Family fallbacks: a Claude model released after this review (e.g.
+ # "claude-opus-6") is estimated at its family's newest listed rate.
+ "claude-fable" => { prompt: 10.00, completion: 50.00, cache_read: 0.25 },
+ "claude-opus" => { prompt: 4.00, completion: 20.00, cache_read: 0.20 },
+ "claude-sonnet" => { prompt: 2.00, completion: 10.00, cache_read: 0.10 },
+ "claude-haiku" => {
+ prompt: 0.10, completion: 0.50,
+ long_context: { threshold: 100_000, prompt: 0.50, completion: 2.50 }
+ }
}
}.freeze
@@ -144,8 +214,11 @@ class LlmUsage < ApplicationRecord
return nil
end
+ # Anthropic reports cached input apart from input_tokens, but its
+ # long-context tier counts cache reads and writes in the prompt length.
+ cached_input_tokens = provider == "anthropic" ? cache_creation_tokens.to_i + cache_read_tokens.to_i : 0
long_context = pricing[:long_context]
- if apply_long_context_pricing && long_context && prompt_tokens > long_context[:threshold]
+ if apply_long_context_pricing && long_context && prompt_tokens + cached_input_tokens > long_context[:threshold]
pricing = long_context
end
@@ -154,7 +227,8 @@ class LlmUsage < ApplicationRecord
completion_cost = (completion_tokens * pricing[:completion]) / 1_000_000.0
# Anthropic prompt-cache tokens bill relative to the input rate: cache
- # writes at 1.25x, cache reads at 0.1x. These multipliers are Anthropic's;
+ # writes at 1.25x, cache reads at 0.1x unless the model lists its own
+ # cache_read rate. These multipliers are Anthropic's;
# gate on the provider so a non-Anthropic caller that happens to pass cache
# counts can't be priced with the wrong rates (OpenAI cache rates vary by
# model). Without cache pricing at all, estimated_cost
@@ -163,7 +237,7 @@ class LlmUsage < ApplicationRecord
cache_read_cost = 0.0
if provider == "anthropic"
cache_creation_cost = (cache_creation_tokens.to_i * pricing[:prompt] * 1.25) / 1_000_000.0
- cache_read_cost = (cache_read_tokens.to_i * pricing[:prompt] * 0.10) / 1_000_000.0
+ cache_read_cost = (cache_read_tokens.to_i * (pricing[:cache_read] || pricing[:prompt] * 0.10)) / 1_000_000.0
end
cost = (prompt_cost + completion_cost + cache_creation_cost + cache_read_cost).round(6)
@@ -179,17 +253,28 @@ class LlmUsage < ApplicationRecord
provider_pricing = PRICING[provider]
+ # Claude: the exact version row (ignoring snapshot dates and suffixes), else
+ # the family row, so "claude-opus-5-6" doesn't take the "claude-opus-5" rate.
+ # OpenRouter writes versions with dots ("claude-opus-4.6").
+ if provider == "anthropic"
+ family, version = model.tr(".", "-").match(/\A(claude-[a-z]+)((?:-\d{1,2}(?!\d))*)/)&.captures
+ # "-4-0" aliases ("claude-opus-4-0") name the "-4" rows.
+ return family && (provider_pricing["#{family}#{version.delete_suffix("-0")}"] || provider_pricing[family])
+ end
+
# Try exact match first
return provider_pricing[model] if provider_pricing.key?(model)
# Try prefix matching longest-first so snapshot IDs for variants (e.g.,
# "gpt-5.4-mini-2026-03-17") do not match a broader family row
- # ("gpt-5.4") before their specific pricing row.
+ # ("gpt-5.4") before their specific pricing row. A row covers its snapshots
+ # but not later versions: "gpt-5" must not price "gpt-5.7-sol".
provider_pricing.sort_by { |model_prefix, _pricing| -model_prefix.length }.each do |model_prefix, pricing|
- return pricing if model.start_with?(model_prefix)
+ return pricing if model.start_with?(model_prefix) && !model.delete_prefix(model_prefix).match?(/\A\.?\d/)
end
- nil
+ tier = model[/\Agpt-[\d.]+-(astra|sol|terra|luna)\b/, 1]
+ tier && provider_pricing["gpt-#{tier}"]
end
# Infer provider from model name by checking which provider has pricing for it
diff --git a/app/models/provider/openai/usage_cost.rb b/app/models/provider/openai/usage_cost.rb
index b2f0178962..78a4b69886 100644
--- a/app/models/provider/openai/usage_cost.rb
+++ b/app/models/provider/openai/usage_cost.rb
@@ -3,13 +3,26 @@ class Provider::Openai::UsageCost
reported_cost = openrouter_cost(usage["cost"], uri_base)
return reported_cost unless reported_cost.nil?
+ prompt_tokens = usage["prompt_tokens"] || usage["input_tokens"] || 0
+ cache_read_tokens = anthropic_cache_read_tokens(model, usage)
+
LlmUsage.calculate_cost(
model: model,
- prompt_tokens: usage["prompt_tokens"] || usage["input_tokens"] || 0,
- completion_tokens: usage["completion_tokens"] || usage["output_tokens"] || 0
+ prompt_tokens: [ prompt_tokens - cache_read_tokens, 0 ].max,
+ completion_tokens: usage["completion_tokens"] || usage["output_tokens"] || 0,
+ cache_read_tokens: cache_read_tokens
)
end
+ # OpenAI-compatible usage counts cached input inside prompt_tokens. Claude
+ # bills it at its own cache-read rate, so split it out for Anthropic models.
+ private_class_method def self.anthropic_cache_read_tokens(model, usage)
+ return 0 unless LlmUsage.infer_provider(model) == "anthropic"
+
+ details = usage["prompt_tokens_details"] || usage["input_tokens_details"]
+ details.is_a?(Hash) ? details["cached_tokens"].to_i : 0
+ end
+
private_class_method def self.openrouter_cost(value, uri_base)
# OpenAI-compatible APIs do not share a currency contract for usage.cost.
# Only OpenRouter's official API reports the account charge in USD credits.
diff --git a/docs/hosting/ai.md b/docs/hosting/ai.md
index d3187fba81..5c521ded33 100644
--- a/docs/hosting/ai.md
+++ b/docs/hosting/ai.md
@@ -1134,9 +1134,11 @@ Good test queries that exercise different capabilities:
### Cloud Costs
-**Pricing table last updated and verified: October 17, 2026.** Every model
+**Full pricing table last verified: October 17, 2026.** Every model
listed in [`LlmUsage::PRICING`](../../app/models/llm_usage.rb) was checked against
-official sources. `PRICING_VERIFIED_ON` supplies the verification date shown on
+official sources on that date, except the Claude and OpenAI rows: those were
+last reviewed on November 1, 2026, without re-checking the Gemini rows.
+`PRICING_VERIFIED_ON` supplies the full-table verification date shown on
the LLM usage screen. This is a manual review date, not a claim that providers
changed every price that day.
@@ -1144,11 +1146,11 @@ Rates are USD per million tokens at the Standard tier. The source coverage is:
| Models in the code | Official pricing source |
| --- | --- |
-| GPT-6 Sol/6.1 Sol, GPT-5.6, GPT-5.5, GPT-5.4, GPT-5.2, GPT-5.1, GPT-5, GPT-4.1, GPT-4o, o1, o3, o4-mini (including listed variants) | [OpenAI pricing](https://developers.openai.com/api/docs/pricing) |
+| GPT-6 Astra, GPT-6 Sol/6.1 Sol, GPT-6.1 Terra, GPT-6 Luna, GPT-5.6 (and its `gpt-5.6` alias for Sol), GPT-5.6/5.5 Cyber, GPT-5.5, GPT-5.4, GPT-5.3 Codex, GPT-5.2, GPT-5.1, GPT-5, GPT-4.1, GPT-4o, o1/o1-pro, o3, o4-mini, chat-latest (including listed variants) | [OpenAI pricing](https://developers.openai.com/api/docs/pricing) |
| GPT-5.2/5.1 Chat aliases | [GPT-5.2 Chat](https://developers.openai.com/api/docs/models/gpt-5.2-chat-latest), [GPT-5.1 Chat](https://developers.openai.com/api/docs/models/gpt-5.1-chat-latest) |
| o1-mini | [o1-mini](https://developers.openai.com/api/docs/models/o1-mini) |
| Gemini 4 Argon, 3.8/3.7/3.6/3.5 Flash, 3.5/3.1 Flash-Lite, 3.1 Pro, 3 Flash, 2.5 Pro/Flash | [Google pricing](https://ai.google.dev/gemini-api/docs/pricing) |
-| Claude Opus 4.6/4.7, Sonnet 4.5/4.6, Haiku 4.5 | [Anthropic pricing](https://platform.claude.com/docs/en/about-claude/pricing) |
+| Claude Fable 5/5.1, Opus 4/4.1/4.5/4.6/4.7/4.8/5/5.5, Sonnet 4/4.5/4.6/5/5.5, Haiku 4.5/5.5 | [Anthropic pricing](https://platform.claude.com/docs/en/about-claude/pricing) |
#### Dated pricing changes
@@ -1174,7 +1176,8 @@ and Gemini 3.8, 3.7, and 3.6 Flash through December 31, 2026.
#### Context tiers and estimate limits
-OpenAI's listed GPT-6 Sol, GPT-6.1 Sol, GPT-5.6, GPT-5.5/Pro and GPT-5.4/Pro
+OpenAI's listed GPT-6 Astra, GPT-6 Sol, GPT-6.1 Sol, GPT-6.1 Terra, GPT-6 Luna,
+GPT-5.6, GPT-5.5/Pro and GPT-5.4/Pro
rates increase above 272,000 input tokens: input doubles and output increases
by 50% for the entire request. GPT-5.4 mini/nano retain their flat rates.
Gemini 4 Argon is $2.00 / $10.00 through November 2026 ($4.00 / $20.00 standard starting
@@ -1186,7 +1189,17 @@ $4.00 / $18.00 above 200,000 input tokens. Gemini 3.8 Flash, 3.7 Flash, and
Gemini 3.5 Flash is $1.50 / $9.00, Gemini 3.5 Flash-Lite is $0.30 / $2.50,
Gemini 3.1 Flash-Lite is $0.25 / $1.50, Gemini 3 Flash is $0.50 / $3.00,
and Gemini 2.5 Flash remains $0.30 / $2.50.
-Claude 4.6/4.7 use standard rates throughout their context window.
+Claude Haiku 5.5 changes from $0.10 / $0.50 to $0.50 / $2.50 above 100,000
+prompt tokens, counting cache reads and writes. Other Claude models use
+standard rates throughout their context window. Claude cache reads cost 0.1x
+input, except Opus 5.5 and Sonnet 5.5 (0.05x) and Fable 5.1 (0.025x).
+A Claude model released after the last review (for example `claude-opus-6`)
+is estimated at the newest listed rate of its family (Fable, Opus, Sonnet or
+Haiku) until the table is updated. Likewise, an unlisted release of an OpenAI
+tier (for example `gpt-6.2-sol` or `gpt-7-astra`) is estimated at the newest
+listed Astra, Sol, Terra or Luna rate. A listed version row covers its dated snapshots but not
+later versions, so other unlisted OpenAI models (for example `gpt-5.9`) show
+no estimate instead of an older model's rate.
Sure estimates individual requests using these tiers. Aggregate categorization
previews assume short requests. For [OpenRouter's official API endpoints](https://openrouter.ai/docs/cookbook/administration/usage-accounting), saved
@@ -1196,8 +1209,10 @@ invalid costs, use the bundled estimates. Unknown models can therefore have a
recorded post-call cost even when their pre-run estimate is N/A. Saved usage costs
are not recalculated. Estimates exclude regional premiums,
alternative service tiers, tool charges and audio-specific rates. Anthropic
-five-minute cache writes and reads are included when reported; OpenAI and Gemini
-cache discounts and cache-write/storage charges are not currently modeled.
+five-minute cache writes and reads are included when reported. For Claude models
+reached through an OpenAI-compatible endpoint, `cached_tokens` are priced at the
+Claude cache-read rate. OpenAI and Gemini cache discounts and
+cache-write/storage charges are not currently modeled.
Custom endpoints may charge different rates.
For comparison, GPT-4.1 is $2 input / $8 output, GPT-5 is $1.25 / $10,
diff --git a/test/models/llm_usage_test.rb b/test/models/llm_usage_test.rb
index 119dbc3e3a..8554238812 100644
--- a/test/models/llm_usage_test.rb
+++ b/test/models/llm_usage_test.rb
@@ -145,7 +145,86 @@ class LlmUsageTest < ActiveSupport::TestCase
end
end
+ test "calculate_cost uses Claude Opus 5.5 rates with its 0.05x cache read" do
+ cost = LlmUsage.calculate_cost(
+ model: "claude-opus-5-5", prompt_tokens: 100_000, completion_tokens: 10_000,
+ cache_creation_tokens: 20_000, cache_read_tokens: 50_000
+ )
+
+ # $0.40 input + $0.20 output + $0.10 cache write + $0.01 cache read.
+ assert_in_delta 0.71, cost, 0.000001
+ end
+
+ { "claude-sonnet-5-5" => 0.10, "claude-fable-5-1" => 0.25, "claude-sonnet-5" => 0.20 }.each do |model, rate|
+ test "calculate_cost uses Anthropic's listed cache read rate for #{model}" do
+ assert_in_delta rate, LlmUsage.calculate_cost(
+ model: model, prompt_tokens: 0, completion_tokens: 0, cache_read_tokens: 1_000_000
+ ), 0.000001
+ end
+ end
+
+ test "Claude Haiku 5.5 long-context tier counts cached input in the prompt length" do
+ # 10K new + 95K cache read = 105K > 100K: $0.005 + $0.00475 + 1K output * $2.50.
+ assert_in_delta 0.01225, LlmUsage.calculate_cost(
+ model: "claude-haiku-5-5", prompt_tokens: 10_000, completion_tokens: 1_000, cache_read_tokens: 95_000
+ ), 0.000001
+ # 10K new + 95K cache write = 105K > 100K: $0.005 + $0.059375 + $0.0025.
+ assert_in_delta 0.066875, LlmUsage.calculate_cost(
+ model: "claude-haiku-5-5", prompt_tokens: 10_000, completion_tokens: 1_000, cache_creation_tokens: 95_000
+ ), 0.000001
+ assert_in_delta 0.0015, LlmUsage.calculate_cost(
+ model: "claude-haiku-5-5", prompt_tokens: 10_000, completion_tokens: 1_000
+ ), 0.000001
+ end
+
+ test "unlisted Claude models fall back to their family's newest rate" do
+ assert_equal "anthropic", LlmUsage.infer_provider("claude-opus-6")
+ assert_equal 4.00, LlmUsage.find_pricing("anthropic", "claude-opus-6")[:prompt]
+ assert_equal 2.00, LlmUsage.find_pricing("anthropic", "claude-sonnet-6-20270101")[:prompt]
+ assert_equal 0.10, LlmUsage.find_pricing("anthropic", "claude-haiku-6")[:prompt]
+ assert_equal 10.00, LlmUsage.find_pricing("anthropic", "claude-fable-6")[:prompt]
+ # A later minor version of a listed major still takes the family's newest rate.
+ assert_equal 4.00, LlmUsage.find_pricing("anthropic", "claude-opus-5-6")[:prompt]
+ assert_equal 0.20, LlmUsage.find_pricing("anthropic", "claude-opus-5-6")[:cache_read]
+
+ # Older listed models keep their own rate instead of the family fallback.
+ assert_equal 15.00, LlmUsage.find_pricing("anthropic", "claude-opus-4-1-20250805")[:prompt]
+ assert_equal 5.00, LlmUsage.find_pricing("anthropic", "claude-opus-4-5-20251101")[:prompt]
+ assert_equal 15.00, LlmUsage.find_pricing("anthropic", "claude-opus-4-0")[:prompt]
+ assert_equal 3.00, LlmUsage.find_pricing("anthropic", "claude-sonnet-4-0")[:prompt]
+ end
+
+ test "unlisted GPT-6 tier releases fall back to the tier's newest rate" do
+ assert_equal "openai", LlmUsage.infer_provider("gpt-6.2-sol")
+ assert_equal 2.00, LlmUsage.find_pricing("openai", "gpt-6.2-sol")[:prompt]
+ assert_equal 2.00, LlmUsage.find_pricing("openai", "gpt-5.7-sol")[:prompt]
+ assert_equal 1.00, LlmUsage.find_pricing("openai", "gpt-6.2-terra")[:prompt]
+ assert_equal 10.00, LlmUsage.find_pricing("openai", "gpt-7-astra-2027-01-01")[:prompt]
+
+ # A version row no longer prices later versions; unknown ones stay N/A.
+ assert_nil LlmUsage.find_pricing("openai", "gpt-5.9")
+ end
+
+ test "OpenAI rows still cover their dated snapshots" do
+ assert_equal 2.00, LlmUsage.find_pricing("openai", "gpt-4.1-2025-04-14")[:prompt]
+ assert_equal 2.50, LlmUsage.find_pricing("openai", "gpt-4o-2024-08-06")[:prompt]
+ assert_equal 5.00, LlmUsage.find_pricing("openai", "gpt-4o-2024-05-13")[:prompt]
+ assert_equal 150.00, LlmUsage.find_pricing("openai", "o1-pro-2025-03-19")[:prompt]
+ assert_equal 1.75, LlmUsage.find_pricing("openai", "gpt-5.3-codex")[:prompt]
+ assert_equal 4.00, LlmUsage.find_pricing("openai", "gpt-5.6")[:prompt]
+ assert_equal 12.50, LlmUsage.find_pricing("openai", "gpt-5.6-cyber")[:prompt]
+ end
+
+ test "find_pricing reads OpenRouter's dotted Claude versions" do
+ assert_equal 5.00, LlmUsage.find_pricing("anthropic", "anthropic/claude-opus-4.6")[:prompt]
+ assert_equal 15.00, LlmUsage.find_pricing("anthropic", "anthropic/claude-opus-4.1")[:prompt]
+ assert_equal 5.00, LlmUsage.find_pricing("anthropic", "anthropic/claude-opus-4.6:thinking")[:prompt]
+ end
+
{
+ "gpt-6-astra" => [ 15.0, 27.5 ],
+ "gpt-6.1-terra" => [ 1.5, 2.75 ],
+ "gpt-6-luna" => [ 0.15, 0.275 ],
"gpt-5.6-sol" => [ 6.0, 11.0 ],
"gpt-5.6-terra" => [ 3.2, 5.8 ],
"gpt-5.6-luna" => [ 0.32, 0.58 ],
diff --git a/test/models/provider/openai/usage_cost_test.rb b/test/models/provider/openai/usage_cost_test.rb
index 031dc76e03..b3d46b6795 100644
--- a/test/models/provider/openai/usage_cost_test.rb
+++ b/test/models/provider/openai/usage_cost_test.rb
@@ -41,6 +41,19 @@ class Provider::Openai::UsageCostTest < ActiveSupport::TestCase
Provider::Openai::UsageCost.calculate(model: "gpt-4.1", usage: usage, uri_base: @endpoint)
end
+ test "fallback prices cached Claude input at the cache read rate" do
+ usage = { "prompt_tokens" => 10_000, "completion_tokens" => 100, "prompt_tokens_details" => { "cached_tokens" => 8_000 } }
+
+ # Opus 5.5: 2K input * $4 + 8K cache read * $0.20 + 100 output * $20 per MTok.
+ assert_in_delta 0.0116, Provider::Openai::UsageCost.calculate(
+ model: "anthropic/claude-opus-5-5", usage: usage, uri_base: @endpoint
+ ), 0.000001
+
+ # Other providers keep the inclusive prompt count.
+ assert_equal LlmUsage.calculate_cost(model: "gpt-4.1", prompt_tokens: 10_000, completion_tokens: 100),
+ Provider::Openai::UsageCost.calculate(model: "gpt-4.1", usage: usage, uri_base: @endpoint)
+ end
+
test "only official OpenRouter API endpoints supply USD costs" do
%w[https://openrouter.ai/api/v1/ https://OPENROUTER.AI/api/v1 https://eu.openrouter.ai/api/v1 https://us.openrouter.ai/api/v1].each do |endpoint|
assert_equal BigDecimal("0.01"), calculate({ "cost" => 0.01 }, uri_base: endpoint)