@bymax-one/nest-ai-tokens 1.0.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/CHANGELOG.md +113 -0
- package/LICENSE +21 -0
- package/README.md +795 -0
- package/dist/prices/index.cjs +218 -0
- package/dist/prices/index.d.cts +131 -0
- package/dist/prices/index.d.ts +131 -0
- package/dist/prices/index.mjs +216 -0
- package/dist/prisma/index.cjs +1197 -0
- package/dist/prisma/index.d.cts +677 -0
- package/dist/prisma/index.d.ts +677 -0
- package/dist/prisma/index.mjs +1195 -0
- package/dist/prisma/migrations/0001_init.sql +198 -0
- package/dist/prisma/schema.prisma.fragment +197 -0
- package/dist/redis/index.cjs +110 -0
- package/dist/redis/index.d.cts +98 -0
- package/dist/redis/index.d.ts +98 -0
- package/dist/redis/index.mjs +107 -0
- package/dist/server/index.cjs +4405 -0
- package/dist/server/index.d.cts +3202 -0
- package/dist/server/index.d.ts +3202 -0
- package/dist/server/index.mjs +4354 -0
- package/dist/shared/index.cjs +659 -0
- package/dist/shared/index.d.cts +1044 -0
- package/dist/shared/index.d.ts +1044 -0
- package/dist/shared/index.mjs +629 -0
- package/package.json +216 -0
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/prices/model-prices.seed.ts
|
|
4
|
+
var ZERO_RATES = {
|
|
5
|
+
inputNanoUsdPerMillion: 0n,
|
|
6
|
+
outputNanoUsdPerMillion: 0n,
|
|
7
|
+
cacheReadNanoUsdPerMillion: 0n,
|
|
8
|
+
cacheWrite5mNanoUsdPerMillion: 0n,
|
|
9
|
+
cacheWrite1hNanoUsdPerMillion: 0n,
|
|
10
|
+
reasoningNanoUsdPerMillion: 0n,
|
|
11
|
+
audioInNanoUsdPerMillion: 0n,
|
|
12
|
+
audioOutNanoUsdPerMillion: 0n,
|
|
13
|
+
imageInNanoUsdPerMillion: 0n,
|
|
14
|
+
imageOutNanoUsdPerMillion: 0n
|
|
15
|
+
};
|
|
16
|
+
function makeRow(input) {
|
|
17
|
+
return {
|
|
18
|
+
provider: input.provider,
|
|
19
|
+
model: input.model,
|
|
20
|
+
operation: input.operation ?? "chat",
|
|
21
|
+
serviceTier: input.serviceTier ?? "standard",
|
|
22
|
+
...ZERO_RATES,
|
|
23
|
+
...input.rates,
|
|
24
|
+
...input.tierThresholdTokens !== void 0 ? { tierThresholdTokens: input.tierThresholdTokens } : {},
|
|
25
|
+
...input.tierInputNanoUsdPerMillion !== void 0 ? { tierInputNanoUsdPerMillion: input.tierInputNanoUsdPerMillion } : {},
|
|
26
|
+
...input.tierOutputNanoUsdPerMillion !== void 0 ? { tierOutputNanoUsdPerMillion: input.tierOutputNanoUsdPerMillion } : {},
|
|
27
|
+
...input.unitRates !== void 0 ? { unitRates: input.unitRates } : {},
|
|
28
|
+
currency: "USD",
|
|
29
|
+
source: "snapshot"
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
var MODEL_PRICES_SEED = [
|
|
33
|
+
// ── OpenAI ───────────────────────────────────────────────────────────────
|
|
34
|
+
// source: OpenAI pricing snapshot 2026-07 — gpt-5 $1.25/$10 per M, cached input $0.125/M.
|
|
35
|
+
makeRow({
|
|
36
|
+
provider: "openai",
|
|
37
|
+
model: "gpt-5",
|
|
38
|
+
rates: {
|
|
39
|
+
inputNanoUsdPerMillion: 1250000000n,
|
|
40
|
+
outputNanoUsdPerMillion: 10000000000n,
|
|
41
|
+
cacheReadNanoUsdPerMillion: 125000000n,
|
|
42
|
+
reasoningNanoUsdPerMillion: 10000000000n
|
|
43
|
+
},
|
|
44
|
+
unitRates: { web_search_requests: 10000000n }
|
|
45
|
+
// VERIFY: $0.01 per built-in web-search call.
|
|
46
|
+
}),
|
|
47
|
+
// source: OpenAI pricing snapshot 2026-07 — Batch API ~50% of standard.
|
|
48
|
+
makeRow({
|
|
49
|
+
provider: "openai",
|
|
50
|
+
model: "gpt-5",
|
|
51
|
+
serviceTier: "batch",
|
|
52
|
+
rates: {
|
|
53
|
+
inputNanoUsdPerMillion: 625000000n,
|
|
54
|
+
outputNanoUsdPerMillion: 5000000000n,
|
|
55
|
+
cacheReadNanoUsdPerMillion: 62500000n,
|
|
56
|
+
reasoningNanoUsdPerMillion: 5000000000n
|
|
57
|
+
}
|
|
58
|
+
}),
|
|
59
|
+
// source: OpenAI pricing snapshot 2026-07 — gpt-5-mini $0.25/$2 per M.
|
|
60
|
+
makeRow({
|
|
61
|
+
provider: "openai",
|
|
62
|
+
model: "gpt-5-mini",
|
|
63
|
+
rates: {
|
|
64
|
+
inputNanoUsdPerMillion: 250000000n,
|
|
65
|
+
outputNanoUsdPerMillion: 2000000000n,
|
|
66
|
+
cacheReadNanoUsdPerMillion: 25000000n,
|
|
67
|
+
reasoningNanoUsdPerMillion: 2000000000n
|
|
68
|
+
}
|
|
69
|
+
}),
|
|
70
|
+
// source: OpenAI pricing snapshot 2026-07 — text-embedding-3-small $0.02/M.
|
|
71
|
+
makeRow({
|
|
72
|
+
provider: "openai",
|
|
73
|
+
model: "text-embedding-3-small",
|
|
74
|
+
operation: "embeddings",
|
|
75
|
+
rates: { inputNanoUsdPerMillion: 20000000n }
|
|
76
|
+
}),
|
|
77
|
+
// source: OpenAI pricing snapshot 2026-07 — text-embedding-3-large $0.13/M.
|
|
78
|
+
makeRow({
|
|
79
|
+
provider: "openai",
|
|
80
|
+
model: "text-embedding-3-large",
|
|
81
|
+
operation: "embeddings",
|
|
82
|
+
rates: { inputNanoUsdPerMillion: 130000000n }
|
|
83
|
+
}),
|
|
84
|
+
// ── Anthropic ────────────────────────────────────────────────────────────
|
|
85
|
+
// source: Anthropic pricing snapshot 2026-07 — Opus $15/$75 per M; cache read 0.1×, write5m 1.25×, write1h 2× input.
|
|
86
|
+
makeRow({
|
|
87
|
+
provider: "anthropic",
|
|
88
|
+
model: "claude-opus-4",
|
|
89
|
+
rates: {
|
|
90
|
+
inputNanoUsdPerMillion: 15000000000n,
|
|
91
|
+
outputNanoUsdPerMillion: 75000000000n,
|
|
92
|
+
cacheReadNanoUsdPerMillion: 1500000000n,
|
|
93
|
+
cacheWrite5mNanoUsdPerMillion: 18750000000n,
|
|
94
|
+
cacheWrite1hNanoUsdPerMillion: 30000000000n,
|
|
95
|
+
reasoningNanoUsdPerMillion: 75000000000n
|
|
96
|
+
},
|
|
97
|
+
unitRates: { web_search_requests: 10000000n }
|
|
98
|
+
// source: Anthropic web search $10 / 1,000 requests.
|
|
99
|
+
}),
|
|
100
|
+
// source: Anthropic pricing snapshot 2026-07 — Sonnet $3/$15 per M.
|
|
101
|
+
makeRow({
|
|
102
|
+
provider: "anthropic",
|
|
103
|
+
model: "claude-sonnet-4",
|
|
104
|
+
rates: {
|
|
105
|
+
inputNanoUsdPerMillion: 3000000000n,
|
|
106
|
+
outputNanoUsdPerMillion: 15000000000n,
|
|
107
|
+
cacheReadNanoUsdPerMillion: 300000000n,
|
|
108
|
+
cacheWrite5mNanoUsdPerMillion: 3750000000n,
|
|
109
|
+
cacheWrite1hNanoUsdPerMillion: 6000000000n,
|
|
110
|
+
reasoningNanoUsdPerMillion: 15000000000n
|
|
111
|
+
}
|
|
112
|
+
}),
|
|
113
|
+
// source: Anthropic pricing snapshot 2026-07 — Haiku $0.80/$4 per M.
|
|
114
|
+
makeRow({
|
|
115
|
+
provider: "anthropic",
|
|
116
|
+
model: "claude-haiku-4",
|
|
117
|
+
rates: {
|
|
118
|
+
inputNanoUsdPerMillion: 800000000n,
|
|
119
|
+
outputNanoUsdPerMillion: 4000000000n,
|
|
120
|
+
cacheReadNanoUsdPerMillion: 80000000n,
|
|
121
|
+
cacheWrite5mNanoUsdPerMillion: 1000000000n,
|
|
122
|
+
cacheWrite1hNanoUsdPerMillion: 1600000000n,
|
|
123
|
+
reasoningNanoUsdPerMillion: 4000000000n
|
|
124
|
+
}
|
|
125
|
+
}),
|
|
126
|
+
// source: Anthropic pricing snapshot 2026-07 — Sonnet Batch API ~50% of standard.
|
|
127
|
+
makeRow({
|
|
128
|
+
provider: "anthropic",
|
|
129
|
+
model: "claude-sonnet-4",
|
|
130
|
+
serviceTier: "batch",
|
|
131
|
+
rates: {
|
|
132
|
+
inputNanoUsdPerMillion: 1500000000n,
|
|
133
|
+
outputNanoUsdPerMillion: 7500000000n,
|
|
134
|
+
cacheReadNanoUsdPerMillion: 150000000n,
|
|
135
|
+
cacheWrite5mNanoUsdPerMillion: 1875000000n,
|
|
136
|
+
cacheWrite1hNanoUsdPerMillion: 3000000000n,
|
|
137
|
+
reasoningNanoUsdPerMillion: 7500000000n
|
|
138
|
+
}
|
|
139
|
+
}),
|
|
140
|
+
// ── Google Gemini ────────────────────────────────────────────────────────
|
|
141
|
+
// source: Gemini pricing snapshot 2026-07 — 2.5 Pro $1.25/$10 (≤200k), $2.50/$15 above; cache read ~10% input.
|
|
142
|
+
makeRow({
|
|
143
|
+
provider: "gemini",
|
|
144
|
+
model: "gemini-2.5-pro",
|
|
145
|
+
rates: {
|
|
146
|
+
inputNanoUsdPerMillion: 1250000000n,
|
|
147
|
+
outputNanoUsdPerMillion: 10000000000n,
|
|
148
|
+
cacheReadNanoUsdPerMillion: 125000000n,
|
|
149
|
+
reasoningNanoUsdPerMillion: 10000000000n
|
|
150
|
+
},
|
|
151
|
+
tierThresholdTokens: 2e5,
|
|
152
|
+
tierInputNanoUsdPerMillion: 2500000000n,
|
|
153
|
+
tierOutputNanoUsdPerMillion: 15000000000n
|
|
154
|
+
}),
|
|
155
|
+
// source: Gemini pricing snapshot 2026-07 — 2.5 Flash $0.30/$2.50; long-context tier VERIFY.
|
|
156
|
+
makeRow({
|
|
157
|
+
provider: "gemini",
|
|
158
|
+
model: "gemini-2.5-flash",
|
|
159
|
+
rates: {
|
|
160
|
+
inputNanoUsdPerMillion: 300000000n,
|
|
161
|
+
outputNanoUsdPerMillion: 2500000000n,
|
|
162
|
+
cacheReadNanoUsdPerMillion: 30000000n,
|
|
163
|
+
reasoningNanoUsdPerMillion: 2500000000n
|
|
164
|
+
},
|
|
165
|
+
tierThresholdTokens: 2e5,
|
|
166
|
+
// VERIFY: Flash long-context surcharge.
|
|
167
|
+
tierInputNanoUsdPerMillion: 600000000n,
|
|
168
|
+
tierOutputNanoUsdPerMillion: 5000000000n
|
|
169
|
+
}),
|
|
170
|
+
// ── Mistral ──────────────────────────────────────────────────────────────
|
|
171
|
+
// source: Mistral pricing snapshot 2026-07 — Large $2/$6 per M.
|
|
172
|
+
makeRow({
|
|
173
|
+
provider: "mistral",
|
|
174
|
+
model: "mistral-large-latest",
|
|
175
|
+
rates: { inputNanoUsdPerMillion: 2000000000n, outputNanoUsdPerMillion: 6000000000n }
|
|
176
|
+
}),
|
|
177
|
+
// source: Mistral pricing snapshot 2026-07 — Medium $0.40/$2 per M.
|
|
178
|
+
makeRow({
|
|
179
|
+
provider: "mistral",
|
|
180
|
+
model: "mistral-medium-latest",
|
|
181
|
+
rates: { inputNanoUsdPerMillion: 400000000n, outputNanoUsdPerMillion: 2000000000n }
|
|
182
|
+
}),
|
|
183
|
+
// source: Mistral pricing snapshot 2026-07 — Small $0.10/$0.30 per M.
|
|
184
|
+
makeRow({
|
|
185
|
+
provider: "mistral",
|
|
186
|
+
model: "mistral-small-latest",
|
|
187
|
+
rates: { inputNanoUsdPerMillion: 100000000n, outputNanoUsdPerMillion: 300000000n }
|
|
188
|
+
}),
|
|
189
|
+
// ── DeepSeek / xAI / Groq (headline models) ──────────────────────────────
|
|
190
|
+
// source: DeepSeek pricing snapshot 2026-07 — chat $0.27/$1.10 per M; cache hit $0.07/M.
|
|
191
|
+
makeRow({
|
|
192
|
+
provider: "deepseek",
|
|
193
|
+
model: "deepseek-chat",
|
|
194
|
+
rates: {
|
|
195
|
+
inputNanoUsdPerMillion: 270000000n,
|
|
196
|
+
outputNanoUsdPerMillion: 1100000000n,
|
|
197
|
+
cacheReadNanoUsdPerMillion: 70000000n
|
|
198
|
+
}
|
|
199
|
+
}),
|
|
200
|
+
// source: xAI pricing snapshot 2026-07 — Grok $3/$15 per M.
|
|
201
|
+
makeRow({
|
|
202
|
+
provider: "xai",
|
|
203
|
+
model: "grok-4",
|
|
204
|
+
rates: {
|
|
205
|
+
inputNanoUsdPerMillion: 3000000000n,
|
|
206
|
+
outputNanoUsdPerMillion: 15000000000n,
|
|
207
|
+
reasoningNanoUsdPerMillion: 15000000000n
|
|
208
|
+
}
|
|
209
|
+
}),
|
|
210
|
+
// source: Groq pricing snapshot 2026-07 — Llama 3.3 70B $0.59/$0.79 per M. VERIFY.
|
|
211
|
+
makeRow({
|
|
212
|
+
provider: "groq",
|
|
213
|
+
model: "llama-3.3-70b-versatile",
|
|
214
|
+
rates: { inputNanoUsdPerMillion: 590000000n, outputNanoUsdPerMillion: 790000000n }
|
|
215
|
+
})
|
|
216
|
+
];
|
|
217
|
+
|
|
218
|
+
exports.MODEL_PRICES_SEED = MODEL_PRICES_SEED;
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Catalog of AI operation kinds a usage record can describe. The
|
|
3
|
+
* operation is part of the price-resolution key; `'responses'` bills identically
|
|
4
|
+
* to `'chat'` and shares its price rows (see spec §5.1).
|
|
5
|
+
* @layer shared
|
|
6
|
+
*/
|
|
7
|
+
/** Every operation kind the library can meter and price. */
|
|
8
|
+
declare const AI_OPERATIONS: readonly ["chat", "responses", "embeddings", "image", "video", "audio", "rerank", "moderation"];
|
|
9
|
+
/** A logical AI operation kind. */
|
|
10
|
+
type AiOperation = (typeof AI_OPERATIONS)[number];
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @fileoverview Catalog of response service tiers. Providers may silently
|
|
14
|
+
* downgrade a request (OpenAI returns `service_tier: "default"` when priority
|
|
15
|
+
* capacity is exhausted), so pricing keys off the tier reported in the RESPONSE,
|
|
16
|
+
* which is what the normalizers read (see spec §5.1).
|
|
17
|
+
* @layer shared
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* Service tier of the actual response. `'batch'` is the Batch API (~50% discount);
|
|
21
|
+
* `'flex'` is OpenAI flex processing (batch rates, synchronous); `'priority'` is
|
|
22
|
+
* paid premium; `'standard'` is the default.
|
|
23
|
+
*/
|
|
24
|
+
declare const SERVICE_TIERS: readonly ["standard", "batch", "flex", "priority"];
|
|
25
|
+
/** A response service tier. */
|
|
26
|
+
type ServiceTier = (typeof SERVICE_TIERS)[number];
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @fileoverview Catalog of the AI providers this library recognizes out of the
|
|
30
|
+
* box. Custom OpenAI-compatible providers register their own id at runtime via
|
|
31
|
+
* `providerPresets.openaiCompatible(id)`, so the public {@link ProviderId} type
|
|
32
|
+
* (see `types/catalogs.ts`) widens this closed list with `(string & {})`.
|
|
33
|
+
* @layer shared
|
|
34
|
+
*/
|
|
35
|
+
/**
|
|
36
|
+
* The provider identifiers shipped with the library. Frozen tuple so the derived
|
|
37
|
+
* {@link KnownProviderId} union stays in sync with the runtime values.
|
|
38
|
+
*/
|
|
39
|
+
declare const PROVIDER_IDS: readonly ["openai", "azure-openai", "anthropic", "gemini", "vertex", "mistral", "bedrock", "openrouter", "deepseek", "xai", "groq"];
|
|
40
|
+
/** A provider id known to the library at build time (excludes custom ids). */
|
|
41
|
+
type KnownProviderId = (typeof PROVIDER_IDS)[number];
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @fileoverview Canonical catalog types that the rest of the library is generic
|
|
45
|
+
* over: provider/operation/tier unions, the metering scope, the rating mode, and
|
|
46
|
+
* the pure normalizer/preset contracts. Framework-free.
|
|
47
|
+
* @layer shared
|
|
48
|
+
*/
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* A provider identifier. Widened with `(string & {})` so custom
|
|
52
|
+
* OpenAI-compatible providers can register their own id while known ids keep
|
|
53
|
+
* editor autocomplete.
|
|
54
|
+
*/
|
|
55
|
+
type ProviderId = KnownProviderId | (string & {});
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* @fileoverview The effective-dated price row and its insert type. Rates are
|
|
59
|
+
* integer nano-USD per 1,000,000 tokens (or per unit for non-token line items),
|
|
60
|
+
* so every cost computation is exact integer math.
|
|
61
|
+
* @layer shared
|
|
62
|
+
*/
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* One immutable, effective-dated price version for a (provider, model, operation,
|
|
66
|
+
* serviceTier) tuple. A call is rated at the row in effect at its timestamp.
|
|
67
|
+
*/
|
|
68
|
+
interface PriceVersion {
|
|
69
|
+
id: string;
|
|
70
|
+
provider: ProviderId;
|
|
71
|
+
model: string;
|
|
72
|
+
operation: AiOperation;
|
|
73
|
+
/** Part of the resolution key; `'standard'` is the default. */
|
|
74
|
+
serviceTier: ServiceTier;
|
|
75
|
+
/** Rates as integer nano-USD per 1,000,000 tokens. */
|
|
76
|
+
inputNanoUsdPerMillion: bigint;
|
|
77
|
+
outputNanoUsdPerMillion: bigint;
|
|
78
|
+
cacheReadNanoUsdPerMillion: bigint;
|
|
79
|
+
cacheWrite5mNanoUsdPerMillion: bigint;
|
|
80
|
+
cacheWrite1hNanoUsdPerMillion: bigint;
|
|
81
|
+
/** Usually equals output; kept separate for models that price reasoning differently. */
|
|
82
|
+
reasoningNanoUsdPerMillion: bigint;
|
|
83
|
+
audioInNanoUsdPerMillion: bigint;
|
|
84
|
+
audioOutNanoUsdPerMillion: bigint;
|
|
85
|
+
imageInNanoUsdPerMillion: bigint;
|
|
86
|
+
imageOutNanoUsdPerMillion: bigint;
|
|
87
|
+
/**
|
|
88
|
+
* Long-context tier threshold: when total input (all input-side categories)
|
|
89
|
+
* exceeds this, the tier rates replace the base input/output rates for the
|
|
90
|
+
* WHOLE call (all-or-nothing, matching Gemini's billing).
|
|
91
|
+
*/
|
|
92
|
+
tierThresholdTokens?: number;
|
|
93
|
+
tierInputNanoUsdPerMillion?: bigint;
|
|
94
|
+
tierOutputNanoUsdPerMillion?: bigint;
|
|
95
|
+
/**
|
|
96
|
+
* Non-token line items in nano-USD PER UNIT, matched against
|
|
97
|
+
* `NormalizedUsage.serverToolUse` / `MeteringContext.extraUnits` by EXACT key —
|
|
98
|
+
* so the key must equal the count key the normalizer emits (e.g. Anthropic's
|
|
99
|
+
* `usage.server_tool_use.web_search_requests`) — e.g.
|
|
100
|
+
* `{ web_search_requests: 10_000_000n }` ($0.01 per web-search call).
|
|
101
|
+
*/
|
|
102
|
+
unitRates?: Record<string, bigint>;
|
|
103
|
+
currency: 'USD';
|
|
104
|
+
effectiveFrom: Date;
|
|
105
|
+
/** `null` = current; set when a newer row supersedes it. */
|
|
106
|
+
effectiveTo: Date | null;
|
|
107
|
+
/** Provenance: `'snapshot' | 'manual' | 'import'`. */
|
|
108
|
+
source: string;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* @fileoverview Pinned per-model price snapshot in bigint nano-USD per 1,000,000
|
|
113
|
+
* tokens (unit rates are per unit). Converted offline from published provider
|
|
114
|
+
* pricing (methodology mirrors LiteLLM's `model_prices_and_context_window.json`,
|
|
115
|
+
* see `scripts/convert-litellm-prices.mjs`). Snapshot date: 2026-07. Pinning
|
|
116
|
+
* keeps rates point-in-time stable; hosts add or override models via
|
|
117
|
+
* `PricingService.upsertPrice()`. Data only — the exported array carries no
|
|
118
|
+
* behavior. Each row's `source` is `'snapshot'`; rates flagged `VERIFY` should be
|
|
119
|
+
* spot-checked against the provider's pricing page during review.
|
|
120
|
+
* @layer prices
|
|
121
|
+
*/
|
|
122
|
+
|
|
123
|
+
/** A seed price row: a {@link PriceVersion} without the store-assigned identity/effective-date fields. */
|
|
124
|
+
type SeedPriceRow = Omit<PriceVersion, 'id' | 'effectiveFrom' | 'effectiveTo'>;
|
|
125
|
+
/**
|
|
126
|
+
* The pinned price snapshot. Rated at published standard-tier prices unless the
|
|
127
|
+
* row's `serviceTier` says otherwise; batch rows are ~50% of standard.
|
|
128
|
+
*/
|
|
129
|
+
declare const MODEL_PRICES_SEED: readonly SeedPriceRow[];
|
|
130
|
+
|
|
131
|
+
export { MODEL_PRICES_SEED, type SeedPriceRow };
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Catalog of AI operation kinds a usage record can describe. The
|
|
3
|
+
* operation is part of the price-resolution key; `'responses'` bills identically
|
|
4
|
+
* to `'chat'` and shares its price rows (see spec §5.1).
|
|
5
|
+
* @layer shared
|
|
6
|
+
*/
|
|
7
|
+
/** Every operation kind the library can meter and price. */
|
|
8
|
+
declare const AI_OPERATIONS: readonly ["chat", "responses", "embeddings", "image", "video", "audio", "rerank", "moderation"];
|
|
9
|
+
/** A logical AI operation kind. */
|
|
10
|
+
type AiOperation = (typeof AI_OPERATIONS)[number];
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @fileoverview Catalog of response service tiers. Providers may silently
|
|
14
|
+
* downgrade a request (OpenAI returns `service_tier: "default"` when priority
|
|
15
|
+
* capacity is exhausted), so pricing keys off the tier reported in the RESPONSE,
|
|
16
|
+
* which is what the normalizers read (see spec §5.1).
|
|
17
|
+
* @layer shared
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* Service tier of the actual response. `'batch'` is the Batch API (~50% discount);
|
|
21
|
+
* `'flex'` is OpenAI flex processing (batch rates, synchronous); `'priority'` is
|
|
22
|
+
* paid premium; `'standard'` is the default.
|
|
23
|
+
*/
|
|
24
|
+
declare const SERVICE_TIERS: readonly ["standard", "batch", "flex", "priority"];
|
|
25
|
+
/** A response service tier. */
|
|
26
|
+
type ServiceTier = (typeof SERVICE_TIERS)[number];
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @fileoverview Catalog of the AI providers this library recognizes out of the
|
|
30
|
+
* box. Custom OpenAI-compatible providers register their own id at runtime via
|
|
31
|
+
* `providerPresets.openaiCompatible(id)`, so the public {@link ProviderId} type
|
|
32
|
+
* (see `types/catalogs.ts`) widens this closed list with `(string & {})`.
|
|
33
|
+
* @layer shared
|
|
34
|
+
*/
|
|
35
|
+
/**
|
|
36
|
+
* The provider identifiers shipped with the library. Frozen tuple so the derived
|
|
37
|
+
* {@link KnownProviderId} union stays in sync with the runtime values.
|
|
38
|
+
*/
|
|
39
|
+
declare const PROVIDER_IDS: readonly ["openai", "azure-openai", "anthropic", "gemini", "vertex", "mistral", "bedrock", "openrouter", "deepseek", "xai", "groq"];
|
|
40
|
+
/** A provider id known to the library at build time (excludes custom ids). */
|
|
41
|
+
type KnownProviderId = (typeof PROVIDER_IDS)[number];
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @fileoverview Canonical catalog types that the rest of the library is generic
|
|
45
|
+
* over: provider/operation/tier unions, the metering scope, the rating mode, and
|
|
46
|
+
* the pure normalizer/preset contracts. Framework-free.
|
|
47
|
+
* @layer shared
|
|
48
|
+
*/
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* A provider identifier. Widened with `(string & {})` so custom
|
|
52
|
+
* OpenAI-compatible providers can register their own id while known ids keep
|
|
53
|
+
* editor autocomplete.
|
|
54
|
+
*/
|
|
55
|
+
type ProviderId = KnownProviderId | (string & {});
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* @fileoverview The effective-dated price row and its insert type. Rates are
|
|
59
|
+
* integer nano-USD per 1,000,000 tokens (or per unit for non-token line items),
|
|
60
|
+
* so every cost computation is exact integer math.
|
|
61
|
+
* @layer shared
|
|
62
|
+
*/
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* One immutable, effective-dated price version for a (provider, model, operation,
|
|
66
|
+
* serviceTier) tuple. A call is rated at the row in effect at its timestamp.
|
|
67
|
+
*/
|
|
68
|
+
interface PriceVersion {
|
|
69
|
+
id: string;
|
|
70
|
+
provider: ProviderId;
|
|
71
|
+
model: string;
|
|
72
|
+
operation: AiOperation;
|
|
73
|
+
/** Part of the resolution key; `'standard'` is the default. */
|
|
74
|
+
serviceTier: ServiceTier;
|
|
75
|
+
/** Rates as integer nano-USD per 1,000,000 tokens. */
|
|
76
|
+
inputNanoUsdPerMillion: bigint;
|
|
77
|
+
outputNanoUsdPerMillion: bigint;
|
|
78
|
+
cacheReadNanoUsdPerMillion: bigint;
|
|
79
|
+
cacheWrite5mNanoUsdPerMillion: bigint;
|
|
80
|
+
cacheWrite1hNanoUsdPerMillion: bigint;
|
|
81
|
+
/** Usually equals output; kept separate for models that price reasoning differently. */
|
|
82
|
+
reasoningNanoUsdPerMillion: bigint;
|
|
83
|
+
audioInNanoUsdPerMillion: bigint;
|
|
84
|
+
audioOutNanoUsdPerMillion: bigint;
|
|
85
|
+
imageInNanoUsdPerMillion: bigint;
|
|
86
|
+
imageOutNanoUsdPerMillion: bigint;
|
|
87
|
+
/**
|
|
88
|
+
* Long-context tier threshold: when total input (all input-side categories)
|
|
89
|
+
* exceeds this, the tier rates replace the base input/output rates for the
|
|
90
|
+
* WHOLE call (all-or-nothing, matching Gemini's billing).
|
|
91
|
+
*/
|
|
92
|
+
tierThresholdTokens?: number;
|
|
93
|
+
tierInputNanoUsdPerMillion?: bigint;
|
|
94
|
+
tierOutputNanoUsdPerMillion?: bigint;
|
|
95
|
+
/**
|
|
96
|
+
* Non-token line items in nano-USD PER UNIT, matched against
|
|
97
|
+
* `NormalizedUsage.serverToolUse` / `MeteringContext.extraUnits` by EXACT key —
|
|
98
|
+
* so the key must equal the count key the normalizer emits (e.g. Anthropic's
|
|
99
|
+
* `usage.server_tool_use.web_search_requests`) — e.g.
|
|
100
|
+
* `{ web_search_requests: 10_000_000n }` ($0.01 per web-search call).
|
|
101
|
+
*/
|
|
102
|
+
unitRates?: Record<string, bigint>;
|
|
103
|
+
currency: 'USD';
|
|
104
|
+
effectiveFrom: Date;
|
|
105
|
+
/** `null` = current; set when a newer row supersedes it. */
|
|
106
|
+
effectiveTo: Date | null;
|
|
107
|
+
/** Provenance: `'snapshot' | 'manual' | 'import'`. */
|
|
108
|
+
source: string;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* @fileoverview Pinned per-model price snapshot in bigint nano-USD per 1,000,000
|
|
113
|
+
* tokens (unit rates are per unit). Converted offline from published provider
|
|
114
|
+
* pricing (methodology mirrors LiteLLM's `model_prices_and_context_window.json`,
|
|
115
|
+
* see `scripts/convert-litellm-prices.mjs`). Snapshot date: 2026-07. Pinning
|
|
116
|
+
* keeps rates point-in-time stable; hosts add or override models via
|
|
117
|
+
* `PricingService.upsertPrice()`. Data only — the exported array carries no
|
|
118
|
+
* behavior. Each row's `source` is `'snapshot'`; rates flagged `VERIFY` should be
|
|
119
|
+
* spot-checked against the provider's pricing page during review.
|
|
120
|
+
* @layer prices
|
|
121
|
+
*/
|
|
122
|
+
|
|
123
|
+
/** A seed price row: a {@link PriceVersion} without the store-assigned identity/effective-date fields. */
|
|
124
|
+
type SeedPriceRow = Omit<PriceVersion, 'id' | 'effectiveFrom' | 'effectiveTo'>;
|
|
125
|
+
/**
|
|
126
|
+
* The pinned price snapshot. Rated at published standard-tier prices unless the
|
|
127
|
+
* row's `serviceTier` says otherwise; batch rows are ~50% of standard.
|
|
128
|
+
*/
|
|
129
|
+
declare const MODEL_PRICES_SEED: readonly SeedPriceRow[];
|
|
130
|
+
|
|
131
|
+
export { MODEL_PRICES_SEED, type SeedPriceRow };
|