usage: GPT-6.2's Ultrafast is priced at OpenAI's 3x, then 6x from March 1st (mu33410 on X)

mu33410 on X asked whether the cost magpie shows is adjusted for GPT's
fast modes. Mostly it was: a call is priced at the tier its reply named
(else the one sent, which is what a Codex/ChatGPT row has) from
models.dev's experimental.modes, on every route (Responses, Chat
Completions, the Responses WebSocket, which goes through the same
handler, and Codex's backend), in the Usage page, a key's spend limit
and a subscription window's API value. Checked against OpenAI's pricing
page: Fast (priority) is 2x on every model that lists it, Flex 0.5x,
Ultrafast 6x on GPT-6 Astra and GPT-6.1 Sol, all matching.

The gap: OpenAI prices GPT-6.2 Astra's and Sol's Ultrafast at "3 times
the Standard rate through February 28, 2027" and "6 times the Standard
rate starting March 1, 2027 (Pacific time)", and models.dev lists their
ultrafast mode with no cost. TierPrice skipped it, so every GPT-6.2
Ultrafast call, on an OpenAI key or a Codex subscription, was priced at
the standard rate, below Fast.

catalog.TierTimes holds that dated multiple; TierPrice takes the call's
time and gives the standard price times the multiple of its day, every
part and the long-context rate with it (Price.Times). The price caches in
Pricer and apiPricer key on the day's rate (Record.tierKey), and the
request-index ask names it, so calls either side of March 1st price
apart. Scoped to the openai maker entry and those two models; Claude's
fast mode reads its own mode as before.

Run (WSL magpie-desktop, Linux, Go 1.26.8; mote overloaded by another
session's full suite, mica's disk full):
- TestDatedUltrafastPricedAtItsDay (new; Claude fast and standard
  unchanged among its cases): red on origin/main 78b6d47cc (Ultrafast
  0.11 for 0.33 and 0.66), green with the fix, also with TZ=UTC and
  TZ=Asia/Tokyo. TestFastCallsPricedAtTheirTier green.
- Broken by hand: tierKey without the day's rate -> red (the March call
  priced at the promotion's 3x through the cache).
- go test ./internal/catalog ./internal/usage: catalog ok; usage ok but
  TestRequestStateKeptAcrossACatalogFetchedAgain, red the same (-count=10)
  on untouched origin/main 78b6d47cc on Linux, filed as #6572.
