@broberg/ai-sdk 0.74.0 → 0.74.1

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.ts CHANGED
@@ -1280,6 +1280,7 @@ declare function geminiAdapter(config?: {
1280
1280
  declare function deepinfraAdapter(config?: {
1281
1281
  apiKey?: string;
1282
1282
  baseUrl?: string;
1283
+ fetch?: typeof fetch;
1283
1284
  }): ProviderAdapter;
1284
1285
 
1285
1286
  interface OpenRouterAdapterConfig {
@@ -1501,6 +1502,10 @@ interface OpenAICompatibleConfig {
1501
1502
  * response's `usage.cost` (USD) as costUsd, falling back to the pricing table.
1502
1503
  * Only OpenRouter returns this field — openai/deepinfra leave it false. */
1503
1504
  costFromResponseField?: boolean;
1505
+ /** F091 — the provider reports its own price under this `usage` field (USD) WITHOUT
1506
+ * being asked: DeepInfra's `estimated_cost`. Read in chat and stream; wins over the
1507
+ * pricing table. Unlike costFromResponseField nothing is added to the request. */
1508
+ reportedCostField?: "estimated_cost";
1504
1509
  /** F039.2 — this provider accepts `prompt_cache_key` and caches a shared prefix
1505
1510
  * on it. Mistral only, deliberately: an unknown field is ignored by some
1506
1511
  * OpenAI-compatible servers and rejected with a 400 by others, so sending it
@@ -1582,8 +1587,8 @@ declare const falStubAdapter: ProviderAdapter;
1582
1587
  * wires the live adapters. */
1583
1588
  declare const stubProviders: Record<string, ProviderAdapter>;
1584
1589
 
1585
- declare const VERSION: "0.74.0";
1586
- declare const SDK_TAG: "@broberg/ai-sdk@0.74.0";
1590
+ declare const VERSION: "0.74.1";
1591
+ declare const SDK_TAG: "@broberg/ai-sdk@0.74.1";
1587
1592
 
1588
1593
  /** Built-in defaults. Every entry is overridable via AiConfig.defaults or a
1589
1594
  * per-call override.
package/dist/index.js CHANGED
@@ -23,7 +23,7 @@ import {
23
23
  listMediaPrices,
24
24
  pricingFreshness,
25
25
  pricingGeneratedAt
26
- } from "./chunk-XKN2PYBQ.js";
26
+ } from "./chunk-WDGXCBD2.js";
27
27
  import {
28
28
  PRICING,
29
29
  getPrice
@@ -1209,6 +1209,12 @@ function makeOpenAICompatibleAdapter(config) {
1209
1209
  });
1210
1210
  if (config.costFromResponseField && typeof data.usage?.cost === "number") {
1211
1211
  usage.costUsd = data.usage.cost;
1212
+ usage.costBasis = "reported";
1213
+ }
1214
+ const reported = config.reportedCostField ? data.usage?.[config.reportedCostField] : void 0;
1215
+ if (typeof reported === "number") {
1216
+ usage.costUsd = reported;
1217
+ usage.costBasis = "reported";
1212
1218
  }
1213
1219
  if (typeof data.model === "string" && data.model) usage.servedModel = data.model;
1214
1220
  const result = { text, usage };
@@ -1278,6 +1284,12 @@ function makeOpenAICompatibleAdapter(config) {
1278
1284
  });
1279
1285
  if (config.costFromResponseField && typeof chunk.usage.cost === "number") {
1280
1286
  usage.costUsd = chunk.usage.cost;
1287
+ usage.costBasis = "reported";
1288
+ }
1289
+ const reportedChunk = config.reportedCostField ? chunk.usage[config.reportedCostField] : void 0;
1290
+ if (typeof reportedChunk === "number") {
1291
+ usage.costUsd = reportedChunk;
1292
+ usage.costBasis = "reported";
1281
1293
  }
1282
1294
  if (typeof chunk.model === "string" && chunk.model) usage.servedModel = chunk.model;
1283
1295
  yield { type: "usage", costUsd: usage.costUsd, model: usage.model, usage };
@@ -1688,7 +1700,10 @@ function deepinfraAdapter(config = {}) {
1688
1700
  return makeOpenAICompatibleAdapter({
1689
1701
  name: "deepinfra",
1690
1702
  baseUrl: config.baseUrl ?? DEFAULT_BASE_URLS.deepinfra,
1691
- apiKey: config.apiKey
1703
+ apiKey: config.apiKey,
1704
+ fetch: config.fetch,
1705
+ // F091 — DeepInfra puts its own price in usage.estimated_cost (measured 2026-11-17).
1706
+ reportedCostField: "estimated_cost"
1692
1707
  });
1693
1708
  }
1694
1709
 
@@ -4506,8 +4521,8 @@ var aiConfigSchema = z.object({
4506
4521
  import { randomUUID } from "crypto";
4507
4522
 
4508
4523
  // src/version.ts
4509
- var VERSION = "0.74.0";
4510
- var SDK_TAG = "@broberg/ai-sdk@0.74.0";
4524
+ var VERSION = "0.74.1";
4525
+ var SDK_TAG = "@broberg/ai-sdk@0.74.1";
4511
4526
 
4512
4527
  // src/cost/sinks/upmetrics.ts
4513
4528
  function isRetryableStatus(status) {