@pydantic/genai-prices 0.0.49 → 0.0.50

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/index.d.cts CHANGED
@@ -131,9 +131,13 @@ export declare interface Tier {
131
131
  start: number;
132
132
  }
133
133
 
134
- export declare interface TieredPrices {
134
+ export declare class TieredPrices {
135
135
  base: number;
136
136
  tiers: Tier[];
137
+ constructor(data: {
138
+ base: number;
139
+ tiers: Tier[];
140
+ });
137
141
  }
138
142
 
139
143
  export declare interface TimeOfDateConstraint {
package/dist/index.d.ts CHANGED
@@ -131,9 +131,13 @@ export declare interface Tier {
131
131
  start: number;
132
132
  }
133
133
 
134
- export declare interface TieredPrices {
134
+ export declare class TieredPrices {
135
135
  base: number;
136
136
  tiers: Tier[];
137
+ constructor(data: {
138
+ base: number;
139
+ tiers: Tier[];
140
+ });
137
141
  }
138
142
 
139
143
  export declare interface TimeOfDateConstraint {
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- const x = [
1
+ const B = [
2
2
  {
3
3
  id: "anthropic",
4
4
  name: "Anthropic",
@@ -3238,6 +3238,51 @@ Compared to other leading proprietary and open-weights models Command A delivers
3238
3238
  }
3239
3239
  }
3240
3240
  },
3241
+ {
3242
+ id: "gemini-3-flash-preview",
3243
+ name: "Gemini 3 Flash Preview",
3244
+ description: "Google's ultra-fast frontier model optimized for speed and efficiency. Delivers state-of-the-art performance while maintaining low latency and cost, with improved reasoning and coding capabilities.",
3245
+ match: {
3246
+ or: [
3247
+ {
3248
+ equals: "gemini-3-flash-preview"
3249
+ },
3250
+ {
3251
+ starts_with: "gemini-3-flash-preview-"
3252
+ }
3253
+ ]
3254
+ },
3255
+ context_window: 1e6,
3256
+ price_comments: "See https://ai.google.dev/gemini-api/docs/pricing. Standard pricing shown; Batch API offers 50% discount on input/output.",
3257
+ prices: {
3258
+ input_mtok: 0.5,
3259
+ cache_read_mtok: 0.05,
3260
+ output_mtok: 3,
3261
+ input_audio_mtok: 1,
3262
+ cache_audio_read_mtok: 0.1
3263
+ }
3264
+ },
3265
+ {
3266
+ id: "gemini-3-pro-image-preview",
3267
+ name: "Gemini 3 Pro Image Preview",
3268
+ description: "Google's image generation model optimized for high-quality image generation. Supports 1K/2K and 4K resolution outputs with flexible pricing based on image dimensions.",
3269
+ match: {
3270
+ or: [
3271
+ {
3272
+ starts_with: "gemini-3-pro-image-preview"
3273
+ },
3274
+ {
3275
+ equals: "gemini-3-pro-image-preview"
3276
+ }
3277
+ ]
3278
+ },
3279
+ context_window: 1e6,
3280
+ price_comments: "See https://ai.google.dev/gemini-api/docs/pricing#gemini-3-pro-image. Image output is priced at $120 per 1M tokens, with each 1K/2K image = 1120 tokens = $0.134/image and each 4K image = 2000 tokens = $0.24/image.",
3281
+ prices: {
3282
+ input_mtok: 2,
3283
+ output_mtok: 120
3284
+ }
3285
+ },
3241
3286
  {
3242
3287
  id: "gemini-3-pro-preview",
3243
3288
  name: "Gemini 3 Pro Preview",
@@ -3248,7 +3293,7 @@ Compared to other leading proprietary and open-weights models Command A delivers
3248
3293
  starts_with: "gemini-3-pro-preview"
3249
3294
  },
3250
3295
  {
3251
- starts_with: "gemini-3-pro-image-preview"
3296
+ equals: "gemini-3-pro-text-preview"
3252
3297
  }
3253
3298
  ]
3254
3299
  },
@@ -17537,49 +17582,114 @@ Compared to other leading proprietary and open-weights models Command A delivers
17537
17582
  cache_read_mtok: 0.75,
17538
17583
  output_mtok: 15
17539
17584
  }
17585
+ },
17586
+ {
17587
+ id: "grok-4-1-fast-non-reasoning",
17588
+ name: "Grok 4.1 Fast Non-Reasoning",
17589
+ description: "A frontier multimodal model optimized specifically for high-performance agentic tool calling.",
17590
+ match: {
17591
+ or: [
17592
+ {
17593
+ equals: "grok-4-1-fast-non-reasoning"
17594
+ },
17595
+ {
17596
+ equals: "grok-4-1-fast-non-reasoning-latest"
17597
+ }
17598
+ ]
17599
+ },
17600
+ context_window: 2e6,
17601
+ prices: {
17602
+ input_mtok: 0.2,
17603
+ cache_read_mtok: 0.05,
17604
+ output_mtok: 0.5
17605
+ }
17606
+ },
17607
+ {
17608
+ id: "grok-4-1-fast-reasoning",
17609
+ name: "Grok 4.1 Fast Reasoning",
17610
+ description: "A frontier multimodal model optimized specifically for high-performance agentic tool calling.",
17611
+ match: {
17612
+ or: [
17613
+ {
17614
+ equals: "grok-4-1-fast"
17615
+ },
17616
+ {
17617
+ equals: "grok-4-1-fast-reasoning"
17618
+ },
17619
+ {
17620
+ equals: "grok-4-1-fast-reasoning-latest"
17621
+ }
17622
+ ]
17623
+ },
17624
+ context_window: 2e6,
17625
+ prices: {
17626
+ input_mtok: 0.2,
17627
+ cache_read_mtok: 0.05,
17628
+ output_mtok: 0.5
17629
+ }
17630
+ },
17631
+ {
17632
+ id: "grok-code-fast-1",
17633
+ name: "Grok Code Fast 1",
17634
+ description: "A speedy and economical reasoning model that excels at agentic coding.",
17635
+ match: {
17636
+ or: [
17637
+ {
17638
+ equals: "grok-code-fast"
17639
+ },
17640
+ {
17641
+ equals: "grok-code-fast-1"
17642
+ },
17643
+ {
17644
+ equals: "grok-code-fast-1-0825"
17645
+ }
17646
+ ]
17647
+ },
17648
+ context_window: 256e3,
17649
+ prices: {
17650
+ input_mtok: 0.2,
17651
+ cache_read_mtok: 0.02,
17652
+ output_mtok: 1.5
17653
+ }
17540
17654
  }