- gofmt -l clean; go vet for linux, windows and darwin on both packages.
Not run before the push: the full ./... suite (runs after, on mote).
This commit is contained in:
yetone
2026-11-18 23:18:27 +08:00
parent ff64cb35d3
commit f1e2ada0f7
5 changed files with 158 additions and 10 deletions
+1 -1
View File
@@ -295,7 +295,7 @@ the key's leaves the call as asked, with a log line (`compactRefused`).
- A request is one usage record, counted once by how it ended (小一 on Discord: Codex on credits showed "5,482 · 1,094 failed" while rows said "2 tries/3 tries" and had been answered). The final record carries `tries` when the route took more than one (`rec.Tries`, from the trace's `Tries`). A try a vendor refused or turned away (`hw.refused`, `hw.turnedAway`) still writes its own record, for what it billed and why it failed, marked `handed_on`; so does any other try that failed, billed something and handed the request on, to another account or member or the same one again (`failedRow` in `serve`, written once the next try begins): a Claude subscription run that failed after Anthropic's `message_start` had written the conversation to that account's cache, and the next account wrote it again, while the Usage page counted the second alone (hhxk233 and Kayrainforest on X; `relay` keeps the reply start's usage on a failure, `TestClaudeSubscriptionFailedTryKeepsItsTokens`). A try that failed before anything was billed has no record; `usage.Totals.count` skips such a record for calls and failures. A request failed only when the agent got an error (`LostRequest`); one answered after a failed try is counted beside it as answered on a retry (`Totals.Retried`, `RetriedRequest`, the `retried` filter). Logs written before `handed_on` are read the same way: the log index marks a failed, non-rejected record followed by another of the same route id as handed on (`routeRows` in [`log_index.go`](../../internal/usage/log_index.go)). Counts by account or route (`vias`, window holds) still count every try. A turn relayed on Codex's own ChatGPT sign-in is recorded as that codex account (`codexServed` in [`codex_backend.go`](../../internal/gateway/codex_backend.go)), so the account card's window counts it; the Routing view still names the seat OpenAI, an API-key call stays `openai` with no account, as does one whose `chatgpt-account-id` isn't the account Codex's auth.json here is signed in to (a Codex in WSL or under another `CODEX_HOME`), and a row already written without an account is left as it is. Those relay rows are still not a lead's answerer (`loggedAnswers`, #1367); a row an account answered, its host `host as email`, still is.
- A failed call is in `app.log` too, not only the Routing page and the usage ledger (wjh66 on Discord: Codex's "error decoding response body" after "reconnecting 5/5", and the log had nothing of the turn). `record` writes each call whose status is 400 or more, or that carries an error, as one line (`failedCallLine`: agent, model, provider, status, time, the error to 300 characters); the same failure again within a minute is counted into the next line, not written (`failedLogEvery`), so a client asking in a loop can't fill the log. A Codex reply relayed from the ChatGPT backend that ends before its last event also says which side ended it (`codexEndedEarly` in [`codex_backend.go`](../../internal/gateway/codex_backend.go)): the read of OpenAI's stream that failed, with its error, or a clean end; and the client gone, a write to it that failed, or the failure passed on as `response.failed`, with the bytes passed on. reqwest, Codex's HTTP client, says "error decoding response body" for any read of a body whose connection broke, so only this line tells the legs apart. A gateway that ends with requests still in flight logs that they were cut (`srv.Shutdown`'s error; on Windows there is no handover, so an update or quit cuts a stream after `shortDrain`) (`TestCodexReplyBrokenOffLogged`, `TestCodexClientGoneLogged`, `TestFailedCallLineOncePerMinute`).
- Each record keeps the service tier three ways (#1784): `tier_asked` is what the client's body asked (`bodyTier`; Claude's speed fast reads `fast`), `tier_sent` is what that try's last request went out with, noted in `forwardOnce` after every rewrite (fast picks, Ultrafast to priority on a plan without it) onto the per-attempt `wireAt`, and `tier_served` is only what the reply said it ran at (`upstreamTier`, read by the sniffer and the translated readers), empty when it says nothing; from the ChatGPT backend (CodexBase's host) its `auto` and `default` are empty too, since it says them whether priority ran or not (`servedTierAt`, applied in `attempt` and `codexUpstreamOn`). The route's tries carry `tier` and `tier_served` the same way, on Codex's own sign-in (`codexUpstreamOn`) too, which before set only the route's `tier`, so a `/fast` turn there showed nothing (Anotiaww on X). The Routing page's request row shows a try's tier as a quiet tag beside the model (`fast` for `priority`, `Ultrafast`, `flex`; an in-flight row the route's asked tier), with the served tier in its title when the reply said another (`rowTier` in [`plugins/routing/client.js`](../../internal/gui/assets/plugins/routing/client.js), `routing-service-tier.test.cjs`). A bridge that doesn't go through `forwardOnce` (the Claude subscription, Cursor's built-in) leaves `tier_sent` empty. Through a Remote magpie the other magpie's word is taken (JackyFill on X: Codex → magpie1 → magpie2 → a ChatGPT account, Fast on in magpie2 alone, was logged `default` on magpie1): a try asked by another magpie (`magpieAsks`) says on its reply's header the tier it sent its vendor (`X-Magpie-Tier-Sent`, `none` for none) and, when that vendor's `auto`/`default` tell nothing, `X-Magpie-Tier-Unsaid: 1` (`stampTier`, from the holdWriter's `writeHeader`). The asking magpie takes them from a remote magpie's reply alone (`tierThere` in `heardReply`; a vendor's `X-Magpie-` headers are never passed) and records them as its try's `tier_sent` (`sentThere`) and an unknown `tier_served` (`servedThere`); a chain of magpies passes the farthest one's on. A reply whose headers a keepalive sent before the try answered carries neither, and the asking magpie keeps its own record. Code: [`tier_record.go`](../../internal/gateway/tier_record.go).
- A record is priced at its tier (`Record.billedTier`: `tier_served` when the reply named one, so an OpenAI API call asked `priority` and run at `default` is billed at the default; else `tier_sent`, which is what a ChatGPT backend row has, its `tier_served` being empty). `catalog.TierPrice` reads the price from the model's models.dev `experimental.modes`: the mode whose `provider.body.service_tier` is the tier, or whose `speed` is `fast` for Claude's `fast`, under `openai` or `anthropic`. That price stands only where the row's price is that entry's standard one, so a relay's rate or the user's own price is left as it is. The pricing pages agree: OpenAI's Fast (Priority processing until 2026-07-30) is twice gpt-6.1-sol's standard and Ultrafast six times, Flex half; Anthropic's fast mode is twice Claude Opus 5.5's. A mode lists no long-context price or 1-hour write, so the standard's are scaled by the mode's own ratio. The Usage page, a key's spend limit (`NewCoster`) and a subscription window's API value (`apiPricer`) all price through it (`TestFastCallsPricedAtTheirTier`, Archivemylife on X). Before this, every tier was priced at the standard rate.
- A record is priced at its tier (`Record.billedTier`: `tier_served` when the reply named one, so an OpenAI API call asked `priority` and run at `default` is billed at the default; else `tier_sent`, which is what a ChatGPT backend row has, its `tier_served` being empty). `catalog.TierPrice` reads the price from the model's models.dev `experimental.modes`: the mode whose `provider.body.service_tier` is the tier, or whose `speed` is `fast` for Claude's `fast`, under `openai` or `anthropic`. That price stands only where the row's price is that entry's standard one, so a relay's rate or the user's own price is left as it is. The pricing pages agree: OpenAI's Fast (Priority processing until 2026-07-30) is twice gpt-6.1-sol's standard and Ultrafast six times, Flex half; Anthropic's fast mode is twice Claude Opus 5.5's. A mode lists no long-context price or 1-hour write, so the standard's are scaled by the mode's own ratio. A tier OpenAI prices as a dated multiple of the standard (`tierTimes`: GPT-6.2 Astra's and Sol's Ultrafast, 3 times through 2027-02-28 and 6 times from 2027-03-01, Pacific time, which models.dev lists with no cost) is the standard times the multiple of the call's own day (`catalog.TierTimes`), every part and long-context rate with it; the price caches key on that day's rate (`Record.tierKey`), so calls either side of the change price apart (`TestDatedUltrafastPricedAtItsDay`, mu33410 on X; before, those calls were priced at the standard rate). The Usage page, a key's spend limit (`NewCoster`) and a subscription window's API value (`apiPricer`) all price through it (`TestFastCallsPricedAtTheirTier`, Archivemylife on X). Before this, every tier was priced at the standard rate.
- An agent's fast pick (`settings.FastPicks`, the bolt in its picker, #954) may also be in `settings.UltraPicks` (#1954), offered by the GUI only where one of Codex's accounts lists Ultrafast on the model (`provider.CanUltra`, `UltraModels`). `fastPick` marks its candidates `ultra`; a try of one goes with `service_tier: "ultrafast"` on Chat and Responses, and an agent on Messages carries it in the context (`withUltra`) to `forwardTranslated`, which sets `Request.Ultrafast` for the ChatGPT backend. Either way the same check as a client's own Ultrafast ask applies, now on Chat as well as Responses: an account whose list doesn't offer it is put after a mate that does (`tierMate`), or, with none left, sent `priority`. A Chat body's own `service_tier: "ultrafast"` is parsed as Ultrafast too (`chat.go`). `TestUltraPickSentUltrafast`.
- A group's member may be Ultrafast as well as fast (`Group.Ultra`, a subset of `Fast`, `Group.SetMemberTier`; the member's button steps Standard speed, Fast, Ultrafast where `ultraOK`; `ultra=` in `magpie group`), and a model has its own speed (`settings.ModelTiers`, "<provider>/<model>" to `priority` or `ultrafast`, `provider.SetModelTier`, Model settings and `magpie model tier`; kdajenks on X). The gateway sends it on a direct pick for an agent with no fast pick of its own (`provider.ModelTier`, the branch after `IsFastPick`), through the same `fastPick`, so an account without Ultrafast is sent `priority`. A group member goes as the group says. On a provider the user added by its address (`OwnFast`, a GPT or o-series model on an OpenAI API) the member's button goes on to Ultrafast when OpenAI offers the tier on the model: one of Codex's accounts lists it, or Codex's own `models_cache.json` entry for the slug does (`codexcat.OwnOffers`, the entry `ownTiers` already offers Codex), and the tier is only asked for, as its Fast is: a provider that turns the field away is asked again without it (KoiLx0 on X). A fast member never goes slower than the provider's extraBody asks: its `service_tier` `ultrafast` (forced or not) makes a Fast member go Ultrafast (`extraUltra`), a slower one (`flex`) gives way to the member's Fast, and a forced `!service_tier` still goes as written over all of them (`TestFastMemberOwnProviderExtraTier`, `TestCanUltraOwnProvider`, `group-member-fast.test.cjs`). `TestModelTierSentToEveryAgent`, `TestGroupMemberUltrafast`, `model-speed.test.cjs`.
- OpenAI's own API serves `service_tier: "ultrafast"` on the models its [Ultrafast mode](https://developers.openai.com/api/docs/guides/ultrafast-mode) names, GPT-6.2 Astra, GPT-6.2 Sol, GPT-6 Astra and GPT-6.1 Sol (`provider.OpenAIUltra`, a dated snapshot too), on its Responses only (OoopsHh on X: in Docker an OpenAI key's GPT-6 Astra had Fast and no Ultrafast, since every Ultrafast offer came from a Codex account's or CLI's list). On 11-18 api.openai.com's `/v1/responses` took the tier for those four and answered `Invalid service_tier argument` for GPT-6 Sol and GPT-6.1 Terra; `/v1/chat/completions` answered that for every model. So `UltraOn` offers Ultrafast on an OpenAI key's Responses (and on a provider added by its address, `OwnFast`) for those models, `buildResponses` sends it to api.openai.com for them alone (another model goes `priority`), and a Chat Completions request to api.openai.com that would carry it, a client's own ask included, goes `priority` instead (`chatNoUltra`, in the `tierMate` check). Another vendor's model is untouched. `TestOpenAIKeyUltrafast`, `TestCanUltraOwnProvider`. A Codex (ChatGPT) account's list is asked with the newest Codex magpie knows (`codexVersion`), and with none at hand, as in Docker, with `codexClientVersion` or npm's latest (`codexPublished`); the backend lists GPT-6.2 and Ultrafast only from 0.166.0, so the fallback is kept at or above it (`TestCodexFallbackListsUltrafast`).
+48 -1
View File
@@ -1000,7 +1000,11 @@ func PriceOf(providerID, modelID string) (Price, bool) {
// at $8/$40, twice too, "across the full context window". A mode lists no
// long-context price or 1-hour cache write, so std's are scaled by the
// mode's own ratio to std, part by part.
func TierPrice(std Price, model, tier string) (Price, bool) {
//
// A tier OpenAI prices as a multiple of the standard rate that changes on
// a date (tierTimes: GPT-6.2's Ultrafast, which models.dev lists with no
// cost) is std times the multiple in force at at, the call's own time.
func TierPrice(std Price, model, tier string, at time.Time) (Price, bool) {
tier = strings.ToLower(strings.TrimSpace(tier))
if tier == "" || tier == "default" || tier == "auto" {
return Price{}, false
@@ -1011,6 +1015,11 @@ func TierPrice(std Price, model, tier string) (Price, bool) {
if !ok || m.Cost == nil || !m.Cost.Same(std) {
continue
}
if maker == "openai" {
if x, _ := TierTimes(model, tier, at); x > 0 {
return std.Times(x), true
}
}
for _, mode := range m.Experimental.Modes {
c, body := mode.Cost, mode.Provider.Body
if c == nil || !(strings.EqualFold(body.ServiceTier, tier) || tier == "fast" && body.Speed == "fast") {
@@ -1037,6 +1046,44 @@ func TierPrice(std Price, model, tier string) (Price, bool) {
return Price{}, false
}
// tierTimes are the service tiers OpenAI's pricing page prices as a
// multiple of a model's standard rate, from a date on: "Ultrafast costs 3
// times the Standard rate through February 28, 2027" and "6 times the
// Standard rate starting March 1, 2027 (Pacific time)", for GPT-6.2 Astra
// and GPT-6.2 Sol (mu33410 on X). models.dev lists their Ultrafast mode
// with no cost, so it was billed at the standard rate, below Fast's.
var tierTimes = func() map[[2]string][]tierRate {
pt, err := time.LoadLocation("America/Los_Angeles")
if err != nil {
pt = time.FixedZone("PST", -8*3600) // March 1st is before DST
}
ultra := []tierRate{{Times: 3}, {From: time.Date(2027, 3, 1, 0, 0, 0, 0, pt), Times: 6}}
return map[[2]string][]tierRate{{"gpt-6.2-astra", "ultrafast"}: ultra, {"gpt-6.2-sol", "ultrafast"}: ultra}
}()
type tierRate struct {
From time.Time // zero: from the start
Times float64
}
// TierTimes is the multiple of model's standard rate OpenAI bills tier at
// a call made at at (tierTimes), and which of its rates that is, for a
// cache to tell calls on either side of a change apart; 0 when the tier
// isn't priced that way. A zero at is now.
func TierTimes(model, tier string, at time.Time) (float64, int) {
rates := tierTimes[[2]string{bareID(model), strings.ToLower(strings.TrimSpace(tier))}]
if at.IsZero() {
at = time.Now()
}
x, n := 0.0, -1
for i, r := range rates {
if !at.Before(r.From) {
x, n = r.Times, i
}
}
return x, n
}
// PricedBy is the list price the first of providers (models.dev ids)
// pricing a model of this id gives it: by its own key first, then by its
// id without a path or case ("openai/GPT-6-Sol" is gpt-6-sol), a Bedrock
+24 -6
View File
@@ -607,7 +607,7 @@ func Pricer() func(Record) *catalog.Price {
// its calls apart from the provider's other keys
key := r.ProviderKeyID
tier := r.billedTier()
k := [7]string{id, r.Model, served, r.SessionProvider, r.Effort, key, tier}
k := [7]string{id, r.Model, served, r.SessionProvider, r.Effort, key, r.tierKey(tier, served)}
if pr, ok := prices[k]; ok {
return atWindow(pr, windows[id], r.Time)
}
@@ -622,7 +622,7 @@ func Pricer() func(Record) *catalog.Price {
} else {
// Fast and Ultrafast bill at more than the standard price
// (Archivemylife on X: a Fast call read at the standard one)
pr = tierPriced(pr, tier, served, r.Model)
pr = tierPriced(pr, tier, r.Time, served, r.Model)
}
prices[k] = pr
return atWindow(pr, ws, r.Time)
@@ -633,8 +633,10 @@ func Pricer() func(Record) *catalog.Price {
// for the tier when pr is that model's standard price, the model that ran
// or the one asked for (catalog.TierPrice), else pr. The rows hold the
// tier's price, so the question is noted: a catalog that prices the tier
// otherwise names the request index anew.
func tierPriced(pr *catalog.Price, tier string, models ...string) *catalog.Price {
// otherwise names the request index anew. at is the call's time: a tier
// whose rate changes on a date (catalog.TierTimes) is priced at the rate
// of its day.
func tierPriced(pr *catalog.Price, tier string, at time.Time, models ...string) *catalog.Price {
if pr == nil || tier == "" {
return pr
}
@@ -643,12 +645,16 @@ func tierPriced(pr *catalog.Price, tier string, models ...string) *catalog.Price
if model == "" {
continue
}
tp, ok := catalog.TierPrice(*pr, model, tier)
tp, ok := catalog.TierPrice(*pr, model, tier, at)
answer := ""
if ok {
answer = priceAnswer(&tp, nil)
}
noteAsk(strings.Join([]string{"t", model, tier, std}, askSep), answer)
q := []string{"t", model, tier, std}
if _, era := catalog.TierTimes(model, tier, at); era >= 0 {
q = append(q, strconv.Itoa(era))
}
noteAsk(strings.Join(q, askSep), answer)
if ok {
return &tp
}
@@ -656,6 +662,18 @@ func tierPriced(pr *catalog.Price, tier string, models ...string) *catalog.Price
return pr
}
// tierKey is tier as a price cache keys it: with the rate of the call's
// day where the tier's rate changes on a date (catalog.TierTimes), so
// calls either side of the change price apart.
func (r Record) tierKey(tier string, models ...string) string {
for _, m := range append(models, r.Model) {
if _, era := catalog.TierTimes(m, tier, r.Time); m != "" && era >= 0 {
return tier + "@" + strconv.Itoa(era)
}
}
return tier
}
// billedTier is the service tier a record's call is priced at: the one
// its reply named, as OpenAI's API bills it (a priority request it ran at
// "default" is billed at the default), else the one sent: the ChatGPT
+83
View File
@@ -0,0 +1,83 @@
package usage
import (
"math"
"os"
"path/filepath"
"testing"
"time"
"github.com/yetone/magpie/internal/catalog"
)
// mu33410 on X asked whether Fast and the other modes are priced as such.
// OpenAI's pricing page prices GPT-6.2 Sol's and Astra's Ultrafast at 3
// times the standard rate through 2027-02-28 and 6 times from 2027-03-01
// (Pacific time), and models.dev lists the mode with no cost, so an
// Ultrafast call there was priced at the standard rate, below Fast's. The
// catalog is models.dev's own bytes for gpt-6.2-sol and claude-opus-5-5.
func TestDatedUltrafastPricedAtItsDay(t *testing.T) {
home := t.TempDir()
t.Setenv("HOME", home)
t.Setenv("USERPROFILE", home)
t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config"))
t.Setenv("XDG_CACHE_HOME", filepath.Join(home, ".cache"))
os.MkdirAll(filepath.Dir(catalog.CachePath()), 0o755)
if err := os.WriteFile(catalog.CachePath(), []byte(`{"openai":{"id":"openai","models":{`+
`"gpt-6.2-sol":{"id":"gpt-6.2-sol","cost":{"input":2,"output":10,"cache_read":0.1,"cache_write":2.5,"tiers":[{"input":4,"output":15,"cache_read":0.2,"cache_write":5,"tier":{"type":"context","size":272000}}],"context_over_200k":{"input":4,"output":15,"cache_read":0.2,"cache_write":5}},"experimental":{"modes":{"fast":{"cost":{"input":4,"output":20,"cache_read":0.2,"cache_write":5},"provider":{"body":{"service_tier":"priority"}}},"pro":{"provider":{"body":{"reasoning":{"mode":"pro"}}}},"ultrafast":{"provider":{"body":{"service_tier":"ultrafast"}}}}}}}},`+
`"anthropic":{"id":"anthropic","models":{`+
`"claude-opus-5-5":{"id":"claude-opus-5-5","cost":{"input":4,"output":20,"cache_read":0.2,"cache_write":5},"experimental":{"modes":{"fast":{"cost":{"input":8,"output":40,"cache_read":0.4,"cache_write":10},"provider":{"body":{"speed":"fast"},"headers":{"anthropic-beta":"fast-mode-2026-02-01"}}}}}}}}}`), 0o644); err != nil {
t.Fatal(err)
}
catalog.Reset()
t.Cleanup(catalog.Reset)
pt, err := time.LoadLocation("America/Los_Angeles")
if err != nil {
t.Fatal(err)
}
change := time.Date(2027, 3, 1, 0, 0, 0, 0, pt)
before, after := change.Add(-time.Second), change
in, out, cached := 40_000, 2_000, 100_000
sol := (float64(in)*2 + float64(out)*10 + float64(cached)*0.1) / 1e6
opus := (float64(in)*4 + float64(out)*20 + float64(cached)*0.2) / 1e6
calls := []struct {
name, prov, model, sent, served string
at time.Time
want float64
}{
{"API Ultrafast in the promotion", "openai", "gpt-6.2-sol", "ultrafast", "ultrafast", before, 3 * sol},
{"API Ultrafast from March 1st", "openai", "gpt-6.2-sol", "ultrafast", "ultrafast", after, 6 * sol},
{"Codex Ultrafast in the promotion", "codex", "gpt-6.2-sol", "ultrafast", "", before, 3 * sol},
{"Codex Ultrafast from March 1st", "codex", "gpt-6.2-sol", "ultrafast", "", after, 6 * sol},
{"API Ultrafast run at the default tier", "openai", "gpt-6.2-sol", "ultrafast", "default", before, sol},
{"API Ultrafast run at priority", "openai", "gpt-6.2-sol", "ultrafast", "priority", after, 2 * sol},
{"API Fast after the change", "openai", "gpt-6.2-sol", "priority", "priority", after, 2 * sol},
{"API standard", "openai", "gpt-6.2-sol", "", "", after, sol},
{"Claude fast, unchanged", "anthropic", "claude-opus-5-5", "fast", "", after, 2 * opus},
{"Claude standard", "anthropic", "claude-opus-5-5", "", "", before, opus},
}
// one Pricer and one Coster across every call: a cache keyed without
// the day would price the second Ultrafast call as the first
cost, api, priceOf := NewCoster(), apiPricer(), Pricer()
for _, c := range calls {
rec := Record{Time: c.at, Provider: c.prov, Model: c.model, TierSent: c.sent, TierServed: c.served, Input: in, Output: out, CacheRead: cached}
if pr := priceOf(rec); pr == nil || math.Abs(rec.CostAt(*pr)-c.want) > 1e-9 {
t.Errorf("%s: the ledger prices it %+v, want cost %v", c.name, pr, c.want)
}
if got, ok := cost(rec); !ok || math.Abs(got-c.want) > 1e-9 {
t.Errorf("%s: a key limit counts it at %v (%v), want %v", c.name, got, ok, c.want)
}
if c.prov == "codex" {
if pr := api(rec); pr == nil || math.Abs(rec.CostAt(*pr)-c.want) > 1e-9 {
t.Errorf("%s: API price %+v, want cost %v", c.name, pr, c.want)
}
}
}
// a long Ultrafast prompt: the standard long-context rate ($4 in, $15
// out) three times over
long := Record{Time: before, Provider: "openai", Model: "gpt-6.2-sol", TierSent: "ultrafast", TierServed: "ultrafast", Input: 300_000, Output: 1_000}
if got, want := func() float64 { c, _ := cost(long); return c }(), 3*(300_000*4.0+1_000*15.0)/1e6; math.Abs(got-want) > 1e-9 {
t.Errorf("a long Ultrafast prompt costs %v, want %v", got, want)
}
}
+2 -2
View File
@@ -365,7 +365,7 @@ func apiPricer() func(Record) *catalog.Price {
}
id := r.priceID()
tier := r.billedTier()
k := [5]string{id, r.Model, served, r.Effort, tier}
k := [5]string{id, r.Model, served, r.Effort, r.tierKey(tier, served)}
if pr, ok := prices[k]; ok {
return pr
}
@@ -383,7 +383,7 @@ func apiPricer() func(Record) *catalog.Price {
pr = one(id, served)
}
// a Fast call is worth Fast's API price (Pricer)
pr = tierPriced(pr, tier, served, r.Model)
pr = tierPriced(pr, tier, r.Time, served, r.Model)
prices[k] = pr
return pr
}