Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

MUL-8018: feat(runtimes): price Claude Sonnet 5.5 and Haiku 5.5 (#9253)

ASPCartman9f82479231b2
diff --git a/packages/views/runtimes/utils.test.ts b/packages/views/runtimes/utils.test.ts
index f1f4c92c89..8b77b736cb 100644
--- a/packages/views/runtimes/utils.test.ts
+++ b/packages/views/runtimes/utils.test.ts
@@ -176,6 +176,64 @@ describe("estimateCost", () => {
expect(cost).toBeCloseTo(10 + 50 + 0.25 + 12.5, 5);
});
+ it.each([
+ {
+ model: "claude-sonnet-5-5",
+ dotted: "claude-sonnet-5.5",
+ expected: { input: 2, output: 10, cacheRead: 0.1, cacheWrite: 2.5 },
+ },
+ {
+ model: "claude-haiku-5-5",
+ dotted: "claude-haiku-5.5",
+ expected: { input: 0.1, output: 0.5, cacheRead: 0.01, cacheWrite: 0.125 },
+ },
+ ])("prices $model across transport spellings", ({ model, dotted, expected }) => {
+ for (const alias of [
+ model,
+ dotted,
+ `anthropic/${model}`,
+ `anthropic:${dotted}`,
+ `${model}[1m]`,
+ `${model}-20261001`,
+ `${model}-2026-10-01[1m]`,
+ `${model}-latest`,
+ ]) {
+ // Aggregate totals do not identify a single request's context tier.
+ const usage = {
+ model: alias,
+ input_tokens: 1_000_000,
+ output_tokens: 1_000_000,
+ cache_read_tokens: 1_000_000,
+ cache_write_tokens: 1_000_000,
+ };
+ expect(estimateCostBreakdown(usage)).toEqual(expected);
+ expect(estimateCost(usage)).toBeCloseTo(
+ expected.input + expected.output + expected.cacheRead + expected.cacheWrite,
+ 5,
+ );
+ expect(collectUnmappedModels([usage])).toEqual([]);
+ }
+ });
+
+ it("keeps unknown Sonnet and Haiku variants unmapped", () => {
+ for (const model of [
+ "claude-sonnet-5-6",
+ "claude-sonnet-5.6",
+ "claude-sonnet-5-55",
+ "claude-haiku-5-6",
+ "claude-haiku-5.6",
+ "claude-haiku-5-55",
+ ...["claude-sonnet-5", "claude-sonnet-5-5", "claude-haiku-5-5"].flatMap(
+ (base) => ["x", "-preview", "-latest-preview", "-20261001x", "[1m]junk", "[1m][2m]", "[]"].map(
+ (suffix) => base + suffix,
+ ),
+ ),
+ ]) {
+ expect(isModelPriced(model)).toBe(false);
+ expect(estimateCost({ ...zeroUsage, model, input_tokens: 1_000_000 })).toBe(0);
+ }
+ });
+
it("prices Claude Sonnet 5 at Anthropic's intro $2 / $10 tier", () => {
const cost = estimateCost({
...zeroUsage,
diff --git a/packages/views/runtimes/utils.ts b/packages/views/runtimes/utils.ts
index 42f152278a..4f9ca67d0d 100644
--- a/packages/views/runtimes/utils.ts
+++ b/packages/views/runtimes/utils.ts
@@ -218,6 +218,13 @@ const MODEL_PRICING: Record<
// usual 0.1x); Opus 4.5 through Opus 5 stay on the lower 5/25 Opus tier,
// and Opus 5.5 drops to 4/20 (cache reads at 0.05x input). --
"claude-sonnet-5": { input: 2, output: 10, cacheRead: 0.20, cacheWrite: 2.50 },
+ // Sonnet 5.5 keeps the 2/10 tier but halves the cache-read rate.
+ "claude-sonnet-5-5": { input: 2, output: 10, cacheRead: 0.10, cacheWrite: 2.50 },
+ // Haiku 5.5 uses the <=100K prompt tier. Above 100K (including cache
+ // reads/writes), all four rates are 5x higher. Rollups lack per-request
+ // prompt sizes, so long requests are underestimated. Mirror the backend
+ // estimate in server/internal/metrics/pricing.go.
+ "claude-haiku-5-5": { input: 0.10, output: 0.50, cacheRead: 0.01, cacheWrite: 0.125 },
"claude-fable-5-1": { input: 10, output: 50, cacheRead: 0.25, cacheWrite: 12.50 },
"claude-fable-5": { input: 10, output: 50, cacheRead: 1.00, cacheWrite: 12.50 },
"claude-opus-5-5": { input: 4, output: 20, cacheRead: 0.20, cacheWrite: 5.00 },
diff --git a/server/internal/integrations/wecom/outbound_inbox_wait_test.go b/server/internal/integrations/wecom/outbound_inbox_wait_test.go
index 624eeb7fa6..91375b2226 100644
--- a/server/internal/integrations/wecom/outbound_inbox_wait_test.go
+++ b/server/internal/integrations/wecom/outbound_inbox_wait_test.go
@@ -15,6 +15,7 @@ import (
"context"
"log/slog"
"testing"
+ "testing/synctest"
"time"
"github.com/jackc/pgx/v5/pgtype"
@@ -109,26 +110,29 @@ func TestTryDeliverInbox_WaitIsBoundedByTheCallersDeadline(t *testing.T) {
// return, leaving the cost at exactly one window rather than two.
func TestTryDeliverInbox_FallbackAttemptDoesNotWaitAgain(t *testing.T) {
t.Parallel()
- // Small enough to keep the test quick, big enough that one window is
- // several polls and two windows would be unmistakable.
- rig := newInboxWaitRig(t, 400*time.Millisecond)
+ // Virtual time keeps CI scheduling delays from consuming the acceptance
+ // poll's timeout cushion while still exercising the real relay and timers.
+ synctest.Test(t, func(t *testing.T) {
+ const window = 400 * time.Millisecond
+ rig := newInboxWaitRig(t, window)
- got, elapsed := rig.deliver(context.Background(), agentInboxItem("new_comment", inboxWaitAgentID))
- if !got {
- t.Error("tryDeliverInbox = false; the fallback publish was accepted and had no route behind it")
- }
- if elapsed > 2*time.Second {
- t.Fatalf("the push took %v for a 400ms window; the fallback must not wait again", elapsed)
- }
- // One window at step = window/8 is about nine polls; two would be about
- // eighteen. The bound sits between them.
- if n := rig.dedupe.claimStateCount(); n > 12 {
- t.Errorf("the claim was polled %d times; the fallback attempt paid a second acceptance window", n)
- }
- if n := rig.relay.publishedTo(inboxWaitFallbackInst); n != 1 {
- t.Errorf("the recipient-wide bot was offered %d frames, want 1", n)
- }
- if n := rig.relay.publishedTo(inboxWaitAgentInst); n != 1 {
- t.Errorf("the acting agent's bot was offered %d frames, want 1", n)
- }
+ got, elapsed := rig.deliver(context.Background(), agentInboxItem("new_comment", inboxWaitAgentID))
+ if !got {
+ t.Error("tryDeliverInbox = false; the fallback publish was accepted and had no route behind it")
+ }
+ if elapsed != window {
+ t.Fatalf("the push took %v, want exactly one acceptance window (%v)", elapsed, window)
+ }
+ // One window at step = window/8 is about nine polls; two would be about
+ // eighteen. The bound sits between them.
+ if n := rig.dedupe.claimStateCount(); n > 12 {
+ t.Errorf("the claim was polled %d times; the fallback attempt paid a second acceptance window", n)
+ }
+ if n := rig.relay.publishedTo(inboxWaitFallbackInst); n != 1 {
+ t.Errorf("the recipient-wide bot was offered %d frames, want 1", n)
+ }
+ if n := rig.relay.publishedTo(inboxWaitAgentInst); n != 1 {
+ t.Errorf("the acting agent's bot was offered %d frames, want 1", n)
+ }
+ })
}
diff --git a/server/internal/metrics/pricing.go b/server/internal/metrics/pricing.go
index c2e1f6d7fa..a33d7a4d97 100644
--- a/server/internal/metrics/pricing.go
+++ b/server/internal/metrics/pricing.go
@@ -47,6 +47,11 @@ var modelPrices = map[string]ModelPrice{
// static table cannot schedule the published post-intro $3 / $15 change yet,
// so keep the intro rate here and update the row when catalog support exists.
"anthropic:claude-sonnet-5": {Provider: "anthropic", Model: "claude-sonnet-5", InputPerM: 2.00, CacheReadPerM: 0.20, CacheWritePerM: 2.50, OutputPerM: 10.00},
+ "anthropic:claude-sonnet-5-5": {Provider: "anthropic", Model: "claude-sonnet-5-5", InputPerM: 2.00, CacheReadPerM: 0.10, CacheWritePerM: 2.50, OutputPerM: 10.00},
+ // Haiku 5.5 uses the <=100K prompt tier, matching the frontend estimate.
+ // Above 100K (including cache reads/writes), all four rates are 5x higher.
+ // Usage aggregates lack per-request prompt sizes, so long requests are underestimated.
+ "anthropic:claude-haiku-5-5": {Provider: "anthropic", Model: "claude-haiku-5-5", InputPerM: 0.10, CacheReadPerM: 0.01, CacheWritePerM: 0.125, OutputPerM: 0.50},
"anthropic:claude-fable-5-1": {Provider: "anthropic", Model: "claude-fable-5-1", InputPerM: 10.00, CacheReadPerM: 0.25, CacheWritePerM: 12.50, OutputPerM: 50.00},
"anthropic:claude-fable-5": {Provider: "anthropic", Model: "claude-fable-5", InputPerM: 10.00, CacheReadPerM: 1.00, CacheWritePerM: 12.50, OutputPerM: 50.00},
"anthropic:claude-opus-5-5": {Provider: "anthropic", Model: "claude-opus-5-5", InputPerM: 4.00, CacheReadPerM: 0.20, CacheWritePerM: 5.00, OutputPerM: 20.00},
@@ -160,7 +165,11 @@ var modelAliasRules = []struct {
{regexp.MustCompile(`(^|/|:)gpt-5[.-]4-mini($|[^a-z0-9])`), "openai:gpt-5.4-mini"},
{regexp.MustCompile(`(^|/|:)gpt-5[.-]3-codex$`), "openai:gpt-5.3-codex"},
{regexp.MustCompile(`(^|/|:)gpt-5[.-]2-codex$`), "openai:gpt-5.2-codex"},
- {regexp.MustCompile(`claude-sonnet-5|claude-5-sonnet`), "anthropic:claude-sonnet-5"},
+ // Sonnet 5.5 halves Sonnet 5's cache-read rate. End both rules at their
+ // own version so later SKUs cannot inherit either tier.
+ {regexp.MustCompile(`claude-sonnet-5[-.]5` + claudeVersionEnd), "anthropic:claude-sonnet-5-5"},
+ {regexp.MustCompile(`(?:claude-sonnet-5|claude-5-sonnet)` + claudeVersionEnd), "anthropic:claude-sonnet-5"},
+ {regexp.MustCompile(`claude-haiku-5[-.]5` + claudeVersionEnd), "anthropic:claude-haiku-5-5"},
// Fable 5.1 shares Fable 5's $10 / $50 and $12.50 cache write but prices
// cache reads at 0.025x input ($0.25) instead of the standard 0.1x, so it
// needs its own row, and both rules end at their own version
diff --git a/server/internal/metrics/pricing_test.go b/server/internal/metrics/pricing_test.go
index 4e780cae09..6c33fd23f2 100644
--- a/server/internal/metrics/pricing_test.go
+++ b/server/internal/metrics/pricing_test.go
@@ -517,6 +517,85 @@ func TestPriceForModelAliasAnthropicFable51(t *testing.T) {
}
}
+func TestPriceForModelAliasAnthropicSonnetAndHaiku55(t *testing.T) {
+ cases := []struct {
+ aliases []string
+ want ModelPrice
+ }{
+ {
+ aliases: []string{
+ "claude-sonnet-5",
+ "claude-5-sonnet",
+ "anthropic/claude-sonnet-5",
+ "claude-sonnet-5[1m]",
+ "claude-sonnet-5-20261001",
+ "claude-sonnet-5-latest",
+ },
+ want: ModelPrice{Provider: "anthropic", Model: "claude-sonnet-5", InputPerM: 2, CacheReadPerM: 0.2, CacheWritePerM: 2.5, OutputPerM: 10},
+ },
+ {
+ aliases: []string{
+ "claude-sonnet-5-5",
+ "claude-sonnet-5.5",
+ "anthropic/claude-sonnet-5-5",
+ "anthropic:claude-sonnet-5.5",
+ "claude-sonnet-5-5[1m]",
+ "claude-sonnet-5-5-20261001",
+ "claude-sonnet-5-5-2026-10-01[1m]",
+ "claude-sonnet-5-5-latest",
+ },
+ want: ModelPrice{Provider: "anthropic", Model: "claude-sonnet-5-5", InputPerM: 2, CacheReadPerM: 0.1, CacheWritePerM: 2.5, OutputPerM: 10},
+ },
+ {
+ aliases: []string{
+ "claude-haiku-5-5",
+ "claude-haiku-5.5",
+ "anthropic/claude-haiku-5-5",
+ "anthropic:claude-haiku-5.5",
+ "claude-haiku-5-5[1m]",
+ "claude-haiku-5-5-20261001",
+ "claude-haiku-5-5-2026-10-01[1m]",
+ "claude-haiku-5-5-latest",
+ },
+ want: ModelPrice{Provider: "anthropic", Model: "claude-haiku-5-5", InputPerM: 0.1, CacheReadPerM: 0.01, CacheWritePerM: 0.125, OutputPerM: 0.5},
+ },
+ }
+ for _, tc := range cases {
+ for _, model := range tc.aliases {
+ t.Run(model, func(t *testing.T) {
+ got, ok := PriceForModelAlias(model)
+ if !ok || got != tc.want {
+ t.Fatalf("PriceForModelAlias(%q) = %+v, %v; want %+v, true", model, got, ok, tc.want)
+ }
+ })
+ }
+ }
+}
+
+func TestPriceForModelAliasAnthropicSonnetAndHaikuUnknownVariants(t *testing.T) {
+ for _, model := range []string{
+ "claude-sonnet-5-6",
+ "claude-sonnet-5.6",
+ "claude-sonnet-5-55",
+ "claude-haiku-5-6",
+ "claude-haiku-5.6",
+ "claude-haiku-5-55",
+ "claude-5-sonnet-preview",
+ } {
+ if got, ok := PriceForModelAlias(model); ok {
+ t.Errorf("PriceForModelAlias(%q) resolved to %+v; want unmapped", model, got)
+ }
+ }
+ for _, base := range []string{"claude-sonnet-5", "claude-sonnet-5-5", "claude-haiku-5-5"} {
+ for _, suffix := range []string{"x", "-preview", "-latest-preview", "-20261001x", "[1m]junk", "[1m][2m]", "[]"} {
+ model := base + suffix
+ if got, ok := PriceForModelAlias(model); ok {
+ t.Errorf("PriceForModelAlias(%q) resolved to %+v; want unmapped", model, got)
+ }
+ }
+ }
+}
+
func TestPriceForModelAliasAnthropicOpus55(t *testing.T) {
// Opus 5.5 is its own SKU at $4 / $20 with cache reads at 0.05x input
// ($0.20). An Opus 5 alias that did not stop at the version would swallow