@broberg/ai-sdk 0.38.0 → 0.40.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/dist/{chunk-QUOZWQ7G.js → chunk-KXTCLLVF.js} +173 -15
- package/dist/chunk-KXTCLLVF.js.map +1 -0
- package/dist/index.d.ts +74 -5
- package/dist/index.js +138 -90
- package/dist/index.js.map +1 -1
- package/dist/pricing.d.ts +84 -4
- package/dist/pricing.js +9 -1
- package/package.json +2 -2
- package/dist/chunk-QUOZWQ7G.js.map +0 -1
package/dist/pricing.d.ts
CHANGED
|
@@ -10,9 +10,22 @@ interface ModelPrice {
|
|
|
10
10
|
inputPer1M: number;
|
|
11
11
|
/** USD per 1M output tokens. */
|
|
12
12
|
outputPer1M: number;
|
|
13
|
-
/** Pricing unit
|
|
13
|
+
/** Pricing unit: "per_1m_tokens", or "per_sec" / "per_image" for a media model.
|
|
14
|
+
* Check it before reading the token rates — they are 0 on a media row, which is a
|
|
15
|
+
* placeholder and NOT a claim that the model is free. */
|
|
14
16
|
unit: string;
|
|
15
|
-
/**
|
|
17
|
+
/** USD per second of generated video. Set only when `unit` is "per_sec". */
|
|
18
|
+
perSec?: number;
|
|
19
|
+
/** USD per generated image. Set only when `unit` is "per_image". */
|
|
20
|
+
perImage?: number;
|
|
21
|
+
/** ISO date this row was last verified. Media rows carry a HUMAN-set date; token
|
|
22
|
+
* rows inherit the inventory snapshot's. */
|
|
23
|
+
checkedAt?: string;
|
|
24
|
+
/** GDPR region derived from the PROVIDER NAME — a rough grouping, not a residency
|
|
25
|
+
* claim. It is `"other"` for vertex/bfl/fal/azure precisely because those take a
|
|
26
|
+
* configurable endpoint, so their region is a property of the CALL and not of the
|
|
27
|
+
* model. For an actual residency answer use `regionOfHost()` before the call, or
|
|
28
|
+
* `usage.region` after it. */
|
|
16
29
|
region: PriceRegion;
|
|
17
30
|
/** "curated" = authoritative hand-maintained number; "inventory" = from inventory.json. */
|
|
18
31
|
source: "curated" | "inventory";
|
|
@@ -25,6 +38,10 @@ interface PriceFilter {
|
|
|
25
38
|
/** Only $0/$0 models when true; only paid when false. */
|
|
26
39
|
free?: boolean;
|
|
27
40
|
}
|
|
41
|
+
/** Every non-token price the SDK bills from (F050). Separate from
|
|
42
|
+
* {@link listModelPrices} because the two answer different questions and mixing
|
|
43
|
+
* them silently changed what an existing caller's list meant. */
|
|
44
|
+
declare function listMediaPrices(): ModelPrice[];
|
|
28
45
|
/** Exact price for a model. `modelId` accepts "vendor/model", "provider:model", or a
|
|
29
46
|
* bare model/basename. Returns undefined if unknown. */
|
|
30
47
|
declare function getModelPrice(modelId: string): ModelPrice | undefined;
|
|
@@ -45,6 +62,17 @@ declare function pricingGeneratedAt(): string;
|
|
|
45
62
|
* ONE constant: the `model-advisor` skill quotes the same number, and two copies of a
|
|
46
63
|
* threshold drift apart until the doc and the code disagree about what "stale" means. */
|
|
47
64
|
declare const PRICING_STALE_AFTER_DAYS = 35;
|
|
65
|
+
/** Freshness of ONE pricing unit. */
|
|
66
|
+
interface UnitFreshness {
|
|
67
|
+
unit: string;
|
|
68
|
+
/** How many rows the table holds in this unit. Zero means NOT COVERED — which is
|
|
69
|
+
* a different answer from "covered and fresh", and used to be indistinguishable. */
|
|
70
|
+
count: number;
|
|
71
|
+
/** When a check last happened for this unit. Empty = never. */
|
|
72
|
+
checkedAt: string;
|
|
73
|
+
ageDays: number | null;
|
|
74
|
+
stale: boolean;
|
|
75
|
+
}
|
|
48
76
|
interface PricingFreshness {
|
|
49
77
|
/** When the numbers last CHANGED. */
|
|
50
78
|
generatedAt: string;
|
|
@@ -54,9 +82,24 @@ interface PricingFreshness {
|
|
|
54
82
|
/** Days since `checkedAt`; `null` when there is no check date to measure from. */
|
|
55
83
|
ageDays: number | null;
|
|
56
84
|
/** True when the check is older than {@link PRICING_STALE_AFTER_DAYS} — or when
|
|
57
|
-
* there is no check date at all. An unanswerable question is not a pass.
|
|
85
|
+
* there is no check date at all. An unanswerable question is not a pass.
|
|
86
|
+
*
|
|
87
|
+
* **Scope: the TOKEN table only.** Unchanged from F046 on purpose — consumers and
|
|
88
|
+
* the release guard already read it. For "is anything I might bill for covered?",
|
|
89
|
+
* read {@link PricingFreshness.caveats}. */
|
|
58
90
|
stale: boolean;
|
|
59
91
|
thresholdDays: number;
|
|
92
|
+
/** Per-unit breakdown (F050). Every unit the SDK can bill in, whether or not the
|
|
93
|
+
* table has rows for it — an absent unit must show up as `count: 0`, not as an
|
|
94
|
+
* absent key that a caller iterating the object would never notice. */
|
|
95
|
+
units: UnitFreshness[];
|
|
96
|
+
/** Human-readable reservations, one per unit that is uncovered or stale.
|
|
97
|
+
*
|
|
98
|
+
* This is the field that makes `stale: false` honest. super measured the state it
|
|
99
|
+
* exists to end: `{ageDays: 0, stale: false}` on a table where per-second prices
|
|
100
|
+
* could not exist, so the API built to catch price drift reported "fresh" about
|
|
101
|
+
* numbers it structurally could not see. Empty array = no reservations. */
|
|
102
|
+
caveats: string[];
|
|
60
103
|
}
|
|
61
104
|
declare function pricingFreshness(nowMs?: number): PricingFreshness;
|
|
62
105
|
/** Warn ONCE per process that these prices are old. Called from every price lookup.
|
|
@@ -69,4 +112,41 @@ declare function warnIfPricingStale(nowMs?: number): void;
|
|
|
69
112
|
/** Test-only: forget that we already warned. */
|
|
70
113
|
declare function resetPricingWarningForTests(): void;
|
|
71
114
|
|
|
72
|
-
|
|
115
|
+
/** A price that is not per-token.
|
|
116
|
+
*
|
|
117
|
+
* Six units, not the two F050 was carded for. The form-forbidding test found ten
|
|
118
|
+
* MORE hand-written price constants than super's report named — speech billed per
|
|
119
|
+
* 1000 characters, transcription per audio-minute, OCR per page, a flat LoRA
|
|
120
|
+
* training fee, and two more per-image tables. Moving only the four that had been
|
|
121
|
+
* noticed would have left `caveats` reporting "covered" while four other units sat
|
|
122
|
+
* in four adapters' private constants: the same blindness, one unit along. */
|
|
123
|
+
type MediaUnit = "per_sec" | "per_image" | "per_1k_chars" | "per_min" | "per_page" | "per_training";
|
|
124
|
+
interface MediaPrice {
|
|
125
|
+
unit: MediaUnit;
|
|
126
|
+
/** USD per second (video) or per generated image. */
|
|
127
|
+
usd: number;
|
|
128
|
+
/** ISO date a HUMAN last checked this against the vendor's published price.
|
|
129
|
+
* Not derived from the monthly token job — that job never sees these. */
|
|
130
|
+
checkedAt: string;
|
|
131
|
+
/** Where the number comes from, so the next person can re-check it. */
|
|
132
|
+
source: string;
|
|
133
|
+
}
|
|
134
|
+
/** When a human last walked the whole media table against vendor pricing pages.
|
|
135
|
+
*
|
|
136
|
+
* ONE date for the table rather than trusting every row's own: a row added later
|
|
137
|
+
* with a fresh date would otherwise pull the table's average forward while the
|
|
138
|
+
* older rows sat unrevised. Freshness reads the OLDEST answer, and this is it. */
|
|
139
|
+
declare const MEDIA_PRICING_CHECKED_AT = "2026-09-05";
|
|
140
|
+
/** Default clip length billed when the caller passes no `durationSec`.
|
|
141
|
+
*
|
|
142
|
+
* It is an ASSUMPTION, not a measurement — the provider does not tell us how long
|
|
143
|
+
* the clip it returned actually is. Every cost derived from it is stamped
|
|
144
|
+
* `costBasis: "estimated"` so a consumer (and upmetrics) can tell it apart from a
|
|
145
|
+
* cost computed off a real duration. super reported using such a number as if it
|
|
146
|
+
* were measured and passing it on to Christian; that is the damage this stamp
|
|
147
|
+
* removes. */
|
|
148
|
+
declare const DEFAULT_CLIP_SEC = 8;
|
|
149
|
+
/** Look up a non-token price. Unknown → undefined (never a fabricated 0). */
|
|
150
|
+
declare function getMediaPrice(provider: string, model: string): MediaPrice | undefined;
|
|
151
|
+
|
|
152
|
+
export { DEFAULT_CLIP_SEC, MEDIA_PRICING_CHECKED_AT, type MediaPrice, type MediaUnit, type ModelPrice, PRICING_STALE_AFTER_DAYS, type PriceFilter, type PriceRegion, type PricingFreshness, type UnitFreshness, findModelPrices, getMediaPrice, getModelPrice, listMediaPrices, listModelPrices, priceCall, pricingFreshness, pricingGeneratedAt, resetPricingWarningForTests, warnIfPricingStale };
|
package/dist/pricing.js
CHANGED
|
@@ -1,18 +1,26 @@
|
|
|
1
1
|
import {
|
|
2
|
+
DEFAULT_CLIP_SEC,
|
|
3
|
+
MEDIA_PRICING_CHECKED_AT,
|
|
2
4
|
PRICING_STALE_AFTER_DAYS,
|
|
3
5
|
findModelPrices,
|
|
6
|
+
getMediaPrice,
|
|
4
7
|
getModelPrice,
|
|
8
|
+
listMediaPrices,
|
|
5
9
|
listModelPrices,
|
|
6
10
|
priceCall,
|
|
7
11
|
pricingFreshness,
|
|
8
12
|
pricingGeneratedAt,
|
|
9
13
|
resetPricingWarningForTests,
|
|
10
14
|
warnIfPricingStale
|
|
11
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-KXTCLLVF.js";
|
|
12
16
|
export {
|
|
17
|
+
DEFAULT_CLIP_SEC,
|
|
18
|
+
MEDIA_PRICING_CHECKED_AT,
|
|
13
19
|
PRICING_STALE_AFTER_DAYS,
|
|
14
20
|
findModelPrices,
|
|
21
|
+
getMediaPrice,
|
|
15
22
|
getModelPrice,
|
|
23
|
+
listMediaPrices,
|
|
16
24
|
listModelPrices,
|
|
17
25
|
priceCall,
|
|
18
26
|
pricingFreshness,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@broberg/ai-sdk",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Unified AI/LLM SDK
|
|
3
|
+
"version": "0.40.0",
|
|
4
|
+
"description": "Unified AI/LLM SDK — one facade, all providers, all capabilities, first-class cost control on every call.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "FSL-1.1-Apache-2.0",
|
|
7
7
|
"author": "Christian Broberg <cb@webhouse.dk>",
|