language-models 2.1.3 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +26 -0
- package/README.md +2 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -1
- package/dist/index.js.map +1 -1
- package/dist/models.d.ts +1 -1
- package/dist/models.d.ts.map +1 -1
- package/dist/models.js +8 -10
- package/dist/models.js.map +1 -1
- package/dist/policy.d.ts +127 -0
- package/dist/policy.d.ts.map +1 -0
- package/dist/policy.js +246 -0
- package/dist/policy.js.map +1 -0
- package/dist/pricing/index.d.ts +19 -0
- package/dist/pricing/index.d.ts.map +1 -0
- package/dist/pricing/index.js +18 -0
- package/dist/pricing/index.js.map +1 -0
- package/dist/pricing/lookup.d.ts +46 -0
- package/dist/pricing/lookup.d.ts.map +1 -0
- package/dist/pricing/lookup.js +94 -0
- package/dist/pricing/lookup.js.map +1 -0
- package/dist/pricing/table.d.ts +46 -0
- package/dist/pricing/table.d.ts.map +1 -0
- package/dist/pricing/table.js +214 -0
- package/dist/pricing/table.js.map +1 -0
- package/dist/pricing/types.d.ts +84 -0
- package/dist/pricing/types.d.ts.map +1 -0
- package/dist/pricing/types.js +32 -0
- package/dist/pricing/types.js.map +1 -0
- package/package.json +16 -12
- package/src/index.ts +42 -1
- package/src/models.ts +8 -12
- package/src/policy.ts +343 -0
- package/src/pricing/index.ts +29 -0
- package/src/pricing/lookup.ts +124 -0
- package/src/pricing/table.ts +235 -0
- package/src/pricing/types.ts +90 -0
- package/{src → test}/aliases.test.ts +20 -22
- package/{src → test}/index.test.ts +9 -9
- package/{src → test}/models.test.ts +8 -6
- package/test/policy.test.ts +203 -0
- package/test/pricing.test.ts +279 -0
- package/vitest.config.ts +21 -1
- package/.turbo/turbo-test.log +0 -18
- package/LICENSE +0 -21
- package/src/aliases.js +0 -40
- package/src/aliases.test.js +0 -264
- package/src/index.js +0 -9
- package/src/index.test.js +0 -320
- package/src/models.js +0 -108
- package/src/models.test.js +0 -335
- package/vitest.config.js +0 -10
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* language-models / pricing — lookup helpers.
|
|
3
|
+
*
|
|
4
|
+
* The single source of truth for cost computation across the Phase-2
|
|
5
|
+
* three-repo cascade. Throws on unknown slug/tier (per BYOK_GATEWAY_LIES
|
|
6
|
+
* memory: silent zero is the lying-gateway pattern; loud failure beats
|
|
7
|
+
* silent downgrade).
|
|
8
|
+
*/
|
|
9
|
+
import { PRICING_TABLE } from './table.js';
|
|
10
|
+
/**
|
|
11
|
+
* Compute USD cost for a known generation. Throws on:
|
|
12
|
+
* - unknown slug (no rows for the slug at all)
|
|
13
|
+
* - unknown/unmodeled tier for the slug (no row for the (slug, tier) pair)
|
|
14
|
+
* - negative token counts (programming error — fail loud)
|
|
15
|
+
*
|
|
16
|
+
* Honors `contextTierBreakpoint` when present: if `inputTokens >=
|
|
17
|
+
* breakpoint`, the entire request is billed at `contextTierAbove` rates
|
|
18
|
+
* (matches Google's published billing model — the rate switches once the
|
|
19
|
+
* input crosses 200K, applied to the full request).
|
|
20
|
+
*
|
|
21
|
+
* `cachedInputTokens` is billed at `cachedInputPer1M` when defined,
|
|
22
|
+
* falling back to the regular input rate otherwise. Cached tokens are
|
|
23
|
+
* SUBTRACTED from `inputTokens` to compute the non-cached portion — i.e.
|
|
24
|
+
* `inputTokens` is the TOTAL input including any cached tokens.
|
|
25
|
+
*/
|
|
26
|
+
export function priceFor(args) {
|
|
27
|
+
const { slug, tier, inputTokens, outputTokens, cachedInputTokens } = args;
|
|
28
|
+
if (inputTokens < 0 || outputTokens < 0 || (cachedInputTokens ?? 0) < 0) {
|
|
29
|
+
throw new RangeError(`priceFor() requires non-negative token counts; got input=${inputTokens}, output=${outputTokens}, cachedInput=${cachedInputTokens ?? 0}`);
|
|
30
|
+
}
|
|
31
|
+
const row = findRow(slug, tier);
|
|
32
|
+
// Pick the right rate block based on context-tier breakpoint.
|
|
33
|
+
const useAbove = typeof row.contextTierBreakpoint === 'number' &&
|
|
34
|
+
row.contextTierAbove !== undefined &&
|
|
35
|
+
inputTokens >= row.contextTierBreakpoint;
|
|
36
|
+
const block = useAbove
|
|
37
|
+
? row.contextTierAbove
|
|
38
|
+
: {
|
|
39
|
+
inputPer1M: row.inputPer1M,
|
|
40
|
+
outputPer1M: row.outputPer1M,
|
|
41
|
+
cachedInputPer1M: row.cachedInputPer1M,
|
|
42
|
+
};
|
|
43
|
+
const cachedTok = Math.min(cachedInputTokens ?? 0, inputTokens);
|
|
44
|
+
const nonCachedInputTok = inputTokens - cachedTok;
|
|
45
|
+
const cachedRate = block.cachedInputPer1M ?? block.inputPer1M;
|
|
46
|
+
const inputUsd = (nonCachedInputTok / 1_000_000) * block.inputPer1M + (cachedTok / 1_000_000) * cachedRate;
|
|
47
|
+
const outputUsd = (outputTokens / 1_000_000) * block.outputPer1M;
|
|
48
|
+
const totalUsd = inputUsd + outputUsd;
|
|
49
|
+
return { inputUsd, outputUsd, totalUsd };
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Returns the unique set of slugs in the table. Useful for adapters that
|
|
53
|
+
* want to validate caller-supplied model ids before dispatching.
|
|
54
|
+
*/
|
|
55
|
+
export function listSlugs() {
|
|
56
|
+
const set = new Set();
|
|
57
|
+
for (const row of PRICING_TABLE)
|
|
58
|
+
set.add(row.slug);
|
|
59
|
+
return Array.from(set);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Returns true if pricing exists for the given (slug, tier). Use this
|
|
63
|
+
* when you need a non-throwing existence check before calling
|
|
64
|
+
* `priceFor()` (e.g. a metering middleware that wants to fall back to
|
|
65
|
+
* "unknown cost" telemetry rather than throwing on a not-yet-registered
|
|
66
|
+
* model).
|
|
67
|
+
*/
|
|
68
|
+
export function hasPricing(args) {
|
|
69
|
+
return PRICING_TABLE.some((row) => row.slug === args.slug && row.tier === args.tier);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Returns all pricing rows for a slug, across all tiers. Useful for
|
|
73
|
+
* tooling that wants to display "this model has standard + batch tiers"
|
|
74
|
+
* in a UI.
|
|
75
|
+
*/
|
|
76
|
+
export function rowsForSlug(slug) {
|
|
77
|
+
return PRICING_TABLE.filter((row) => row.slug === slug);
|
|
78
|
+
}
|
|
79
|
+
// ---------------------------------------------------------------------------
|
|
80
|
+
// Internal
|
|
81
|
+
// ---------------------------------------------------------------------------
|
|
82
|
+
function findRow(slug, tier) {
|
|
83
|
+
const slugRows = PRICING_TABLE.filter((row) => row.slug === slug);
|
|
84
|
+
if (slugRows.length === 0) {
|
|
85
|
+
throw new Error(`Unknown model slug: '${slug}'. Known slugs: ${listSlugs().slice(0, 8).join(', ')}${listSlugs().length > 8 ? `, ...(${listSlugs().length - 8} more)` : ''}`);
|
|
86
|
+
}
|
|
87
|
+
const tierRow = slugRows.find((row) => row.tier === tier);
|
|
88
|
+
if (tierRow === undefined) {
|
|
89
|
+
const availableTiers = slugRows.map((row) => row.tier);
|
|
90
|
+
throw new Error(`No '${tier}' pricing for slug '${slug}'. Available tiers: ${availableTiers.join(', ')}`);
|
|
91
|
+
}
|
|
92
|
+
return tierRow;
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=lookup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lookup.js","sourceRoot":"","sources":["../../src/pricing/lookup.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAS1C;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,QAAQ,CAAC,IAAkB;IACzC,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,WAAW,EAAE,YAAY,EAAE,iBAAiB,EAAE,GAAG,IAAI,CAAA;IAEzE,IAAI,WAAW,GAAG,CAAC,IAAI,YAAY,GAAG,CAA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G,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,KAAK,IAAI,CAAC,CAAA;IACzD,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC1B,MAAM,cAAc,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;QACtD,MAAM,IAAI,KAAK,CACb,OAAO,IAAI,uBAAuB,IAAI,uBAAuB,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CACzF,CAAA;IACH,CAAC;IACD,OAAO,OAAO,CAAA;AAChB,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* language-models / pricing — canonical model pricing table.
|
|
3
|
+
*
|
|
4
|
+
* All rates are USD per 1,000,000 tokens (per1M form, NOT per1k). Sourced
|
|
5
|
+
* from public list prices on 2026-05-07. Where prior repo tables disagree,
|
|
6
|
+
* the most-recently-updated source wins:
|
|
7
|
+
*
|
|
8
|
+
* - **Vertex Gemini 3.x**: startup-builder/packages/llm-vertex-batch
|
|
9
|
+
* (sb-srnl 2026-05-07 verified) is canonical for the flex/batch tier.
|
|
10
|
+
* startup-builder/packages/llm-vertex (same date) is canonical for
|
|
11
|
+
* standard interactive pricing.
|
|
12
|
+
* - **Vertex Gemini 2.5**: startup-builder/llm-vertex-batch is canonical
|
|
13
|
+
* (icps's `gemini-2.5-flash` rates were ~4× off — likely transposed
|
|
14
|
+
* from a different SKU).
|
|
15
|
+
* - **Bedrock Anthropic**: startup-builder/packages/llm-bedrock is the
|
|
16
|
+
* most-recently-curated table (matches AWS Bedrock public pricing on
|
|
17
|
+
* 2026-05-07).
|
|
18
|
+
* - **Embeddings**: icps/packages/llm/pricing.ts is the source for
|
|
19
|
+
* `gemini-embedding-2`. Bedrock has no first-party Gemini embedding
|
|
20
|
+
* SKU; Anthropic has no embedding SKU. Embedding lives under
|
|
21
|
+
* `aistudio/` since the cheapest path is the AI Studio API key (icps's
|
|
22
|
+
* 2026-05-07 fallback chain — the path startup-builder also uses).
|
|
23
|
+
*
|
|
24
|
+
* 200K-context tier breakpoint:
|
|
25
|
+
*
|
|
26
|
+
* Gemini 3.1 Pro Preview list pricing has a 2× rate above 200K input
|
|
27
|
+
* tokens. We model this with `contextTierBreakpoint: 200_000` +
|
|
28
|
+
* `contextTierAbove`. Anthropic Claude has flat pricing (no breakpoint).
|
|
29
|
+
* Gemini 2.5 + 3.x flash-lite + embedding SKUs are flat too.
|
|
30
|
+
*
|
|
31
|
+
* Adding a new SKU:
|
|
32
|
+
*
|
|
33
|
+
* 1. Append a new row keyed on `<provider>/<short-slug>` + `tier`. Both
|
|
34
|
+
* fields together form the lookup key; duplicates are caught by the
|
|
35
|
+
* table-integrity test.
|
|
36
|
+
* 2. If the SKU has a context-tier breakpoint, add
|
|
37
|
+
* `contextTierBreakpoint` + `contextTierAbove`. Otherwise omit them.
|
|
38
|
+
* 3. If both standard + batch tiers exist, add BOTH rows; downstream
|
|
39
|
+
* consumers select via `priceFor({ tier: ... })`. Vertex's batch tier
|
|
40
|
+
* is ~50% of standard; that's not enforced — declare the actual
|
|
41
|
+
* published rates.
|
|
42
|
+
* 4. Bump the package version (semver minor for additions).
|
|
43
|
+
*/
|
|
44
|
+
import type { ModelPricing } from './types.js';
|
|
45
|
+
export declare const PRICING_TABLE: readonly ModelPricing[];
|
|
46
|
+
//# sourceMappingURL=table.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"table.d.ts","sourceRoot":"","sources":["../../src/pricing/table.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAE9C,eAAO,MAAM,aAAa,EAAE,SAAS,YAAY,EA4LhD,CAAA"}
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* language-models / pricing — canonical model pricing table.
|
|
3
|
+
*
|
|
4
|
+
* All rates are USD per 1,000,000 tokens (per1M form, NOT per1k). Sourced
|
|
5
|
+
* from public list prices on 2026-05-07. Where prior repo tables disagree,
|
|
6
|
+
* the most-recently-updated source wins:
|
|
7
|
+
*
|
|
8
|
+
* - **Vertex Gemini 3.x**: startup-builder/packages/llm-vertex-batch
|
|
9
|
+
* (sb-srnl 2026-05-07 verified) is canonical for the flex/batch tier.
|
|
10
|
+
* startup-builder/packages/llm-vertex (same date) is canonical for
|
|
11
|
+
* standard interactive pricing.
|
|
12
|
+
* - **Vertex Gemini 2.5**: startup-builder/llm-vertex-batch is canonical
|
|
13
|
+
* (icps's `gemini-2.5-flash` rates were ~4× off — likely transposed
|
|
14
|
+
* from a different SKU).
|
|
15
|
+
* - **Bedrock Anthropic**: startup-builder/packages/llm-bedrock is the
|
|
16
|
+
* most-recently-curated table (matches AWS Bedrock public pricing on
|
|
17
|
+
* 2026-05-07).
|
|
18
|
+
* - **Embeddings**: icps/packages/llm/pricing.ts is the source for
|
|
19
|
+
* `gemini-embedding-2`. Bedrock has no first-party Gemini embedding
|
|
20
|
+
* SKU; Anthropic has no embedding SKU. Embedding lives under
|
|
21
|
+
* `aistudio/` since the cheapest path is the AI Studio API key (icps's
|
|
22
|
+
* 2026-05-07 fallback chain — the path startup-builder also uses).
|
|
23
|
+
*
|
|
24
|
+
* 200K-context tier breakpoint:
|
|
25
|
+
*
|
|
26
|
+
* Gemini 3.1 Pro Preview list pricing has a 2× rate above 200K input
|
|
27
|
+
* tokens. We model this with `contextTierBreakpoint: 200_000` +
|
|
28
|
+
* `contextTierAbove`. Anthropic Claude has flat pricing (no breakpoint).
|
|
29
|
+
* Gemini 2.5 + 3.x flash-lite + embedding SKUs are flat too.
|
|
30
|
+
*
|
|
31
|
+
* Adding a new SKU:
|
|
32
|
+
*
|
|
33
|
+
* 1. Append a new row keyed on `<provider>/<short-slug>` + `tier`. Both
|
|
34
|
+
* fields together form the lookup key; duplicates are caught by the
|
|
35
|
+
* table-integrity test.
|
|
36
|
+
* 2. If the SKU has a context-tier breakpoint, add
|
|
37
|
+
* `contextTierBreakpoint` + `contextTierAbove`. Otherwise omit them.
|
|
38
|
+
* 3. If both standard + batch tiers exist, add BOTH rows; downstream
|
|
39
|
+
* consumers select via `priceFor({ tier: ... })`. Vertex's batch tier
|
|
40
|
+
* is ~50% of standard; that's not enforced — declare the actual
|
|
41
|
+
* published rates.
|
|
42
|
+
* 4. Bump the package version (semver minor for additions).
|
|
43
|
+
*/
|
|
44
|
+
export const PRICING_TABLE = [
|
|
45
|
+
// ---------------------------------------------------------------------
|
|
46
|
+
// Vertex Gemini 3.x (200K-context breakpoint applies to 3.1 Pro)
|
|
47
|
+
// ---------------------------------------------------------------------
|
|
48
|
+
// gemini-3.1-pro-preview standard interactive
|
|
49
|
+
// ≤200K: $2/M in, $12/M out ; >200K: $4/M in, $18/M out
|
|
50
|
+
{
|
|
51
|
+
provider: 'vertex',
|
|
52
|
+
slug: 'vertex/gemini-3.1-pro',
|
|
53
|
+
tier: 'standard',
|
|
54
|
+
inputPer1M: 2.0,
|
|
55
|
+
outputPer1M: 12.0,
|
|
56
|
+
contextTierBreakpoint: 200_000,
|
|
57
|
+
contextTierAbove: { inputPer1M: 4.0, outputPer1M: 18.0 },
|
|
58
|
+
},
|
|
59
|
+
// gemini-3.1-pro-preview flex/batch (sb-srnl 2026-05-07 verified)
|
|
60
|
+
// ≤200K: $1/M in, $6/M out ; >200K: $2/M in, $9/M out
|
|
61
|
+
{
|
|
62
|
+
provider: 'vertex',
|
|
63
|
+
slug: 'vertex/gemini-3.1-pro',
|
|
64
|
+
tier: 'batch',
|
|
65
|
+
inputPer1M: 1.0,
|
|
66
|
+
outputPer1M: 6.0,
|
|
67
|
+
contextTierBreakpoint: 200_000,
|
|
68
|
+
contextTierAbove: { inputPer1M: 2.0, outputPer1M: 9.0 },
|
|
69
|
+
},
|
|
70
|
+
// gemini-3.1-flash-lite-preview standard
|
|
71
|
+
// Flat: $0.25/M in, $1.50/M out (no breakpoint per public table)
|
|
72
|
+
{
|
|
73
|
+
provider: 'vertex',
|
|
74
|
+
slug: 'vertex/gemini-3.1-flash-lite',
|
|
75
|
+
tier: 'standard',
|
|
76
|
+
inputPer1M: 0.25,
|
|
77
|
+
outputPer1M: 1.5,
|
|
78
|
+
},
|
|
79
|
+
// gemini-3.1-flash-lite-preview flex/batch
|
|
80
|
+
// Flat: $0.13/M in, $0.75/M out
|
|
81
|
+
{
|
|
82
|
+
provider: 'vertex',
|
|
83
|
+
slug: 'vertex/gemini-3.1-flash-lite',
|
|
84
|
+
tier: 'batch',
|
|
85
|
+
inputPer1M: 0.13,
|
|
86
|
+
outputPer1M: 0.75,
|
|
87
|
+
},
|
|
88
|
+
// gemini-3-pro-preview — placeholder pricing using 3.1 sibling rates
|
|
89
|
+
// (Vertex hasn't published separate 3.0 list prices as of 2026-05-07)
|
|
90
|
+
{
|
|
91
|
+
provider: 'vertex',
|
|
92
|
+
slug: 'vertex/gemini-3-pro',
|
|
93
|
+
tier: 'standard',
|
|
94
|
+
inputPer1M: 2.0,
|
|
95
|
+
outputPer1M: 12.0,
|
|
96
|
+
contextTierBreakpoint: 200_000,
|
|
97
|
+
contextTierAbove: { inputPer1M: 4.0, outputPer1M: 18.0 },
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
provider: 'vertex',
|
|
101
|
+
slug: 'vertex/gemini-3-pro',
|
|
102
|
+
tier: 'batch',
|
|
103
|
+
inputPer1M: 1.0,
|
|
104
|
+
outputPer1M: 6.0,
|
|
105
|
+
contextTierBreakpoint: 200_000,
|
|
106
|
+
contextTierAbove: { inputPer1M: 2.0, outputPer1M: 9.0 },
|
|
107
|
+
},
|
|
108
|
+
// gemini-3-flash-preview — placeholder using 3.1 flash-lite sibling rates
|
|
109
|
+
{
|
|
110
|
+
provider: 'vertex',
|
|
111
|
+
slug: 'vertex/gemini-3-flash',
|
|
112
|
+
tier: 'standard',
|
|
113
|
+
inputPer1M: 0.25,
|
|
114
|
+
outputPer1M: 1.5,
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
provider: 'vertex',
|
|
118
|
+
slug: 'vertex/gemini-3-flash',
|
|
119
|
+
tier: 'batch',
|
|
120
|
+
inputPer1M: 0.13,
|
|
121
|
+
outputPer1M: 0.75,
|
|
122
|
+
},
|
|
123
|
+
// ---------------------------------------------------------------------
|
|
124
|
+
// Vertex Gemini 2.5 (no context-tier breakpoint per public table)
|
|
125
|
+
// ---------------------------------------------------------------------
|
|
126
|
+
// gemini-2.5-pro standard: $1.25/M in, $10/M out
|
|
127
|
+
{
|
|
128
|
+
provider: 'vertex',
|
|
129
|
+
slug: 'vertex/gemini-2.5-pro',
|
|
130
|
+
tier: 'standard',
|
|
131
|
+
inputPer1M: 1.25,
|
|
132
|
+
outputPer1M: 10.0,
|
|
133
|
+
},
|
|
134
|
+
// gemini-2.5-pro batch: ~50% of standard
|
|
135
|
+
{
|
|
136
|
+
provider: 'vertex',
|
|
137
|
+
slug: 'vertex/gemini-2.5-pro',
|
|
138
|
+
tier: 'batch',
|
|
139
|
+
inputPer1M: 0.625,
|
|
140
|
+
outputPer1M: 5.0,
|
|
141
|
+
},
|
|
142
|
+
// gemini-2.5-flash standard: $0.075/M in, $0.30/M out
|
|
143
|
+
// (startup-builder/llm-vertex-batch source — supersedes icps's stale rate)
|
|
144
|
+
{
|
|
145
|
+
provider: 'vertex',
|
|
146
|
+
slug: 'vertex/gemini-2.5-flash',
|
|
147
|
+
tier: 'standard',
|
|
148
|
+
inputPer1M: 0.075,
|
|
149
|
+
outputPer1M: 0.3,
|
|
150
|
+
},
|
|
151
|
+
// gemini-2.5-flash batch: ~50% of standard
|
|
152
|
+
{
|
|
153
|
+
provider: 'vertex',
|
|
154
|
+
slug: 'vertex/gemini-2.5-flash',
|
|
155
|
+
tier: 'batch',
|
|
156
|
+
inputPer1M: 0.0375,
|
|
157
|
+
outputPer1M: 0.15,
|
|
158
|
+
},
|
|
159
|
+
// ---------------------------------------------------------------------
|
|
160
|
+
// Bedrock Anthropic Claude (flat pricing — no context-tier breakpoint)
|
|
161
|
+
// ---------------------------------------------------------------------
|
|
162
|
+
// claude-opus-4-7: $15/M in, $75/M out
|
|
163
|
+
{
|
|
164
|
+
provider: 'bedrock',
|
|
165
|
+
slug: 'bedrock/claude-opus-4-7',
|
|
166
|
+
tier: 'standard',
|
|
167
|
+
inputPer1M: 15.0,
|
|
168
|
+
outputPer1M: 75.0,
|
|
169
|
+
},
|
|
170
|
+
// claude-opus-4-6: same as 4-7
|
|
171
|
+
{
|
|
172
|
+
provider: 'bedrock',
|
|
173
|
+
slug: 'bedrock/claude-opus-4-6',
|
|
174
|
+
tier: 'standard',
|
|
175
|
+
inputPer1M: 15.0,
|
|
176
|
+
outputPer1M: 75.0,
|
|
177
|
+
},
|
|
178
|
+
// claude-sonnet-4-7: $3/M in, $15/M out
|
|
179
|
+
{
|
|
180
|
+
provider: 'bedrock',
|
|
181
|
+
slug: 'bedrock/claude-sonnet-4-7',
|
|
182
|
+
tier: 'standard',
|
|
183
|
+
inputPer1M: 3.0,
|
|
184
|
+
outputPer1M: 15.0,
|
|
185
|
+
},
|
|
186
|
+
// claude-sonnet-4-6: same as 4-7
|
|
187
|
+
{
|
|
188
|
+
provider: 'bedrock',
|
|
189
|
+
slug: 'bedrock/claude-sonnet-4-6',
|
|
190
|
+
tier: 'standard',
|
|
191
|
+
inputPer1M: 3.0,
|
|
192
|
+
outputPer1M: 15.0,
|
|
193
|
+
},
|
|
194
|
+
// claude-haiku-4-5: $1/M in, $5/M out
|
|
195
|
+
{
|
|
196
|
+
provider: 'bedrock',
|
|
197
|
+
slug: 'bedrock/claude-haiku-4-5',
|
|
198
|
+
tier: 'standard',
|
|
199
|
+
inputPer1M: 1.0,
|
|
200
|
+
outputPer1M: 5.0,
|
|
201
|
+
},
|
|
202
|
+
// ---------------------------------------------------------------------
|
|
203
|
+
// Google AI Studio embeddings
|
|
204
|
+
// ---------------------------------------------------------------------
|
|
205
|
+
// gemini-embedding-2: $0.15/M input (no output side — pure embedding SKU)
|
|
206
|
+
{
|
|
207
|
+
provider: 'google-ai-studio',
|
|
208
|
+
slug: 'aistudio/gemini-embedding-2',
|
|
209
|
+
tier: 'standard',
|
|
210
|
+
inputPer1M: 0.15,
|
|
211
|
+
outputPer1M: 0,
|
|
212
|
+
},
|
|
213
|
+
];
|
|
214
|
+
//# sourceMappingURL=table.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"table.js","sourceRoot":"","sources":["../../src/pricing/table.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AAIH,MAAM,CAAC,MAAM,aAAa,GAA4B;IACpD,wEAAwE;IACxE,iEAAiE;IACjE,wEAAwE;IAExE,8CAA8C;IAC9C,0DAA0D;IAC1D;QACE,QAAQ,EAAE,QAAQ;QAClB,IAAI,EAAE,uBAAuB;QAC7B,IAAI,EAAE,UAAU;QAChB,UAAU,EAAE,GAAG;QACf,WAAW,EAAE,IAAI;QACjB,qBAAqB,EAAE,OAAO;QAC9B,gBAAgB,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE;KACzD;IAED,kEAAkE;IAClE,wDAAwD;IACxD;QACE,QAAQ,EAAE,QAAQ;QAClB,IAAI,EAAE,uBAAuB;QAC7B,IAAI,EAAE,OAAO;QACb,UAAU,EAAE,GAAG;QACf,WAAW,EAAE,GAAG;QAChB,qBAAqB,EAAE,OAAO;QAC9B,gBAAgB,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE;KACxD;IAED,yCAAyC;IACzC,iEAAiE;IACjE;QACE,QAAQ,EAAE,QAAQ;QAClB,IAAI,EAAE,8BAA8B;QACpC,IAAI,EAAE,UAAU;QAChB,UAAU,EAAE,IAAI;QAChB,WAAW,EAAE,GAAG;KACjB;IAED,2CAA2C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,kBAAkB;QAC5B,IAAI,EAAE,6BAA6B;QACnC,IAAI,EAAE,UAAU;QAChB,UAAU,EAAE,IAAI;QAChB,WAAW,EAAE,CAAC;KACf;CACF,CAAA"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* language-models / pricing — type definitions for the canonical pricing table.
|
|
3
|
+
*
|
|
4
|
+
* Schema design notes (sb-ncer 2026-05-07):
|
|
5
|
+
*
|
|
6
|
+
* 1. **Provider** is the upstream API surface, not the model family. AWS
|
|
7
|
+
* Bedrock hosts Anthropic Claude, but `provider: 'bedrock'` (not
|
|
8
|
+
* `'anthropic'`) — same model, different cost when consumed via
|
|
9
|
+
* Anthropic's first-party API key (provider: 'anthropic' would be a
|
|
10
|
+
* DIFFERENT row with potentially different rates).
|
|
11
|
+
*
|
|
12
|
+
* 2. **Slug** is the caller-facing string: `<provider>/<short-name>`.
|
|
13
|
+
* Multiple slugs (the cascade short slug, the SDK-native id, etc.)
|
|
14
|
+
* can map to the same logical SKU — but for the canonical primitive
|
|
15
|
+
* we only carry the cascade short slug (`vertex/gemini-3.1-pro`,
|
|
16
|
+
* `bedrock/claude-opus-4-7`). Adapter packages can layer their own
|
|
17
|
+
* rewrite tables on top.
|
|
18
|
+
*
|
|
19
|
+
* 3. **Tier** distinguishes pricing modes for the same SKU:
|
|
20
|
+
* - `standard`: synchronous interactive pricing (full price)
|
|
21
|
+
* - `batch`: async batch-prediction pricing (typically 50% discount)
|
|
22
|
+
* - `flex`: flex-tier pricing (Vertex's name for batch, kept as alias)
|
|
23
|
+
* - `provisioned`: provisioned-throughput pricing (per-hour, not
|
|
24
|
+
* currently modeled — placeholder for future PT entries)
|
|
25
|
+
*
|
|
26
|
+
* 4. **contextTierBreakpoint + contextTierAbove**: Gemini 3.x SKUs apply
|
|
27
|
+
* a 2× rate above 200K input tokens; Anthropic Claude pricing is flat.
|
|
28
|
+
* Optional fields — when absent, the base rate applies regardless of
|
|
29
|
+
* input size.
|
|
30
|
+
*/
|
|
31
|
+
export type Provider = 'vertex' | 'bedrock' | 'openai' | 'anthropic' | 'google-ai-studio';
|
|
32
|
+
export type PricingTier = 'standard' | 'batch' | 'flex' | 'provisioned';
|
|
33
|
+
/** Rates expressed in USD per 1,000,000 tokens. */
|
|
34
|
+
export interface RateBlock {
|
|
35
|
+
/** USD per 1M input tokens. */
|
|
36
|
+
readonly inputPer1M: number;
|
|
37
|
+
/** USD per 1M output (completion) tokens. */
|
|
38
|
+
readonly outputPer1M: number;
|
|
39
|
+
/**
|
|
40
|
+
* Optional USD per 1M cached input tokens (prompt-caching tier). When
|
|
41
|
+
* absent, callers should fall back to inputPer1M (no cache discount).
|
|
42
|
+
*/
|
|
43
|
+
readonly cachedInputPer1M?: number;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Single canonical pricing row. Identity is `(slug, tier)` — provider is
|
|
47
|
+
* derived from the slug prefix and stored explicitly only for tooling
|
|
48
|
+
* convenience.
|
|
49
|
+
*/
|
|
50
|
+
export interface ModelPricing extends RateBlock {
|
|
51
|
+
readonly provider: Provider;
|
|
52
|
+
readonly slug: string;
|
|
53
|
+
readonly tier: PricingTier;
|
|
54
|
+
/**
|
|
55
|
+
* Token count at which pricing changes (inclusive — i.e. inputs >=
|
|
56
|
+
* breakpoint use contextTierAbove). Currently only Gemini 3.x SKUs
|
|
57
|
+
* have a breakpoint (200_000). Anthropic Claude has flat pricing.
|
|
58
|
+
*/
|
|
59
|
+
readonly contextTierBreakpoint?: number;
|
|
60
|
+
/** Rates that apply when inputTokens >= contextTierBreakpoint. */
|
|
61
|
+
readonly contextTierAbove?: RateBlock;
|
|
62
|
+
}
|
|
63
|
+
export interface PriceForArgs {
|
|
64
|
+
readonly slug: string;
|
|
65
|
+
readonly tier: PricingTier;
|
|
66
|
+
readonly inputTokens: number;
|
|
67
|
+
readonly outputTokens: number;
|
|
68
|
+
/**
|
|
69
|
+
* Optional cached input tokens (subset of inputTokens that hit a
|
|
70
|
+
* prompt-caching tier). Billed at cachedInputPer1M when the row
|
|
71
|
+
* defines it; otherwise at inputPer1M (i.e. no discount).
|
|
72
|
+
*/
|
|
73
|
+
readonly cachedInputTokens?: number;
|
|
74
|
+
}
|
|
75
|
+
export interface PriceForResult {
|
|
76
|
+
readonly inputUsd: number;
|
|
77
|
+
readonly outputUsd: number;
|
|
78
|
+
readonly totalUsd: number;
|
|
79
|
+
}
|
|
80
|
+
export interface HasPricingArgs {
|
|
81
|
+
readonly slug: string;
|
|
82
|
+
readonly tier: PricingTier;
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/pricing/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,MAAM,MAAM,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,QAAQ,GAAG,WAAW,GAAG,kBAAkB,CAAA;AAEzF,MAAM,MAAM,WAAW,GAAG,UAAU,GAAG,OAAO,GAAG,MAAM,GAAG,aAAa,CAAA;AAEvE,mDAAmD;AACnD,MAAM,WAAW,SAAS;IACxB,+BAA+B;IAC/B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,6CAA6C;IAC7C,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;IAC5B;;;OAGG;IACH,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAA;CACnC;AAED;;;;GAIG;AACH,MAAM,WAAW,YAAa,SAAQ,SAAS;IAC7C,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAA;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAA;IAC1B;;;;OAIG;IACH,QAAQ,CAAC,qBAAqB,CAAC,EAAE,MAAM,CAAA;IACvC,kEAAkE;IAClE,QAAQ,CAAC,gBAAgB,CAAC,EAAE,SAAS,CAAA;CACtC;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAA;IAC1B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;IAC5B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;IAC7B;;;;OAIG;IACH,QAAQ,CAAC,iBAAiB,CAAC,EAAE,MAAM,CAAA;CACpC;AAED,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;CAC1B;AAED,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAA;CAC3B"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* language-models / pricing — type definitions for the canonical pricing table.
|
|
3
|
+
*
|
|
4
|
+
* Schema design notes (sb-ncer 2026-05-07):
|
|
5
|
+
*
|
|
6
|
+
* 1. **Provider** is the upstream API surface, not the model family. AWS
|
|
7
|
+
* Bedrock hosts Anthropic Claude, but `provider: 'bedrock'` (not
|
|
8
|
+
* `'anthropic'`) — same model, different cost when consumed via
|
|
9
|
+
* Anthropic's first-party API key (provider: 'anthropic' would be a
|
|
10
|
+
* DIFFERENT row with potentially different rates).
|
|
11
|
+
*
|
|
12
|
+
* 2. **Slug** is the caller-facing string: `<provider>/<short-name>`.
|
|
13
|
+
* Multiple slugs (the cascade short slug, the SDK-native id, etc.)
|
|
14
|
+
* can map to the same logical SKU — but for the canonical primitive
|
|
15
|
+
* we only carry the cascade short slug (`vertex/gemini-3.1-pro`,
|
|
16
|
+
* `bedrock/claude-opus-4-7`). Adapter packages can layer their own
|
|
17
|
+
* rewrite tables on top.
|
|
18
|
+
*
|
|
19
|
+
* 3. **Tier** distinguishes pricing modes for the same SKU:
|
|
20
|
+
* - `standard`: synchronous interactive pricing (full price)
|
|
21
|
+
* - `batch`: async batch-prediction pricing (typically 50% discount)
|
|
22
|
+
* - `flex`: flex-tier pricing (Vertex's name for batch, kept as alias)
|
|
23
|
+
* - `provisioned`: provisioned-throughput pricing (per-hour, not
|
|
24
|
+
* currently modeled — placeholder for future PT entries)
|
|
25
|
+
*
|
|
26
|
+
* 4. **contextTierBreakpoint + contextTierAbove**: Gemini 3.x SKUs apply
|
|
27
|
+
* a 2× rate above 200K input tokens; Anthropic Claude pricing is flat.
|
|
28
|
+
* Optional fields — when absent, the base rate applies regardless of
|
|
29
|
+
* input size.
|
|
30
|
+
*/
|
|
31
|
+
export {};
|
|
32
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/pricing/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "language-models",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"description": "Model listing and resolution for LLM providers",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -9,8 +9,21 @@
|
|
|
9
9
|
".": {
|
|
10
10
|
"import": "./dist/index.js",
|
|
11
11
|
"types": "./dist/index.d.ts"
|
|
12
|
+
},
|
|
13
|
+
"./pricing": {
|
|
14
|
+
"import": "./dist/pricing/index.js",
|
|
15
|
+
"types": "./dist/pricing/index.d.ts"
|
|
12
16
|
}
|
|
13
17
|
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tsc -p tsconfig.json && cp -r data dist/",
|
|
20
|
+
"dev": "tsc -p tsconfig.json --watch",
|
|
21
|
+
"test": "vitest run",
|
|
22
|
+
"typecheck": "tsc --noEmit",
|
|
23
|
+
"lint": "eslint .",
|
|
24
|
+
"clean": "rm -rf dist",
|
|
25
|
+
"fetch-models": "npx tsx scripts/fetch-models.ts"
|
|
26
|
+
},
|
|
14
27
|
"keywords": [
|
|
15
28
|
"ai",
|
|
16
29
|
"llm",
|
|
@@ -19,14 +32,5 @@
|
|
|
19
32
|
"primitives"
|
|
20
33
|
],
|
|
21
34
|
"license": "MIT",
|
|
22
|
-
"dependencies": {}
|
|
23
|
-
|
|
24
|
-
"build": "tsc -p tsconfig.json && cp -r data dist/",
|
|
25
|
-
"dev": "tsc -p tsconfig.json --watch",
|
|
26
|
-
"test": "vitest",
|
|
27
|
-
"typecheck": "tsc --noEmit",
|
|
28
|
-
"lint": "eslint .",
|
|
29
|
-
"clean": "rm -rf dist",
|
|
30
|
-
"fetch-models": "npx tsx scripts/fetch-models.ts"
|
|
31
|
-
}
|
|
32
|
-
}
|
|
35
|
+
"dependencies": {}
|
|
36
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -16,6 +16,47 @@ export {
|
|
|
16
16
|
type ModelInfo,
|
|
17
17
|
type ProviderEndpoint,
|
|
18
18
|
type ResolvedModel,
|
|
19
|
-
type DirectProvider
|
|
19
|
+
type DirectProvider,
|
|
20
20
|
} from './models.js'
|
|
21
21
|
export { ALIASES } from './aliases.js'
|
|
22
|
+
|
|
23
|
+
// Per-model resilience and tier policy data.
|
|
24
|
+
// The runtime *machinery* (RetryPolicy, CircuitBreaker, FallbackChain) lives
|
|
25
|
+
// in `ai-functions`; the *data* (which categories are retryable, which models
|
|
26
|
+
// to fall back to, which batch tiers are eligible) lives here alongside the
|
|
27
|
+
// catalog because it's a per-model concern.
|
|
28
|
+
export {
|
|
29
|
+
policyFor,
|
|
30
|
+
derivePolicy,
|
|
31
|
+
defaultPolicy,
|
|
32
|
+
resetPolicyCache,
|
|
33
|
+
listAliases,
|
|
34
|
+
DEFAULT_RETRY,
|
|
35
|
+
DEFAULT_CIRCUIT_BREAKER,
|
|
36
|
+
type ModelPolicy,
|
|
37
|
+
type RetryPolicyData,
|
|
38
|
+
type CircuitBreakerPolicyData,
|
|
39
|
+
type BatchTier,
|
|
40
|
+
type ErrorCategoryName,
|
|
41
|
+
type ErrorMapping,
|
|
42
|
+
} from './policy.js'
|
|
43
|
+
|
|
44
|
+
// =============================================================================
|
|
45
|
+
// Pricing (consolidated from former @primitives/llm-pricing — see
|
|
46
|
+
// `./pricing/` for the source. Also re-exported under the subpath
|
|
47
|
+
// `language-models/pricing` for surgical imports.)
|
|
48
|
+
// =============================================================================
|
|
49
|
+
export {
|
|
50
|
+
PRICING_TABLE,
|
|
51
|
+
priceFor,
|
|
52
|
+
listSlugs,
|
|
53
|
+
hasPricing,
|
|
54
|
+
rowsForSlug,
|
|
55
|
+
type ModelPricing,
|
|
56
|
+
type PricingTier,
|
|
57
|
+
type Provider,
|
|
58
|
+
type RateBlock,
|
|
59
|
+
type PriceForArgs,
|
|
60
|
+
type PriceForResult,
|
|
61
|
+
type HasPricingArgs,
|
|
62
|
+
} from './pricing/index.js'
|
package/src/models.ts
CHANGED
|
@@ -63,7 +63,7 @@ export function list(): ModelInfo[] {
|
|
|
63
63
|
* Get a model by exact ID
|
|
64
64
|
*/
|
|
65
65
|
export function get(id: string): ModelInfo | undefined {
|
|
66
|
-
return loadModels().find(m => m.id === id)
|
|
66
|
+
return loadModels().find((m) => m.id === id)
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
/**
|
|
@@ -72,9 +72,8 @@ export function get(id: string): ModelInfo | undefined {
|
|
|
72
72
|
*/
|
|
73
73
|
export function search(query: string): ModelInfo[] {
|
|
74
74
|
const q = query.toLowerCase()
|
|
75
|
-
return loadModels().filter(
|
|
76
|
-
m.id.toLowerCase().includes(q) ||
|
|
77
|
-
m.name.toLowerCase().includes(q)
|
|
75
|
+
return loadModels().filter(
|
|
76
|
+
(m) => m.id.toLowerCase().includes(q) || m.name.toLowerCase().includes(q)
|
|
78
77
|
)
|
|
79
78
|
}
|
|
80
79
|
|
|
@@ -123,7 +122,7 @@ export function resolve(input: string): string {
|
|
|
123
122
|
* These providers have special capabilities like MCP, extended thinking, etc.
|
|
124
123
|
*/
|
|
125
124
|
export const DIRECT_PROVIDERS = ['openai', 'anthropic', 'google'] as const
|
|
126
|
-
export type DirectProvider = typeof DIRECT_PROVIDERS[number]
|
|
125
|
+
export type DirectProvider = (typeof DIRECT_PROVIDERS)[number]
|
|
127
126
|
|
|
128
127
|
/**
|
|
129
128
|
* Result of resolving a model with provider routing info
|
|
@@ -164,11 +163,8 @@ export function resolveWithProvider(input: string): ResolvedModel {
|
|
|
164
163
|
|
|
165
164
|
const supportsDirectRouting = (DIRECT_PROVIDERS as readonly string[]).includes(provider)
|
|
166
165
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
supportsDirectRouting,
|
|
172
|
-
model
|
|
173
|
-
}
|
|
166
|
+
const result: ResolvedModel = { id, provider, supportsDirectRouting }
|
|
167
|
+
if (model) result.model = model
|
|
168
|
+
if (model?.provider_model_id) result.providerModelId = model.provider_model_id
|
|
169
|
+
return result
|
|
174
170
|
}
|