Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ jobs:
- name: Vet integration tests
run: go vet -tags integration ./...

- name: Vet price check
run: go vet -tags pricecheck ./...

- name: Test
run: go test -race -coverprofile=coverage.out ./...

Expand Down
57 changes: 57 additions & 0 deletions .github/workflows/pricing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Pricing

on:
schedule:
- cron: "17 6 * * 1"
workflow_dispatch:
pull_request:
paths:
- pricing.go
- pricing_feed_test.go
- pricing_live_test.go
- claude.go
- codex.go
- copilot.go
- opencode.go
- .github/workflows/pricing.yml

defaults:
run:
shell: bash -euo pipefail {0}

permissions: {}

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

jobs:
feed:
name: compare with models.dev
runs-on: ubuntu-24.04
timeout-minutes: 15
permissions:
contents: read
steps:
- name: Set up Git repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false

- name: Set up Go
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version-file: go.mod
cache: false

- name: Compare the pricing table with the feed
run: go test -tags pricecheck -run '^TestPricingMatchesFeed$' -count=1 . 2>&1 | tee pricecheck.log

- name: Summarize
if: always()
run: |
{
echo '```'
cat pricecheck.log
echo '```'
} >> "${GITHUB_STEP_SUMMARY}"
6 changes: 6 additions & 0 deletions copilot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,9 @@ func TestCopilotStreamUsageLongPromptRate(t *testing.T) {
stream := strings.Join([]string{
`{"type":"assistant.usage","data":{"model":"claude-haiku-5.5","inputTokens":100000,"outputTokens":1000}}`,
`{"type":"assistant.usage","data":{"model":"claude-haiku-5.5","inputTokens":100001,"outputTokens":1000}}`,
`{"type":"assistant.usage","data":{"model":"gpt-5.5","inputTokens":272000,"outputTokens":1000,"cacheReadTokens":200000}}`,
`{"type":"assistant.usage","data":{"model":"gpt-5.5","inputTokens":272001,"outputTokens":1000,"cacheReadTokens":200000}}`,
`{"type":"assistant.usage","data":{"model":"gpt-5.6-sol","inputTokens":300000,"outputTokens":1000,"cacheReadTokens":100000,"cacheWriteTokens":50000}}`,
}, "\n")

var costs []float64
Expand All @@ -379,6 +382,9 @@ func TestCopilotStreamUsageLongPromptRate(t *testing.T) {
want := []float64{
(100000*0.10 + 1000*0.50) / 1e6,
(100001*0.50 + 1000*2.50) / 1e6,
(72000*5.00 + 200000*0.50 + 1000*30.00) / 1e6,
(72001*10.00 + 200000*1.00 + 1000*45.00) / 1e6,
(150000*8.00 + 100000*0.80 + 50000*10.00 + 1000*30.00) / 1e6,
}
if len(costs) != len(want) {
t.Fatalf("usage costs = %v, want %v", costs, want)
Expand Down
39 changes: 27 additions & 12 deletions pricing.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,26 @@ func (p modelPrice) forPrompt(tokens int) modelPrice {
return p
}

// over returns p with long as its rates for prompts above tokens.
func (p modelPrice) over(tokens int, long modelPrice) modelPrice {
p.LongPromptOver = tokens
p.LongPrompt = &long
return p
}

// openAILongPrompt is the prompt size above which OpenAI charges its
// long-context rates.
const openAILongPrompt = 272_000

// modelPricing lets callers calculate cost when a backend reports tokens but
// no dollar amount. Rows for backends that report cost directly remain here so
// tests can require every default model to have a known price.
//
// Prices are USD rates per million tokens. Copilot-only rows use
// the token prices returned by CLI 1.0.80's models.list, converting one AI
// credit to $0.01. Update this table with each backend's DefaultModels list.
// TestPricingMatchesFeed, built with the pricecheck tag, compares it with
// https://models.dev/api.json.
//
//nolint:mnd // pricing is data, and named constants would obscure the table
var modelPricing = map[string]modelPrice{
Expand Down Expand Up @@ -59,17 +72,22 @@ var modelPricing = map[string]modelPrice{
"claude-fable-5.2": {In: 8.00, Out: 40.00, CachedIn: 0.20, CacheWrite: 10.00},

// OpenAI
// Sol's promotional standard rates apply at least through 2026-11-21; recheck then.
// Sol's promotional standard rates apply through 2026-11-30.
// https://developers.openai.com/api/docs/pricing
modelGPT56SolID: {In: 4.00, Out: 20.00, CachedIn: 0.40, CacheWrite: 5.00},
"gpt-5.6-terra": {In: 2.00, Out: 12.00, CachedIn: 0.20, CacheWrite: 2.50},
"gpt-5.6-luna": {In: 0.20, Out: 1.20, CachedIn: 0.02, CacheWrite: 0.25},
modelGPT55ID: {In: 5.00, Out: 30.00, CachedIn: 0.50},
modelGPT54ID: {In: 2.50, Out: 15.00, CachedIn: 0.25},
modelGPT56SolID: modelPrice{In: 4.00, Out: 20.00, CachedIn: 0.40, CacheWrite: 5.00}.
over(openAILongPrompt, modelPrice{In: 8.00, Out: 30.00, CachedIn: 0.80, CacheWrite: 10.00}),
"gpt-5.6-terra": modelPrice{In: 2.00, Out: 12.00, CachedIn: 0.20, CacheWrite: 2.50}.
over(openAILongPrompt, modelPrice{In: 4.00, Out: 18.00, CachedIn: 0.40, CacheWrite: 5.00}),
"gpt-5.6-luna": modelPrice{In: 0.20, Out: 1.20, CachedIn: 0.02, CacheWrite: 0.25}.
over(openAILongPrompt, modelPrice{In: 0.40, Out: 1.80, CachedIn: 0.04, CacheWrite: 0.50}),
modelGPT55ID: modelPrice{In: 5.00, Out: 30.00, CachedIn: 0.50}.
over(openAILongPrompt, modelPrice{In: 10.00, Out: 45.00, CachedIn: 1.00}),
modelGPT54ID: modelPrice{In: 2.50, Out: 15.00, CachedIn: 0.25}.
over(openAILongPrompt, modelPrice{In: 5.00, Out: 22.50, CachedIn: 0.50}),
modelGPT54MiniID: {In: 0.75, Out: 4.50, CachedIn: 0.075},
modelGPT53CodexID: {In: 1.75, Out: 14.00, CachedIn: 0.175},
"gpt-5.2": {In: 1.75, Out: 14.00, CachedIn: 0.175},
"gpt-5-mini": {In: 0.25, Out: 2.00, CachedIn: 0.02},
"gpt-5-mini": {In: 0.25, Out: 2.00, CachedIn: 0.025},

// Copilot-hosted Microsoft, Google, and xAI models.
"mai-code-1-flash-picker": {In: 0.75, Out: 4.50, CachedIn: 0.07},
Expand All @@ -85,11 +103,8 @@ var modelPricing = map[string]modelPrice{
// claudeHaiku55Price is five times dearer for prompts over 100,000 tokens.
//
//nolint:mnd // pricing is data
var claudeHaiku55Price = modelPrice{
In: 0.10, Out: 0.50, CachedIn: 0.01, CacheWrite: 0.125,
LongPromptOver: 100_000,
LongPrompt: &modelPrice{In: 0.50, Out: 2.50, CachedIn: 0.05, CacheWrite: 0.625},
}
var claudeHaiku55Price = modelPrice{In: 0.10, Out: 0.50, CachedIn: 0.01, CacheWrite: 0.125}.
over(100_000, modelPrice{In: 0.50, Out: 2.50, CachedIn: 0.05, CacheWrite: 0.625})

const perMillion = 1e6

Expand Down
Loading
Loading