17541
17655
  ]
17542
17656
  }
17543
17657
  ];
17544
- function M(t, e) {
17658
+ function y(t, e, a) {
17545
17659
  if (e <= 0) return 0;
17546
- let a = 0;
17547
- const i = [...t.tiers].sort((m, n) => m.start - n.start), o = i[0]?.start ?? e, r = Math.min(e, o);
17548
- a += r * t.base / 1e6;
17549
- for (let m = 0; m < i.length; m++) {
17550
- const n = i[m], s = i[m + 1]?.start ?? 1 / 0, u = Math.max(0, Math.min(e, s) - n.start);
17551
- u > 0 && (a += u * n.price / 1e6);
17552
- }
17553
- return a;
17660
+ let i = t.base;
17661
+ for (const o of t.tiers)
17662
+ a > o.start && (i = o.price);
17663
+ return i * e / 1e6;
17554
17664
  }
17555
- function c(t, e, a) {
17556
- return t === void 0 || e === void 0 ? 0 : typeof t == "number" ? t * e / 1e6 : M(t, e);
17665
+ function c(t, e, a, i) {
17666
+ return t === void 0 || e === void 0 ? 0 : typeof t == "number" ? t * e / 1e6 : y(t, e, i);
17557
17667
  }
17558
17668
  function L(t, e) {
17559
17669
  let a = 0, i = 0;
17560
- const o = t.cache_read_tokens ?? 0, r = t.cache_write_tokens ?? 0, m = t.cache_audio_read_tokens ?? 0, n = t.output_audio_tokens ?? 0;
17561
- let s = t.input_audio_tokens ?? 0;
17562
- if (s -= m, s < 0)
17670
+ const o = t.input_tokens ?? 0, r = t.cache_read_tokens ?? 0, u = t.cache_write_tokens ?? 0, n = t.cache_audio_read_tokens ?? 0, s = t.output_audio_tokens ?? 0;
17671
+ let m = t.input_audio_tokens ?? 0;
17672
+ if (m -= n, m < 0)
17563
17673
  throw new Error("cache_audio_read_tokens cannot be greater than input_audio_tokens");
17564
- let u = t.input_tokens ?? 0;
17565
- if (u -= o, u -= r, u -= s, u < 0)
17674
+ let p = t.input_tokens ?? 0;
17675
+ if (p -= r, p -= u, p -= m, p < 0)
17566
17676
  throw new Error("Uncached text input tokens cannot be negative");
17567
- let p = o;
17568
- if (p -= m, p < 0)
17569
- throw new Error("cache_audio_read_tokens cannot be greater than cache_read_tokens");
17570
- a += c(e.input_mtok, u), a += c(e.cache_read_mtok, p), a += c(e.cache_write_mtok, r), a += c(e.input_audio_mtok, s), a += c(e.cache_audio_read_mtok, m);
17571
- let k = t.output_tokens ?? 0;
17677
+ let k = r;
17572
17678
  if (k -= n, k < 0)
17679
+ throw new Error("cache_audio_read_tokens cannot be greater than cache_read_tokens");
17680
+ a += c(e.input_mtok, p, "input_mtok", o), a += c(e.cache_read_mtok, k, "cache_read_mtok", o), a += c(e.cache_write_mtok, u, "cache_write_mtok", o), a += c(e.input_audio_mtok, m, "input_audio_mtok", o), a += c(e.cache_audio_read_mtok, n, "cache_audio_read_mtok", o);
17681
+ let q = t.output_tokens ?? 0;
17682
+ if (q -= s, q < 0)
17573
17683
  throw new Error("output_audio_tokens cannot be greater than output_tokens");
17574
- i += c(e.output_mtok, k), i += c(e.output_audio_mtok, t.output_audio_tokens);
17575
- let f = a + i;
17576
- return e.requests_kcount !== void 0 && (f += e.requests_kcount / 1e3), {
17684
+ i += c(e.output_mtok, q, "output_mtok", o), i += c(e.output_audio_mtok, t.output_audio_tokens, "output_audio_mtok", o);
17685
+ let v = a + i;
17686
+ return e.requests_kcount !== void 0 && (v += e.requests_kcount / 1e3), {
17577
17687
  input_price: a,
17578
17688
  output_price: i,
17579
- total_price: f
17689
+ total_price: v
17580
17690
  };
17581
17691
  }
17582
- function y(t, e) {
17692
+ function Q(t, e) {
17583
17693
  if (!Array.isArray(t.prices))
17584
17694
  return t.prices;
17585
17695
  for (let a = t.prices.length - 1; a >= 0; a--) {
@@ -17590,11 +17700,11 @@ function y(t, e) {
17590
17700
  if (e >= new Date(o.start_date))
17591
17701
  return i.prices;
17592
17702
  } else {
17593
- const r = e.toISOString().slice(11, 19), m = o.start_time, n = o.end_time;
17594
- if (n < m) {
17595
- if (r >= m || r < n)
17703
+ const r = e.toISOString().slice(11, 19), u = o.start_time, n = o.end_time;
17704
+ if (n < u) {
17705
+ if (r >= u || r < n)
17596
17706
  return i.prices;
17597
- } else if (r >= m && r < n)
17707
+ } else if (r >= u && r < n)
17598
17708
  return i.prices;
17599
17709
  }
17600
17710
  }
@@ -17603,48 +17713,48 @@ function y(t, e) {
17603
17713
  function _(t, e) {
17604
17714
  return "or" in t ? t.or.some((a) => _(a, e)) : "and" in t ? t.and.every((a) => _(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;
17605
17715
  }
17606
- function Q(t, e) {
17716
+ function T(t, e) {
17607
17717
  const a = e.toLowerCase().trim(), i = t.find((o) => o.id === a);
17608
17718
  return i || t.find((o) => o.provider_match && _(o.provider_match, a));
17609
17719
  }
17610
- function B(t, { modelId: e, providerApiUrl: a, providerId: i }) {
17720
+ function I(t, { modelId: e, providerApiUrl: a, providerId: i }) {
17611
17721
  if (i)
17612
- return Q(t, i);
17722
+ return T(t, i);
17613
17723
  if (a)
17614
17724
  return t.find((o) => new RegExp(o.api_pattern).test(a));
17615
17725
  if (e)
17616
17726
  return t.find((o) => o.model_match && _(o.model_match, e));
17617
17727
  }
17618
- function T(t, e) {
17728
+ function P(t, e) {
17619
17729
  return t.find((a) => _(a.match, e));
17620
17730
  }
17621
- const P = "https://raw.githubusercontent.com/pydantic/genai-prices/main/prices/data.json";
17622
- let g = x, w = Promise.resolve(x), b = null;
17623
- function S(t) {
17624
- t !== null && ("then" in t ? (w = t, t.then((e) => {
17731
+ const S = "https://raw.githubusercontent.com/pydantic/genai-prices/main/prices/data.json";
17732
+ let g = B, b = Promise.resolve(B), f = null;
17733
+ function A(t) {
17734
+ t !== null && ("then" in t ? (b = t, t.then((e) => {
17625
17735
  e !== null && (g = e);
17626
- })) : (w = Promise.resolve(t), g = t));
17736
+ })) : (b = Promise.resolve(t), g = t));
17627
17737
  }
17628
- function A(t) {
17629
- b = t;
17738
+ function G(t) {
17739
+ f = t;
17630
17740
  }
17631
17741
  function C(t) {
17632
17742
  t({
17633
- onCalc: A,
17634
- remoteDataUrl: P,
17635
- setProviderData: S
17743
+ onCalc: G,
17744
+ remoteDataUrl: S,
17745
+ setProviderData: A
17636
17746
  });
17637
17747
  }
17638
- function z() {
17639
- return w;
17748
+ function N() {
17749
+ return b;
17640
17750
  }
17641
- function N(t, e, a) {
17642
- b?.();
17643
- const i = e.toLowerCase().trim(), o = a?.provider ?? B(g, { modelId: i, providerApiUrl: a?.providerApiUrl, providerId: a?.providerId });
17751
+ function V(t, e, a) {
17752
+ f?.();
17753
+ const i = e.toLowerCase().trim(), o = a?.provider ?? I(g, { modelId: i, providerApiUrl: a?.providerApiUrl, providerId: a?.providerId });
17644
17754
  if (!o) return null;
17645
- const r = T(o.models, i);
17755
+ const r = P(o.models, i);
17646
17756
  if (!r) return null;
17647
- const m = a?.timestamp ?? /* @__PURE__ */ new Date(), n = y(r, m), s = L(t, n);
17757
+ const u = a?.timestamp ?? /* @__PURE__ */ new Date(), n = Q(r, u), s = L(t, n);
17648
17758
  return {
17649
17759
  auto_update_timestamp: void 0,
17650
17760
  model: r,
@@ -17653,42 +17763,42 @@ function N(t, e, a) {
17653
17763
  ...s
17654
17764
  };
17655
17765
  }
17656
- function V(t) {
17657
- return b?.(), B(g, t);
17766
+ function E(t) {
17767
+ return f?.(), I(g, t);
17658
17768
  }
17659
- function E(t, e, a) {
17769
+ function O(t, e, a) {
17660
17770
  if (a = a ?? "default", !t.extractors)
17661
17771
  throw new Error("No extraction logic defined for this provider");
17662
17772
  const i = t.extractors.find((s) => s.api_flavor === a);
17663
17773
  if (!i) {
17664
- const s = t.extractors.map((u) => u.api_flavor).join(", ");
17774
+ const s = t.extractors.map((m) => m.api_flavor).join(", ");
17665
17775
  throw new Error(`Unknown apiFlavor '${a}', allowed values: ${s}`);
17666
17776
  }
17667
17777
  if (!h.guard(e))
17668
17778
  throw new Error(`Expected response data to be a mapping object, got ${l(e)}`);
17669
- const o = q(i.model_path, e, R, !1, []), r = I(i.root), m = q(r, e, h, !0, []), n = {};
17779
+ const o = w(i.model_path, e, D, !1, []), r = M(i.root), u = w(r, e, h, !0, []), n = {};
17670
17780
  for (const s of i.mappings) {
17671
- const u = q(s.path, m, D, s.required, r);
17672
- if (u !== null) {
17781
+ const m = w(s.path, u, z, s.required, r);
17782
+ if (m !== null) {
17673
17783
  const p = n[s.dest] ?? 0;
17674
- n[s.dest] = p + u;
17784
+ n[s.dest] = p + m;
17675
17785
  }
17676
17786
  }
17677
17787
  if (!Object.keys(n).length)
17678
17788
  throw new Error(`No usage information found at ${JSON.stringify(i.root)}`);
17679
17789
  return { model: o, usage: n };
17680
17790
  }
17681
- function q(t, e, a, i, o) {
17682
- const [r, ...m] = I(t).reverse();
17791
+ function w(t, e, a, i, o) {
17792
+ const [r, ...u] = M(t).reverse();
17683
17793
  if (typeof r != "string")
17684
17794
  throw new Error(`Expected last step of path to be a string, got ${l(r)}`);
17685
- m.reverse();
17795
+ u.reverse();
17686
17796
  let n = e;
17687
17797
  const s = [];
17688
- for (const p of m) {
17798
+ for (const p of u) {
17689
17799
  if (s.push(p), typeof p == "object")
17690
17800
  if (Array.isArray(n))
17691
- n = G(p, n);
17801
+ n = R(p, n);
17692
17802
  else {
17693
17803
  if (i)
17694
17804
  throw new Error(`Expected \`${d(o, s)}\` value to be a mapping, got ${l(n)}`);
@@ -17713,19 +17823,19 @@ function q(t, e, a, i, o) {
17713
17823
  throw new Error(`Expected \`${d(o, s)}\` value to be a mapping, got ${l(n)}`);
17714
17824
  return null;
17715
17825
  }
17716
- const u = n[r];
17717
- if (typeof u > "u") {
17826
+ const m = n[r];
17827
+ if (typeof m > "u") {
17718
17828
  if (i)
17719
17829
  throw s.push(r), new Error(`Missing value at \`${d(o, s)}\``);
17720
17830
  return null;
17721
17831
  }
17722
- if (a.guard(u))
17723
- return u;
17832
+ if (a.guard(m))
17833
+ return m;
17724
17834
  if (i)
17725
- throw s.push(r), new Error(`Expected \`${d(o, s)}\` value to be a ${a.name}, got ${l(u)}`);
17835
+ throw s.push(r), new Error(`Expected \`${d(o, s)}\` value to be a ${a.name}, got ${l(m)}`);
17726
17836
  return null;
17727
17837
  }
17728
- function G(t, e) {
17838
+ function R(t, e) {
17729
17839
  for (const a of e)
17730
17840
  if (h.guard(a)) {
17731
17841
  const i = a[t.field];
@@ -17733,7 +17843,7 @@ function G(t, e) {
17733
17843
  return a;
17734
17844
  }
17735
17845
  }
17736
- function I(t) {
17846
+ function M(t) {
17737
17847
  return Array.isArray(t) ? [...t] : [t];
17738
17848
  }
17739
17849
  function l(t) {
@@ -17742,18 +17852,26 @@ function l(t) {
17742
17852
  const h = {
17743
17853
  guard: (t) => l(t) === "mapping",
17744
17854
  name: "mapping"
17745
- }, R = {
17855
+ }, D = {
17746
17856
  guard: (t) => typeof t == "string",
17747
17857
  name: "string"
17748
- }, D = {
17858
+ }, z = {
17749
17859
  guard: (t) => typeof t == "number",
17750
17860
  name: "number"
17751
- }, d = (t, e) => [...t.map(v), ...e.map(v)].join("."), v = (t) => typeof t == "string" ? t : JSON.stringify(t);
17861
+ }, d = (t, e) => [...t.map(x), ...e.map(x)].join("."), x = (t) => typeof t == "string" ? t : JSON.stringify(t);
17862
+ class F {
17863
+ base;
17864
+ tiers;
17865
+ constructor(e) {
17866
+ this.base = e.base, this.tiers = [...e.tiers].sort((a, i) => a.start - i.start);
17867
+ }
17868
+ }
17752
17869
  export {
17753
- P as REMOTE_DATA_JSON_URL,
17754
- N as calcPrice,
17755
- E as extractUsage,
17756
- V as findProvider,
17870
+ S as REMOTE_DATA_JSON_URL,
17871
+ F as TieredPrices,
17872
+ V as calcPrice,
17873
+ O as extractUsage,
17874
+ E as findProvider,
17757
17875
  C as updatePrices,
17758
- z as waitForUpdate
17876
+ N as waitForUpdate
17759
17877
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pydantic/genai-prices",
3
- "version": "0.0.49",
3
+ "version": "0.0.50",
4
4
  "description": "Calculate prices for calling LLM inference APIs",
5
5
  "author": "Pydantic Team",
6
6
  "type": "module",