@blockrun/llm 3.24.4 → 3.24.5

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.cjs CHANGED
@@ -5089,7 +5089,7 @@ function getCostSummary() {
5089
5089
  }
5090
5090
 
5091
5091
  // src/version.ts
5092
- var SDK_VERSION = "3.24.4";
5092
+ var SDK_VERSION = "3.24.5";
5093
5093
  var USER_AGENT = `blockrun-ts/${SDK_VERSION}`;
5094
5094
 
5095
5095
  // src/client.ts
@@ -5157,8 +5157,15 @@ var LLMClient = class _LLMClient {
5157
5157
  modelPricingCache = null;
5158
5158
  modelPricingPromise = null;
5159
5159
  // Pre-auth cache: avoids the 402 round-trip on repeat requests to the same model.
5160
- // Key = "endpoint:model", value = cached payment header + timestamp.
5160
+ // Key = "endpoint:model", value = cached payment header + timestamp + the
5161
+ // length of the request body it was quoted for.
5161
5162
  // TTL: 1 hour — pre-auth quotes are stable server-side on that horizon.
5163
+ //
5164
+ // A quote prices ONE request (input size + max_tokens), and exact settles
5165
+ // the whole signed amount, so reusing it for a smaller request overpaid and
5166
+ // for a larger one underpaid. The gateway refuses both with a 402 (an
5167
+ // over-signed payment since blockrun#874), so a reuse is only attempted for
5168
+ // a body the same size as the one that was quoted.
5162
5169
  preAuthCache = /* @__PURE__ */ new Map();
5163
5170
  static PRE_AUTH_TTL_MS = 36e5;
5164
5171
  /**
@@ -5765,9 +5772,10 @@ var LLMClient = class _LLMClient {
5765
5772
  if (options?.responseFormat !== void 0) body.response_format = options.responseFormat;
5766
5773
  if (options?.stop !== void 0) body.stop = options.stop;
5767
5774
  const cacheKey2 = `/v1/chat/completions:${requestModel}`;
5775
+ const requestBody = JSON.stringify(body);
5768
5776
  const cached = this.preAuthCache.get(cacheKey2);
5769
5777
  const now = Date.now();
5770
- if (cached && now - cached.cachedAt < _LLMClient.PRE_AUTH_TTL_MS) {
5778
+ if (cached && now - cached.cachedAt < _LLMClient.PRE_AUTH_TTL_MS && cached.bodyLength === requestBody.length) {
5771
5779
  let signed;
5772
5780
  try {
5773
5781
  signed = await this.signPayment(cached.paymentHeader);
@@ -5836,7 +5844,7 @@ var LLMClient = class _LLMClient {
5836
5844
  }
5837
5845
  }
5838
5846
  if (!paymentHeader) throw new PaymentError("402 response but no payment requirements found");
5839
- this.preAuthCache.set(cacheKey2, { paymentHeader, cachedAt: now });
5847
+ this.preAuthCache.set(cacheKey2, { paymentHeader, cachedAt: now, bodyLength: requestBody.length });
5840
5848
  const { paymentPayload, costUsd } = await this.signPayment(paymentHeader);
5841
5849
  const streamResp = await this.fetchWithTimeout(url, {
5842
5850
  method: "POST",
package/dist/index.js CHANGED
@@ -4958,7 +4958,7 @@ function getCostSummary() {
4958
4958
  }
4959
4959
 
4960
4960
  // src/version.ts
4961
- var SDK_VERSION = "3.24.4";
4961
+ var SDK_VERSION = "3.24.5";
4962
4962
  var USER_AGENT = `blockrun-ts/${SDK_VERSION}`;
4963
4963
 
4964
4964
  // src/client.ts
@@ -5026,8 +5026,15 @@ var LLMClient = class _LLMClient {
5026
5026
  modelPricingCache = null;
5027
5027
  modelPricingPromise = null;
5028
5028
  // Pre-auth cache: avoids the 402 round-trip on repeat requests to the same model.
5029
- // Key = "endpoint:model", value = cached payment header + timestamp.
5029
+ // Key = "endpoint:model", value = cached payment header + timestamp + the
5030
+ // length of the request body it was quoted for.
5030
5031
  // TTL: 1 hour — pre-auth quotes are stable server-side on that horizon.
5032
+ //
5033
+ // A quote prices ONE request (input size + max_tokens), and exact settles
5034
+ // the whole signed amount, so reusing it for a smaller request overpaid and
5035
+ // for a larger one underpaid. The gateway refuses both with a 402 (an
5036
+ // over-signed payment since blockrun#874), so a reuse is only attempted for
5037
+ // a body the same size as the one that was quoted.
5031
5038
  preAuthCache = /* @__PURE__ */ new Map();
5032
5039
  static PRE_AUTH_TTL_MS = 36e5;
5033
5040
  /**
@@ -5634,9 +5641,10 @@ var LLMClient = class _LLMClient {
5634
5641
  if (options?.responseFormat !== void 0) body.response_format = options.responseFormat;
5635
5642
  if (options?.stop !== void 0) body.stop = options.stop;
5636
5643
  const cacheKey2 = `/v1/chat/completions:${requestModel}`;
5644
+ const requestBody = JSON.stringify(body);
5637
5645
  const cached = this.preAuthCache.get(cacheKey2);
5638
5646
  const now = Date.now();
5639
- if (cached && now - cached.cachedAt < _LLMClient.PRE_AUTH_TTL_MS) {
5647
+ if (cached && now - cached.cachedAt < _LLMClient.PRE_AUTH_TTL_MS && cached.bodyLength === requestBody.length) {
5640
5648
  let signed;
5641
5649
  try {
5642
5650
  signed = await this.signPayment(cached.paymentHeader);
@@ -5705,7 +5713,7 @@ var LLMClient = class _LLMClient {
5705
5713
  }
5706
5714
  }
5707
5715
  if (!paymentHeader) throw new PaymentError("402 response but no payment requirements found");
5708
- this.preAuthCache.set(cacheKey2, { paymentHeader, cachedAt: now });
5716
+ this.preAuthCache.set(cacheKey2, { paymentHeader, cachedAt: now, bodyLength: requestBody.length });
5709
5717
  const { paymentPayload, costUsd } = await this.signPayment(paymentHeader);
5710
5718
  const streamResp = await this.fetchWithTimeout(url, {
5711
5719
  method: "POST",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blockrun/llm",
3
- "version": "3.24.4",
3
+ "version": "3.24.5",
4
4
  "type": "module",
5
5
  "description": "TypeScript SDK for BlockRun - every frontier model behind one OpenAI-compatible client. Pay with a BlockRun API key or per-call in USDC. Smart routing picks the cheapest capable model. No rate limits.",
6
6
  "main": "dist/index.cjs",