@pydantic/genai-prices 0.0.34 → 0.0.36
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/dist/cli.js +209 -96
- package/dist/index.cjs +3 -3
- package/dist/index.js +211 -95
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const x = [
|
|
2
2
|
{
|
|
3
3
|
id: "anthropic",
|
|
4
4
|
name: "Anthropic",
|
|
@@ -1701,6 +1701,43 @@ Compared to other leading proprietary and open-weights models Command A delivers
|
|
|
1701
1701
|
required: !1
|
|
1702
1702
|
}
|
|
1703
1703
|
]
|
|
1704
|
+
},
|
|
1705
|
+
{
|
|
1706
|
+
api_flavor: "anthropic",
|
|
1707
|
+
root: "usage",
|
|
1708
|
+
model_path: "model",
|
|
1709
|
+
mappings: [
|
|
1710
|
+
{
|
|
1711
|
+
path: "input_tokens",
|
|
1712
|
+
dest: "input_tokens",
|
|
1713
|
+
required: !0
|
|
1714
|
+
},
|
|
1715
|
+
{
|
|
1716
|
+
path: "cache_creation_input_tokens",
|
|
1717
|
+
dest: "input_tokens",
|
|
1718
|
+
required: !1
|
|
1719
|
+
},
|
|
1720
|
+
{
|
|
1721
|
+
path: "cache_read_input_tokens",
|
|
1722
|
+
dest: "input_tokens",
|
|
1723
|
+
required: !1
|
|
1724
|
+
},
|
|
1725
|
+
{
|
|
1726
|
+
path: "cache_creation_input_tokens",
|
|
1727
|
+
dest: "cache_write_tokens",
|
|
1728
|
+
required: !1
|
|
1729
|
+
},
|
|
1730
|
+
{
|
|
1731
|
+
path: "cache_read_input_tokens",
|
|
1732
|
+
dest: "cache_read_tokens",
|
|
1733
|
+
required: !1
|
|
1734
|
+
},
|
|
1735
|
+
{
|
|
1736
|
+
path: "output_tokens",
|
|
1737
|
+
dest: "output_tokens",
|
|
1738
|
+
required: !0
|
|
1739
|
+
}
|
|
1740
|
+
]
|
|
1704
1741
|
}
|
|
1705
1742
|
],
|
|
1706
1743
|
models: [
|
|
@@ -5466,7 +5503,14 @@ Compared to other leading proprietary and open-weights models Command A delivers
|
|
|
5466
5503
|
id: "gemini-2.5-flash",
|
|
5467
5504
|
name: "Gemini 2.5 Flash",
|
|
5468
5505
|
match: {
|
|
5469
|
-
|
|
5506
|
+
or: [
|
|
5507
|
+
{
|
|
5508
|
+
equals: "gemini-2.5-flash"
|
|
5509
|
+
},
|
|
5510
|
+
{
|
|
5511
|
+
equals: "google/gemini-2.5-flash"
|
|
5512
|
+
}
|
|
5513
|
+
]
|
|
5470
5514
|
},
|
|
5471
5515
|
prices: {
|
|
5472
5516
|
input_mtok: 0.3,
|
|
@@ -5805,6 +5849,48 @@ Compared to other leading proprietary and open-weights models Command A delivers
|
|
|
5805
5849
|
},
|
|
5806
5850
|
prices: {}
|
|
5807
5851
|
},
|
|
5852
|
+
{
|
|
5853
|
+
id: "google/gemini-2.5-flash-image",
|
|
5854
|
+
name: "Gemini 2.5 Flash Image (Nano Banana)",
|
|
5855
|
+
match: {
|
|
5856
|
+
or: [
|
|
5857
|
+
{
|
|
5858
|
+
equals: "google/gemini-2.5-flash-image"
|
|
5859
|
+
},
|
|
5860
|
+
{
|
|
5861
|
+
equals: "google/gemini-2.5-flash-image-preview"
|
|
5862
|
+
}
|
|
5863
|
+
]
|
|
5864
|
+
},
|
|
5865
|
+
prices: {
|
|
5866
|
+
input_mtok: 0.3,
|
|
5867
|
+
output_mtok: 2.5
|
|
5868
|
+
}
|
|
5869
|
+
},
|
|
5870
|
+
{
|
|
5871
|
+
id: "google/gemini-2.5-flash-lite",
|
|
5872
|
+
name: "Gemini 2.5 Flash Lite",
|
|
5873
|
+
match: {
|
|
5874
|
+
equals: "google/gemini-2.5-flash-lite"
|
|
5875
|
+
},
|
|
5876
|
+
prices: {
|
|
5877
|
+
input_mtok: 0.1,
|
|
5878
|
+
cache_write_mtok: 0.183,
|
|
5879
|
+
cache_read_mtok: 0.025,
|
|
5880
|
+
output_mtok: 0.4
|
|
5881
|
+
}
|
|
5882
|
+
},
|
|
5883
|
+
{
|
|
5884
|
+
id: "google/gemini-2.5-flash-lite-preview-09-2025",
|
|
5885
|
+
name: "Gemini 2.5 Flash Lite Preview 09-2025",
|
|
5886
|
+
match: {
|
|
5887
|
+
equals: "google/gemini-2.5-flash-lite-preview-09-2025"
|
|
5888
|
+
},
|
|
5889
|
+
prices: {
|
|
5890
|
+
input_mtok: 0.1,
|
|
5891
|
+
output_mtok: 0.4
|
|
5892
|
+
}
|
|
5893
|
+
},
|
|
5808
5894
|
{
|
|
5809
5895
|
id: "google/gemini-2.5-flash-preview",
|
|
5810
5896
|
match: {
|
|
@@ -5815,6 +5901,19 @@ Compared to other leading proprietary and open-weights models Command A delivers
|
|
|
5815
5901
|
output_mtok: 0.6
|
|
5816
5902
|
}
|
|
5817
5903
|
},
|
|
5904
|
+
{
|
|
5905
|
+
id: "google/gemini-2.5-flash-preview-09-2025",
|
|
5906
|
+
name: "Gemini 2.5 Flash Preview 09-2025",
|
|
5907
|
+
match: {
|
|
5908
|
+
equals: "google/gemini-2.5-flash-preview-09-2025"
|
|
5909
|
+
},
|
|
5910
|
+
prices: {
|
|
5911
|
+
input_mtok: 0.3,
|
|
5912
|
+
cache_write_mtok: 0.383,
|
|
5913
|
+
cache_read_mtok: 0.075,
|
|
5914
|
+
output_mtok: 2.5
|
|
5915
|
+
}
|
|
5916
|
+
},
|
|
5818
5917
|
{
|
|
5819
5918
|
id: "google/gemini-2.5-flash-preview:thinking",
|
|
5820
5919
|
match: {
|
|
@@ -11033,31 +11132,45 @@ Compared to other leading proprietary and open-weights models Command A delivers
|
|
|
11033
11132
|
]
|
|
11034
11133
|
}
|
|
11035
11134
|
];
|
|
11036
|
-
function
|
|
11135
|
+
function M(t, e) {
|
|
11037
11136
|
if (e <= 0) return 0;
|
|
11038
11137
|
let a = 0;
|
|
11039
|
-
const i = [...t.tiers].sort((r, s) => r.start - s.start), o = i[0]?.start ?? e,
|
|
11040
|
-
a +=
|
|
11138
|
+
const i = [...t.tiers].sort((r, s) => r.start - s.start), o = i[0]?.start ?? e, m = Math.min(e, o);
|
|
11139
|
+
a += m * t.base / 1e6;
|
|
11041
11140
|
for (let r = 0; r < i.length; r++) {
|
|
11042
|
-
const s = i[r],
|
|
11141
|
+
const s = i[r], n = i[r + 1]?.start ?? 1 / 0, u = Math.max(0, Math.min(e, n) - s.start);
|
|
11043
11142
|
u > 0 && (a += u * s.price / 1e6);
|
|
11044
11143
|
}
|
|
11045
11144
|
return a;
|
|
11046
11145
|
}
|
|
11047
11146
|
function p(t, e, a) {
|
|
11048
|
-
return t === void 0 || e === void 0 ? 0 : typeof t == "number" ? t * e / 1e6 :
|
|
11147
|
+
return t === void 0 || e === void 0 ? 0 : typeof t == "number" ? t * e / 1e6 : M(t, e);
|
|
11049
11148
|
}
|
|
11050
|
-
function
|
|
11149
|
+
function I(t, e) {
|
|
11051
11150
|
let a = 0, i = 0;
|
|
11052
|
-
|
|
11053
|
-
|
|
11054
|
-
|
|
11151
|
+
const o = t.cache_read_tokens ?? 0, m = t.cache_write_tokens ?? 0, r = t.cache_audio_read_tokens ?? 0, s = t.output_audio_tokens ?? 0;
|
|
11152
|
+
let n = t.input_audio_tokens ?? 0;
|
|
11153
|
+
if (n -= r, n < 0)
|
|
11154
|
+
throw new Error("cache_audio_read_tokens cannot be greater than input_audio_tokens");
|
|
11155
|
+
let u = t.input_tokens ?? 0;
|
|
11156
|
+
if (u -= o, u -= m, u -= n, u < 0)
|
|
11157
|
+
throw new Error("Uncached text input tokens cannot be negative");
|
|
11158
|
+
let l = o;
|
|
11159
|
+
if (l -= r, l < 0)
|
|
11160
|
+
throw new Error("cache_audio_read_tokens cannot be greater than cache_read_tokens");
|
|
11161
|
+
a += p(e.input_mtok, u), a += p(e.cache_read_mtok, l), a += p(e.cache_write_mtok, m), a += p(e.input_audio_mtok, n), a += p(e.cache_audio_read_mtok, r);
|
|
11162
|
+
let k = t.output_tokens ?? 0;
|
|
11163
|
+
if (k -= s, k < 0)
|
|
11164
|
+
throw new Error("output_audio_tokens cannot be greater than output_tokens");
|
|
11165
|
+
i += p(e.output_mtok, k), i += p(e.output_audio_mtok, t.output_audio_tokens);
|
|
11166
|
+
let w = a + i;
|
|
11167
|
+
return e.requests_kcount !== void 0 && (w += e.requests_kcount / 1e3), {
|
|
11055
11168
|
input_price: a,
|
|
11056
11169
|
output_price: i,
|
|
11057
|
-
total_price:
|
|
11170
|
+
total_price: w
|
|
11058
11171
|
};
|
|
11059
11172
|
}
|
|
11060
|
-
function
|
|
11173
|
+
function P(t, e) {
|
|
11061
11174
|
if (!Array.isArray(t.prices))
|
|
11062
11175
|
return t.prices;
|
|
11063
11176
|
for (let a = t.prices.length - 1; a >= 0; a--) {
|
|
@@ -11068,11 +11181,11 @@ function I(t, e) {
|
|
|
11068
11181
|
if (e >= new Date(o.start_date))
|
|
11069
11182
|
return i.prices;
|
|
11070
11183
|
} else {
|
|
11071
|
-
const
|
|
11184
|
+
const m = e.toISOString().slice(11, 19), r = o.start_time, s = o.end_time;
|
|
11072
11185
|
if (s < r) {
|
|
11073
|
-
if (
|
|
11186
|
+
if (m >= r || m < s)
|
|
11074
11187
|
return i.prices;
|
|
11075
|
-
} else if (
|
|
11188
|
+
} else if (m >= r && m < s)
|
|
11076
11189
|
return i.prices;
|
|
11077
11190
|
}
|
|
11078
11191
|
}
|
|
@@ -11081,154 +11194,157 @@ function I(t, e) {
|
|
|
11081
11194
|
function h(t, e) {
|
|
11082
11195
|
return "or" in t ? t.or.some((a) => h(a, e)) : "and" in t ? t.and.every((a) => h(a, e)) : "equals" in t ? e === t.equals : "starts_with" in t ? e.startsWith(t.starts_with) : "ends_with" in t ? e.endsWith(t.ends_with) : "contains" in t ? e.includes(t.contains) : "regex" in t ? new RegExp(t.regex).test(e) : !1;
|
|
11083
11196
|
}
|
|
11084
|
-
function
|
|
11197
|
+
function L(t, e) {
|
|
11085
11198
|
const a = e.toLowerCase().trim(), i = t.find((o) => o.id === a);
|
|
11086
11199
|
return i || t.find((o) => o.provider_match && h(o.provider_match, a));
|
|
11087
11200
|
}
|
|
11088
|
-
function
|
|
11201
|
+
function B(t, { modelId: e, providerApiUrl: a, providerId: i }) {
|
|
11089
11202
|
if (i)
|
|
11090
|
-
return
|
|
11203
|
+
return L(t, i);
|
|
11091
11204
|
if (a)
|
|
11092
11205
|
return t.find((o) => new RegExp(o.api_pattern).test(a));
|
|
11093
11206
|
if (e)
|
|
11094
11207
|
return t.find((o) => o.model_match && h(o.model_match, e));
|
|
11095
11208
|
}
|
|
11096
|
-
function
|
|
11209
|
+
function T(t, e) {
|
|
11097
11210
|
return t.find((a) => h(a.match, e));
|
|
11098
11211
|
}
|
|
11099
|
-
const
|
|
11100
|
-
let
|
|
11101
|
-
function G(t) {
|
|
11102
|
-
"then" in t ? (q = t, t.then((e) => {
|
|
11103
|
-
_ = e;
|
|
11104
|
-
})) : (q = Promise.resolve(t), _ = t);
|
|
11105
|
-
}
|
|
11212
|
+
const G = "https://raw.githubusercontent.com/pydantic/genai-prices/main/prices/data.json";
|
|
11213
|
+
let g = x, b = Promise.resolve(x), f = null;
|
|
11106
11214
|
function S(t) {
|
|
11107
|
-
b = t
|
|
11215
|
+
"then" in t ? (b = t, t.then((e) => {
|
|
11216
|
+
g = e;
|
|
11217
|
+
})) : (b = Promise.resolve(t), g = t);
|
|
11218
|
+
}
|
|
11219
|
+
function A(t) {
|
|
11220
|
+
f = t;
|
|
11108
11221
|
}
|
|
11109
|
-
function
|
|
11222
|
+
function N(t) {
|
|
11110
11223
|
t({
|
|
11111
|
-
onCalc:
|
|
11112
|
-
remoteDataUrl:
|
|
11113
|
-
setProviderData:
|
|
11224
|
+
onCalc: A,
|
|
11225
|
+
remoteDataUrl: G,
|
|
11226
|
+
setProviderData: S
|
|
11114
11227
|
});
|
|
11115
11228
|
}
|
|
11116
|
-
function
|
|
11117
|
-
return
|
|
11229
|
+
function Q() {
|
|
11230
|
+
return b;
|
|
11118
11231
|
}
|
|
11119
|
-
function
|
|
11120
|
-
|
|
11121
|
-
const i = e.toLowerCase().trim(), o = a?.provider ??
|
|
11232
|
+
function E(t, e, a) {
|
|
11233
|
+
f?.();
|
|
11234
|
+
const i = e.toLowerCase().trim(), o = a?.provider ?? B(g, { modelId: i, providerApiUrl: a?.providerApiUrl, providerId: a?.providerId });
|
|
11122
11235
|
if (!o) return null;
|
|
11123
|
-
const
|
|
11124
|
-
if (!
|
|
11125
|
-
const r = a?.timestamp ?? /* @__PURE__ */ new Date(), s =
|
|
11236
|
+
const m = T(o.models, i);
|
|
11237
|
+
if (!m) return null;
|
|
11238
|
+
const r = a?.timestamp ?? /* @__PURE__ */ new Date(), s = P(m, r), n = I(t, s);
|
|
11126
11239
|
return {
|
|
11127
11240
|
auto_update_timestamp: void 0,
|
|
11128
|
-
model:
|
|
11241
|
+
model: m,
|
|
11129
11242
|
model_price: s,
|
|
11130
11243
|
provider: o,
|
|
11131
|
-
...
|
|
11244
|
+
...n
|
|
11132
11245
|
};
|
|
11133
11246
|
}
|
|
11134
|
-
function
|
|
11135
|
-
return
|
|
11247
|
+
function O(t) {
|
|
11248
|
+
return f?.(), B(g, t);
|
|
11136
11249
|
}
|
|
11137
11250
|
function D(t, e, a) {
|
|
11138
|
-
if (!t.extractors)
|
|
11251
|
+
if (a = a ?? "default", !t.extractors)
|
|
11139
11252
|
throw new Error("No extraction logic defined for this provider");
|
|
11140
|
-
|
|
11141
|
-
if (
|
|
11142
|
-
const
|
|
11143
|
-
|
|
11144
|
-
|
|
11145
|
-
|
|
11146
|
-
const u = t.extractors.map((l) => l.api_flavor).join(", ");
|
|
11147
|
-
throw new Error(`Unknown apiFlavor '${a}', allowed values: ${u}`);
|
|
11148
|
-
}
|
|
11149
|
-
} else if (t.extractors.length === 1)
|
|
11150
|
-
i = t.extractors[0];
|
|
11151
|
-
else
|
|
11152
|
-
throw new Error("No apiFlavor specified and multiple extractors available");
|
|
11153
|
-
if (!k.guard(e))
|
|
11253
|
+
const i = t.extractors.find((n) => n.api_flavor === a);
|
|
11254
|
+
if (!i) {
|
|
11255
|
+
const n = t.extractors.map((u) => u.api_flavor).join(", ");
|
|
11256
|
+
throw new Error(`Unknown apiFlavor '${a}', allowed values: ${n}`);
|
|
11257
|
+
}
|
|
11258
|
+
if (!_.guard(e))
|
|
11154
11259
|
throw new Error(`Expected response data to be a mapping object, got ${c(e)}`);
|
|
11155
|
-
const o =
|
|
11156
|
-
for (const
|
|
11157
|
-
const u =
|
|
11260
|
+
const o = q(i.model_path, e, C, !1, []), m = y(i.root), r = q(m, e, _, !0, []), s = {};
|
|
11261
|
+
for (const n of i.mappings) {
|
|
11262
|
+
const u = q(n.path, r, z, n.required, m);
|
|
11158
11263
|
if (u !== null) {
|
|
11159
|
-
const l = s[
|
|
11160
|
-
s[
|
|
11264
|
+
const l = s[n.dest] ?? 0;
|
|
11265
|
+
s[n.dest] = l + u;
|
|
11161
11266
|
}
|
|
11162
11267
|
}
|
|
11163
11268
|
if (!Object.keys(s).length)
|
|
11164
11269
|
throw new Error(`No usage information found at ${JSON.stringify(i.root)}`);
|
|
11165
11270
|
return { model: o, usage: s };
|
|
11166
11271
|
}
|
|
11167
|
-
function
|
|
11168
|
-
const [
|
|
11169
|
-
if (typeof
|
|
11170
|
-
throw new Error(`Expected last step of path to be a string, got ${c(
|
|
11272
|
+
function q(t, e, a, i, o) {
|
|
11273
|
+
const [m, ...r] = y(t).reverse();
|
|
11274
|
+
if (typeof m != "string")
|
|
11275
|
+
throw new Error(`Expected last step of path to be a string, got ${c(m)}`);
|
|
11171
11276
|
r.reverse();
|
|
11172
11277
|
let s = e;
|
|
11173
|
-
const
|
|
11278
|
+
const n = [];
|
|
11174
11279
|
for (const l of r) {
|
|
11175
|
-
if (
|
|
11280
|
+
if (n.push(l), typeof l == "object")
|
|
11176
11281
|
if (Array.isArray(s))
|
|
11177
|
-
s =
|
|
11178
|
-
else
|
|
11179
|
-
|
|
11180
|
-
|
|
11282
|
+
s = R(l, s);
|
|
11283
|
+
else {
|
|
11284
|
+
if (i)
|
|
11285
|
+
throw new Error(`Expected \`${d(o, n)}\` value to be a mapping, got ${c(s)}`);
|
|
11286
|
+
return null;
|
|
11287
|
+
}
|
|
11288
|
+
else if (_.guard(s))
|
|
11181
11289
|
s = s[l];
|
|
11182
|
-
else
|
|
11183
|
-
|
|
11290
|
+
else {
|
|
11291
|
+
if (i)
|
|
11292
|
+
throw new Error(`Expected \`${d(o, n)}\` value to be a mapping, got ${c(s)}`);
|
|
11293
|
+
return null;
|
|
11294
|
+
}
|
|
11184
11295
|
if (typeof s > "u")
|
|
11185
11296
|
if (i) {
|
|
11186
|
-
const
|
|
11187
|
-
throw new Error(`${
|
|
11297
|
+
const k = typeof l == "object" ? "Unable to find item" : "Missing value";
|
|
11298
|
+
throw new Error(`${k} at \`${d(o, n)}\``);
|
|
11188
11299
|
} else
|
|
11189
11300
|
return null;
|
|
11190
11301
|
}
|
|
11191
|
-
if (!
|
|
11192
|
-
|
|
11193
|
-
|
|
11302
|
+
if (!_.guard(s)) {
|
|
11303
|
+
if (i)
|
|
11304
|
+
throw new Error(`Expected \`${d(o, n)}\` value to be a mapping, got ${c(s)}`);
|
|
11305
|
+
return null;
|
|
11306
|
+
}
|
|
11307
|
+
const u = s[m];
|
|
11194
11308
|
if (typeof u > "u") {
|
|
11195
11309
|
if (i)
|
|
11196
|
-
throw
|
|
11310
|
+
throw n.push(m), new Error(`Missing value at \`${d(o, n)}\``);
|
|
11197
11311
|
return null;
|
|
11198
11312
|
}
|
|
11199
11313
|
if (a.guard(u))
|
|
11200
11314
|
return u;
|
|
11201
|
-
|
|
11315
|
+
if (i)
|
|
11316
|
+
throw n.push(m), new Error(`Expected \`${d(o, n)}\` value to be a ${a.name}, got ${c(u)}`);
|
|
11317
|
+
return null;
|
|
11202
11318
|
}
|
|
11203
|
-
function
|
|
11319
|
+
function R(t, e) {
|
|
11204
11320
|
for (const a of e)
|
|
11205
|
-
if (
|
|
11321
|
+
if (_.guard(a)) {
|
|
11206
11322
|
const i = a[t.field];
|
|
11207
11323
|
if (typeof i == "string" && h(t.match, i))
|
|
11208
11324
|
return a;
|
|
11209
11325
|
}
|
|
11210
11326
|
}
|
|
11211
|
-
function
|
|
11327
|
+
function y(t) {
|
|
11212
11328
|
return Array.isArray(t) ? [...t] : [t];
|
|
11213
11329
|
}
|
|
11214
11330
|
function c(t) {
|
|
11215
11331
|
return t === null ? "null" : Array.isArray(t) ? "array" : typeof t == "object" ? "mapping" : typeof t;
|
|
11216
11332
|
}
|
|
11217
|
-
const
|
|
11333
|
+
const _ = {
|
|
11218
11334
|
guard: (t) => c(t) === "mapping",
|
|
11219
11335
|
name: "mapping"
|
|
11220
|
-
},
|
|
11336
|
+
}, C = {
|
|
11221
11337
|
guard: (t) => typeof t == "string",
|
|
11222
11338
|
name: "string"
|
|
11223
|
-
},
|
|
11339
|
+
}, z = {
|
|
11224
11340
|
guard: (t) => typeof t == "number",
|
|
11225
11341
|
name: "number"
|
|
11226
|
-
}, d = (t, e) => [...t.map(
|
|
11342
|
+
}, d = (t, e) => [...t.map(v), ...e.map(v)].join("."), v = (t) => typeof t == "string" ? t : JSON.stringify(t);
|
|
11227
11343
|
export {
|
|
11228
|
-
|
|
11229
|
-
|
|
11344
|
+
G as REMOTE_DATA_JSON_URL,
|
|
11345
|
+
E as calcPrice,
|
|
11230
11346
|
D as extractUsage,
|
|
11231
|
-
|
|
11232
|
-
|
|
11233
|
-
|
|
11347
|
+
O as findProvider,
|
|
11348
|
+
N as updatePrices,
|
|
11349
|
+
Q as waitForUpdate
|
|
11234
11350
|
};
|