SPB Git forge

spb/polyllm

Public
15commits 1branches 0releases
2.2 MBsize
maindefault branch
13 days agolast push
TypeScript 97.4% SQL 1% JavaScript 0.9% CSS 0.6%
3.7 KB · 62 lines typescript
Raw Blame History
1import type { ModelPricing } from "@/lib/ai/core/types";23/**4 * Anthropic pricing (USD per 1M tokens) — first-party API rates.5 * Source: https://platform.claude.com/docs/en/about-claude/pricing (audited 2026-09-08).6 * Cache reads are billed at 10% of input (Fable 5.1 / Mythos 5.1: $0.25 flat per MTok).7 * The Models API does not expose pricing, so this table is the only hand-maintained piece.8 */9export const ANTHROPIC_PRICING: Record<string, ModelPricing> = {10  "claude-fable-5-1": { inputPerMillion: 10, outputPerMillion: 50, cachedInputPerMillion: 0.25 },11  "claude-mythos-5-1": { inputPerMillion: 10, outputPerMillion: 50, cachedInputPerMillion: 0.25 },12  "claude-fable-5": { inputPerMillion: 10, outputPerMillion: 50, cachedInputPerMillion: 1 },13  "claude-opus-5": { inputPerMillion: 5, outputPerMillion: 25, cachedInputPerMillion: 0.5 },14  "claude-opus-4-8": { inputPerMillion: 5, outputPerMillion: 25, cachedInputPerMillion: 0.5 },15  "claude-opus-4-7": { inputPerMillion: 5, outputPerMillion: 25, cachedInputPerMillion: 0.5 },16  "claude-opus-4-6": { inputPerMillion: 5, outputPerMillion: 25, cachedInputPerMillion: 0.5 },17  "claude-sonnet-5": { inputPerMillion: 2, outputPerMillion: 10, cachedInputPerMillion: 0.2 },18  "claude-sonnet-4-6": { inputPerMillion: 3, outputPerMillion: 15, cachedInputPerMillion: 0.3 },19  "claude-haiku-4-5": { inputPerMillion: 1, outputPerMillion: 5, cachedInputPerMillion: 0.1 },20  "claude-opus-4-5": { inputPerMillion: 5, outputPerMillion: 25, cachedInputPerMillion: 0.5 },21  "claude-sonnet-4-5": { inputPerMillion: 3, outputPerMillion: 15, cachedInputPerMillion: 0.3 },22  "claude-opus-4-1": { inputPerMillion: 15, outputPerMillion: 75, cachedInputPerMillion: 1.5 },23  "claude-opus-4": { inputPerMillion: 15, outputPerMillion: 75, cachedInputPerMillion: 1.5 },24  "claude-sonnet-4": { inputPerMillion: 3, outputPerMillion: 15, cachedInputPerMillion: 0.3 },25  "claude-3-7-sonnet": { inputPerMillion: 3, outputPerMillion: 15, cachedInputPerMillion: 0.3 },26  "claude-3-5-haiku": { inputPerMillion: 0.8, outputPerMillion: 4, cachedInputPerMillion: 0.08 },27  "claude-3-haiku": { inputPerMillion: 0.25, outputPerMillion: 1.25, cachedInputPerMillion: 0.03 },28};2930export function anthropicPricingFor(modelId: string): ModelPricing | null {31  if (ANTHROPIC_PRICING[modelId]) return { ...ANTHROPIC_PRICING[modelId], source: "anthropic-pricing-page", asOf: "2026-09-08" };32  // dated snapshots: claude-sonnet-4-5-20250929 → claude-sonnet-4-533  const base = modelId.replace(/-\d{8}$/, "");34  if (ANTHROPIC_PRICING[base]) return { ...ANTHROPIC_PRICING[base], source: "anthropic-pricing-page", asOf: "2026-09-08" };35  return null;36}3738/** Models retired or scheduled for retirement per the deprecations page. */39export const ANTHROPIC_DEPRECATED = new Set(["claude-3-haiku-20240307", "claude-3-5-haiku-20241022", "claude-3-7-sonnet-20250219", "claude-opus-4-20250514", "claude-opus-4-1-20250805", "claude-sonnet-4-20250514"]);4041/** Ordering weight for the selector (higher first). */42export function anthropicSortWeight(id: string): number {43  if (id.startsWith("claude-fable-5-1")) return 100;44  if (id.startsWith("claude-opus-5")) return 95;45  if (id.startsWith("claude-sonnet-5")) return 90;46  if (id.startsWith("claude-fable-5")) return 85;47  if (id.startsWith("claude-opus-4-8")) return 80;48  if (id.startsWith("claude-opus-4-7")) return 75;49  if (id.startsWith("claude-sonnet-4-6")) return 70;50  if (id.startsWith("claude-opus-4-6")) return 68;51  if (id.startsWith("claude-haiku-4-5")) return 60;52  return 10;53}5455export function anthropicFamily(id: string): string {56  if (id.includes("fable") || id.includes("mythos")) return "Fable";57  if (id.includes("opus")) return "Opus";58  if (id.includes("sonnet")) return "Sonnet";59  if (id.includes("haiku")) return "Haiku";60  return "Claude";61}62