@broberg/ai-sdk 0.18.0 → 0.20.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-V5AQYES2.js +100 -0
- package/dist/chunk-V5AQYES2.js.map +1 -0
- package/dist/index.d.ts +29 -3
- package/dist/index.js +92 -102
- package/dist/index.js.map +1 -1
- package/dist/pricing.d.ts +40 -0
- package/dist/pricing.js +118 -0
- package/dist/pricing.js.map +1 -0
- package/package.json +7 -2
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
// src/cost/pricing.ts
|
|
2
|
+
var V = "2026-06-02";
|
|
3
|
+
var MS = "2026-06-04-mistral.ai";
|
|
4
|
+
var PRICING = {
|
|
5
|
+
// Anthropic (direct API). DEFAULT_TIER_MAP: fast/cheap=haiku, smart/vision=sonnet, powerful=opus.
|
|
6
|
+
"anthropic:claude-haiku-4-5": {
|
|
7
|
+
inputPer1M: 0.8,
|
|
8
|
+
outputPer1M: 4,
|
|
9
|
+
cacheReadPer1M: 0.08,
|
|
10
|
+
cacheWritePer1M: 1,
|
|
11
|
+
version: V
|
|
12
|
+
},
|
|
13
|
+
"anthropic:claude-sonnet-4-6": {
|
|
14
|
+
inputPer1M: 3,
|
|
15
|
+
outputPer1M: 15,
|
|
16
|
+
cacheReadPer1M: 0.3,
|
|
17
|
+
cacheWritePer1M: 3.75,
|
|
18
|
+
version: V
|
|
19
|
+
},
|
|
20
|
+
"anthropic:claude-opus-4-8": {
|
|
21
|
+
inputPer1M: 15,
|
|
22
|
+
outputPer1M: 75,
|
|
23
|
+
cacheReadPer1M: 1.5,
|
|
24
|
+
cacheWritePer1M: 18.75,
|
|
25
|
+
version: V
|
|
26
|
+
},
|
|
27
|
+
// OpenAI. embedding default tier = text-embedding-3-small (no output tokens).
|
|
28
|
+
"openai:text-embedding-3-small": { inputPer1M: 0.02, outputPer1M: 0, version: V },
|
|
29
|
+
"openai:text-embedding-3-large": { inputPer1M: 0.13, outputPer1M: 0, version: V },
|
|
30
|
+
"openai:gpt-4o": { inputPer1M: 2.5, outputPer1M: 10, version: V },
|
|
31
|
+
"openai:gpt-4o-mini": { inputPer1M: 0.15, outputPer1M: 0.6, version: V },
|
|
32
|
+
// Whisper is priced per minute, not per token — not representable here; transcribe
|
|
33
|
+
// (F5.6) computes its own cost. Listed as 0 so token-based compute never charges it.
|
|
34
|
+
"openai:whisper-1": { inputPer1M: 0, outputPer1M: 0, version: V },
|
|
35
|
+
// OpenRouter (meta-router — model slugs include the upstream vendor). Slugs use
|
|
36
|
+
// dots (claude-sonnet-4.6) to match OpenRouter's live ids; the dashed forms
|
|
37
|
+
// never matched a real call. Caught by the F014 catalogue research.
|
|
38
|
+
"openrouter:anthropic/claude-sonnet-4.6": { inputPer1M: 3, outputPer1M: 15, version: V },
|
|
39
|
+
// OpenRouter ground-truth $1/$5 — a markup over Anthropic-direct's $0.8/$4
|
|
40
|
+
// (the `anthropic:` entry above). Was masked while the slug used dashes.
|
|
41
|
+
"openrouter:anthropic/claude-haiku-4.5": { inputPer1M: 1, outputPer1M: 5, version: "2026-06-04" },
|
|
42
|
+
"openrouter:google/gemini-2.5-flash": { inputPer1M: 0.3, outputPer1M: 2.5, version: V },
|
|
43
|
+
// Ground-truth from OpenRouter /api/v1/models (was a 0.3 estimate; now 0.279).
|
|
44
|
+
"openrouter:minimax/minimax-m2.7": {
|
|
45
|
+
inputPer1M: 0.279,
|
|
46
|
+
outputPer1M: 1.2,
|
|
47
|
+
version: "2026-06-04"
|
|
48
|
+
},
|
|
49
|
+
// DeepSeek V4 (CN-hosted — NOT GDPR-safe; non-personal-data workloads only).
|
|
50
|
+
// On 2026-05-22 DeepSeek made the "75% off" promo the permanent official price.
|
|
51
|
+
// V4-Pro $0.435/$0.87 is ~34x cheaper than GPT-5.5 on output; flash is cheaper
|
|
52
|
+
// still. Numbers match OpenRouter /api/v1/models 1:1 (no router markup). A strong
|
|
53
|
+
// cheap route for fleet background work once `claude -p` is API-billed (15 Jun).
|
|
54
|
+
"openrouter:deepseek/deepseek-v4-pro": { inputPer1M: 0.435, outputPer1M: 0.87, version: "2026-05-22-deepseek-official" },
|
|
55
|
+
"openrouter:deepseek/deepseek-v4-flash": { inputPer1M: 0.0983, outputPer1M: 0.1966, version: "2026-05-22-deepseek-official" },
|
|
56
|
+
// Google Gemini (direct). Provider key is "gemini" — matches the adapter's
|
|
57
|
+
// usage.provider + the override.provider callers pass. (Image-gen models are
|
|
58
|
+
// priced per-image in the adapter, not here.)
|
|
59
|
+
"gemini:gemini-2.5-flash": { inputPer1M: 0.3, outputPer1M: 2.5, version: V },
|
|
60
|
+
// flash-lite is the default `video` tier (F019) — cheap native video understanding.
|
|
61
|
+
"gemini:gemini-2.5-flash-lite": { inputPer1M: 0.1, outputPer1M: 0.4, version: "2026-06-04-or-xref" },
|
|
62
|
+
// Mistral (direct, La Plateforme). Official prices from mistral.ai/pricing
|
|
63
|
+
// (2026-06-04, per Christian's CD report). EU/Paris-hosted — the designated
|
|
64
|
+
// GDPR-safe provider for client/personal-data workloads (see F015). NB:
|
|
65
|
+
// medium-3.5 is the premium "Vibe" coding tier ($1.5/$7.5); Large 3 ($0.5/$1.5)
|
|
66
|
+
// is the cheaper frontier general-purpose model despite the higher number.
|
|
67
|
+
"mistral:mistral-large-latest": { inputPer1M: 0.5, outputPer1M: 1.5, version: MS },
|
|
68
|
+
"mistral:mistral-large-2512": { inputPer1M: 0.5, outputPer1M: 1.5, version: MS },
|
|
69
|
+
"mistral:mistral-medium-latest": { inputPer1M: 1.5, outputPer1M: 7.5, version: MS },
|
|
70
|
+
"mistral:mistral-medium-3.5": { inputPer1M: 1.5, outputPer1M: 7.5, version: MS },
|
|
71
|
+
"mistral:mistral-medium-3": { inputPer1M: 0.4, outputPer1M: 2, version: "2026-06-04-or-xref" },
|
|
72
|
+
"mistral:mistral-small-latest": { inputPer1M: 0.1, outputPer1M: 0.3, version: MS },
|
|
73
|
+
"mistral:mistral-small-2603": { inputPer1M: 0.1, outputPer1M: 0.3, version: MS },
|
|
74
|
+
"mistral:ministral-3b-latest": { inputPer1M: 0.1, outputPer1M: 0.1, version: MS },
|
|
75
|
+
"mistral:ministral-8b-latest": { inputPer1M: 0.15, outputPer1M: 0.15, version: MS },
|
|
76
|
+
"mistral:ministral-14b-latest": { inputPer1M: 0.2, outputPer1M: 0.2, version: MS },
|
|
77
|
+
"mistral:magistral-medium-latest": { inputPer1M: 2, outputPer1M: 5, version: MS },
|
|
78
|
+
"mistral:magistral-small-latest": { inputPer1M: 0.5, outputPer1M: 1.5, version: MS },
|
|
79
|
+
"mistral:devstral-latest": { inputPer1M: 0.4, outputPer1M: 2, version: MS },
|
|
80
|
+
"mistral:codestral-latest": { inputPer1M: 0.3, outputPer1M: 0.9, version: MS },
|
|
81
|
+
"mistral:open-mistral-nemo": { inputPer1M: 0.15, outputPer1M: 0.15, version: MS },
|
|
82
|
+
// Moderation (F016.4) — per input token; output 0. (OCR is per-page in the adapter.)
|
|
83
|
+
"mistral:mistral-moderation-latest": { inputPer1M: 0.1, outputPer1M: 0, version: MS },
|
|
84
|
+
// Embeddings (F016.5) — per input token.
|
|
85
|
+
"mistral:mistral-embed": { inputPer1M: 0.1, outputPer1M: 0, version: MS },
|
|
86
|
+
"mistral:codestral-embed": { inputPer1M: 0.15, outputPer1M: 0, version: MS }
|
|
87
|
+
};
|
|
88
|
+
function getPrice(provider, model) {
|
|
89
|
+
const exact = PRICING[`${provider}:${model}`];
|
|
90
|
+
if (exact) return exact;
|
|
91
|
+
const base = model.replace(/-\d{8}$/, "");
|
|
92
|
+
if (base !== model) return PRICING[`${provider}:${base}`];
|
|
93
|
+
return void 0;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export {
|
|
97
|
+
PRICING,
|
|
98
|
+
getPrice
|
|
99
|
+
};
|
|
100
|
+
//# sourceMappingURL=chunk-V5AQYES2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/cost/pricing.ts"],"sourcesContent":["// Versioned per-(provider, model) pricing. F3.6 populates the table + adds tests\n// + MiniMax coverage. F3.1 ships the type + lookup with an empty table, so\n// computeCost returns 0 for every model until F3.6 lands (calls still complete).\nexport interface PricingEntry {\n /** USD per 1M input tokens. */\n inputPer1M: number;\n /** USD per 1M output tokens. */\n outputPer1M: number;\n /** USD per 1M cache-read tokens (falls back to input rate if unset). */\n cacheReadPer1M?: number;\n /** USD per 1M cache-write/creation tokens (falls back to input rate if unset). */\n cacheWritePer1M?: number;\n /** Pricing snapshot version (date or tag) so stale entries are detectable. */\n version: string;\n}\n\n// USD per 1M tokens. Anthropic cache multipliers follow the standard model:\n// cache-read ≈ 0.1× input, cache-write ≈ 1.25× input. Verified against the\n// pricing tables in cms (packages/cms-ai/src/providers) + trail (model-lab).\n// MiniMax M2.7 is an estimate pending confirmation against OpenRouter's live\n// price page — flagged in its version string.\nconst V = \"2026-06-02\";\n// Mistral prices come straight from mistral.ai/pricing (per Christian's CD report).\nconst MS = \"2026-06-04-mistral.ai\";\n\n/** Keyed `${provider}:${model}`. Exported so the catalogue-research job (F014)\n * can enumerate every priced entry and diff it against the live provider lists. */\nexport const PRICING: Record<string, PricingEntry> = {\n // Anthropic (direct API). DEFAULT_TIER_MAP: fast/cheap=haiku, smart/vision=sonnet, powerful=opus.\n \"anthropic:claude-haiku-4-5\": {\n inputPer1M: 0.8,\n outputPer1M: 4.0,\n cacheReadPer1M: 0.08,\n cacheWritePer1M: 1.0,\n version: V,\n },\n \"anthropic:claude-sonnet-4-6\": {\n inputPer1M: 3.0,\n outputPer1M: 15.0,\n cacheReadPer1M: 0.3,\n cacheWritePer1M: 3.75,\n version: V,\n },\n \"anthropic:claude-opus-4-8\": {\n inputPer1M: 15.0,\n outputPer1M: 75.0,\n cacheReadPer1M: 1.5,\n cacheWritePer1M: 18.75,\n version: V,\n },\n\n // OpenAI. embedding default tier = text-embedding-3-small (no output tokens).\n \"openai:text-embedding-3-small\": { inputPer1M: 0.02, outputPer1M: 0, version: V },\n \"openai:text-embedding-3-large\": { inputPer1M: 0.13, outputPer1M: 0, version: V },\n \"openai:gpt-4o\": { inputPer1M: 2.5, outputPer1M: 10.0, version: V },\n \"openai:gpt-4o-mini\": { inputPer1M: 0.15, outputPer1M: 0.6, version: V },\n // Whisper is priced per minute, not per token — not representable here; transcribe\n // (F5.6) computes its own cost. Listed as 0 so token-based compute never charges it.\n \"openai:whisper-1\": { inputPer1M: 0, outputPer1M: 0, version: V },\n\n // OpenRouter (meta-router — model slugs include the upstream vendor). Slugs use\n // dots (claude-sonnet-4.6) to match OpenRouter's live ids; the dashed forms\n // never matched a real call. Caught by the F014 catalogue research.\n \"openrouter:anthropic/claude-sonnet-4.6\": { inputPer1M: 3.0, outputPer1M: 15.0, version: V },\n // OpenRouter ground-truth $1/$5 — a markup over Anthropic-direct's $0.8/$4\n // (the `anthropic:` entry above). Was masked while the slug used dashes.\n \"openrouter:anthropic/claude-haiku-4.5\": { inputPer1M: 1.0, outputPer1M: 5.0, version: \"2026-06-04\" },\n \"openrouter:google/gemini-2.5-flash\": { inputPer1M: 0.3, outputPer1M: 2.5, version: V },\n // Ground-truth from OpenRouter /api/v1/models (was a 0.3 estimate; now 0.279).\n \"openrouter:minimax/minimax-m2.7\": {\n inputPer1M: 0.279,\n outputPer1M: 1.2,\n version: \"2026-06-04\",\n },\n // DeepSeek V4 (CN-hosted — NOT GDPR-safe; non-personal-data workloads only).\n // On 2026-05-22 DeepSeek made the \"75% off\" promo the permanent official price.\n // V4-Pro $0.435/$0.87 is ~34x cheaper than GPT-5.5 on output; flash is cheaper\n // still. Numbers match OpenRouter /api/v1/models 1:1 (no router markup). A strong\n // cheap route for fleet background work once `claude -p` is API-billed (15 Jun).\n \"openrouter:deepseek/deepseek-v4-pro\": { inputPer1M: 0.435, outputPer1M: 0.87, version: \"2026-05-22-deepseek-official\" },\n \"openrouter:deepseek/deepseek-v4-flash\": { inputPer1M: 0.0983, outputPer1M: 0.1966, version: \"2026-05-22-deepseek-official\" },\n\n // Google Gemini (direct). Provider key is \"gemini\" — matches the adapter's\n // usage.provider + the override.provider callers pass. (Image-gen models are\n // priced per-image in the adapter, not here.)\n \"gemini:gemini-2.5-flash\": { inputPer1M: 0.3, outputPer1M: 2.5, version: V },\n // flash-lite is the default `video` tier (F019) — cheap native video understanding.\n \"gemini:gemini-2.5-flash-lite\": { inputPer1M: 0.1, outputPer1M: 0.4, version: \"2026-06-04-or-xref\" },\n\n // Mistral (direct, La Plateforme). Official prices from mistral.ai/pricing\n // (2026-06-04, per Christian's CD report). EU/Paris-hosted — the designated\n // GDPR-safe provider for client/personal-data workloads (see F015). NB:\n // medium-3.5 is the premium \"Vibe\" coding tier ($1.5/$7.5); Large 3 ($0.5/$1.5)\n // is the cheaper frontier general-purpose model despite the higher number.\n \"mistral:mistral-large-latest\": { inputPer1M: 0.5, outputPer1M: 1.5, version: MS },\n \"mistral:mistral-large-2512\": { inputPer1M: 0.5, outputPer1M: 1.5, version: MS },\n \"mistral:mistral-medium-latest\": { inputPer1M: 1.5, outputPer1M: 7.5, version: MS },\n \"mistral:mistral-medium-3.5\": { inputPer1M: 1.5, outputPer1M: 7.5, version: MS },\n \"mistral:mistral-medium-3\": { inputPer1M: 0.4, outputPer1M: 2.0, version: \"2026-06-04-or-xref\" },\n \"mistral:mistral-small-latest\": { inputPer1M: 0.1, outputPer1M: 0.3, version: MS },\n \"mistral:mistral-small-2603\": { inputPer1M: 0.1, outputPer1M: 0.3, version: MS },\n \"mistral:ministral-3b-latest\": { inputPer1M: 0.1, outputPer1M: 0.1, version: MS },\n \"mistral:ministral-8b-latest\": { inputPer1M: 0.15, outputPer1M: 0.15, version: MS },\n \"mistral:ministral-14b-latest\": { inputPer1M: 0.2, outputPer1M: 0.2, version: MS },\n \"mistral:magistral-medium-latest\": { inputPer1M: 2.0, outputPer1M: 5.0, version: MS },\n \"mistral:magistral-small-latest\": { inputPer1M: 0.5, outputPer1M: 1.5, version: MS },\n \"mistral:devstral-latest\": { inputPer1M: 0.4, outputPer1M: 2.0, version: MS },\n \"mistral:codestral-latest\": { inputPer1M: 0.3, outputPer1M: 0.9, version: MS },\n \"mistral:open-mistral-nemo\": { inputPer1M: 0.15, outputPer1M: 0.15, version: MS },\n // Moderation (F016.4) — per input token; output 0. (OCR is per-page in the adapter.)\n \"mistral:mistral-moderation-latest\": { inputPer1M: 0.1, outputPer1M: 0, version: MS },\n // Embeddings (F016.5) — per input token.\n \"mistral:mistral-embed\": { inputPer1M: 0.1, outputPer1M: 0, version: MS },\n \"mistral:codestral-embed\": { inputPer1M: 0.15, outputPer1M: 0, version: MS },\n};\n\nexport function getPrice(provider: string, model: string): PricingEntry | undefined {\n const exact = PRICING[`${provider}:${model}`];\n if (exact) return exact;\n // Providers ship dated model snapshots, e.g. \"claude-haiku-4-5-20251001\".\n // Strip a trailing -YYYYMMDD and retry the base lookup so a dated variant\n // prices the same as its base model instead of falling through to 0 — a real\n // paid call must never be logged as $0 (F012). Covers openrouter slugs too.\n const base = model.replace(/-\\d{8}$/, \"\");\n if (base !== model) return PRICING[`${provider}:${base}`];\n return undefined;\n}\n"],"mappings":"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","names":[]}
|
package/dist/index.d.ts
CHANGED
|
@@ -245,6 +245,9 @@ interface TranscribeRequest {
|
|
|
245
245
|
language?: string;
|
|
246
246
|
/** Audio length in seconds — enables per-minute cost (Whisper). Omit → cost 0. */
|
|
247
247
|
durationSec?: number;
|
|
248
|
+
/** Bias recognition toward these brand/jargon terms (Azure phraseList, F029.3).
|
|
249
|
+
* Providers without biasing support (Voxtral/Whisper) ignore it. */
|
|
250
|
+
phrases?: string[];
|
|
248
251
|
spec: TierSpec;
|
|
249
252
|
}
|
|
250
253
|
interface TranscribeResult {
|
|
@@ -1312,6 +1315,8 @@ declare const transcribeInputSchema: z.ZodObject<{
|
|
|
1312
1315
|
language: z.ZodOptional<z.ZodString>;
|
|
1313
1316
|
/** Audio length in seconds — enables Whisper per-minute cost. */
|
|
1314
1317
|
durationSec: z.ZodOptional<z.ZodNumber>;
|
|
1318
|
+
/** Bias toward brand/jargon terms (Azure phraseList, F029.3); others ignore it. */
|
|
1319
|
+
phrases: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
1315
1320
|
}, "strip", z.ZodTypeAny, {
|
|
1316
1321
|
audio: string | Uint8Array<ArrayBuffer>;
|
|
1317
1322
|
language?: string | undefined;
|
|
@@ -1329,6 +1334,7 @@ declare const transcribeInputSchema: z.ZodObject<{
|
|
|
1329
1334
|
})[] | undefined;
|
|
1330
1335
|
labels?: Record<string, string> | undefined;
|
|
1331
1336
|
durationSec?: number | undefined;
|
|
1337
|
+
phrases?: string[] | undefined;
|
|
1332
1338
|
}, {
|
|
1333
1339
|
audio: string | Uint8Array<ArrayBuffer>;
|
|
1334
1340
|
language?: string | undefined;
|
|
@@ -1346,6 +1352,7 @@ declare const transcribeInputSchema: z.ZodObject<{
|
|
|
1346
1352
|
})[] | undefined;
|
|
1347
1353
|
labels?: Record<string, string> | undefined;
|
|
1348
1354
|
durationSec?: number | undefined;
|
|
1355
|
+
phrases?: string[] | undefined;
|
|
1349
1356
|
}>;
|
|
1350
1357
|
declare const ocrInputSchema: z.ZodObject<{
|
|
1351
1358
|
tier: z.ZodOptional<z.ZodEnum<["fast", "smart", "powerful", "cheap", "vision", "video", "embedding"]>>;
|
|
@@ -1804,6 +1811,14 @@ declare function openrouterAdapter(config?: {
|
|
|
1804
1811
|
title?: string;
|
|
1805
1812
|
}): ProviderAdapter;
|
|
1806
1813
|
|
|
1814
|
+
declare function requestyAdapter(config?: {
|
|
1815
|
+
apiKey?: string;
|
|
1816
|
+
baseUrl?: string;
|
|
1817
|
+
eu?: boolean;
|
|
1818
|
+
referer?: string;
|
|
1819
|
+
title?: string;
|
|
1820
|
+
}): ProviderAdapter;
|
|
1821
|
+
|
|
1807
1822
|
declare function mistralAdapter(config?: {
|
|
1808
1823
|
apiKey?: string;
|
|
1809
1824
|
baseUrl?: string;
|
|
@@ -1863,6 +1878,17 @@ declare function azureAdapter(config?: {
|
|
|
1863
1878
|
region?: string;
|
|
1864
1879
|
fetch?: typeof fetch;
|
|
1865
1880
|
pricePer1kChars?: number;
|
|
1881
|
+
/** USD per audio-minute for transcribe (overrides AZURE_STT_PRICE_PER_MIN). */
|
|
1882
|
+
sttPricePerMin?: number;
|
|
1883
|
+
/** STT base URL override (e.g. a resource custom domain). */
|
|
1884
|
+
sttBaseUrl?: string;
|
|
1885
|
+
/** Resource name → custom-domain STT host `{resource}.cognitiveservices.azure.com`
|
|
1886
|
+
* (or env AZURE_SPEECH_RESOURCE). Without it, STT uses the regional host. */
|
|
1887
|
+
resource?: string;
|
|
1888
|
+
/** Fast-transcription api-version (overrides the GA default). */
|
|
1889
|
+
sttApiVersion?: string;
|
|
1890
|
+
/** phraseList biasing weight (0–2) applied when a call passes `phrases`. Default 1.5. */
|
|
1891
|
+
sttBiasingWeight?: number;
|
|
1866
1892
|
}): ProviderAdapter;
|
|
1867
1893
|
|
|
1868
1894
|
interface FalAdapterConfig {
|
|
@@ -1945,8 +1971,8 @@ declare const falStubAdapter: ProviderAdapter;
|
|
|
1945
1971
|
* wires the live adapters. */
|
|
1946
1972
|
declare const stubProviders: Record<string, ProviderAdapter>;
|
|
1947
1973
|
|
|
1948
|
-
declare const VERSION: "0.
|
|
1949
|
-
declare const SDK_TAG: "@broberg/ai-sdk@0.
|
|
1974
|
+
declare const VERSION: "0.20.0";
|
|
1975
|
+
declare const SDK_TAG: "@broberg/ai-sdk@0.20.0";
|
|
1950
1976
|
|
|
1951
1977
|
/** Built-in defaults. Every entry is overridable via AiConfig.defaults or a
|
|
1952
1978
|
* per-call override. Model IDs are current at scaffold time; callers pin their
|
|
@@ -2269,4 +2295,4 @@ interface StreamTransportRequest extends TransportRequest {
|
|
|
2269
2295
|
*/
|
|
2270
2296
|
declare function streamTransport(req: StreamTransportRequest): AsyncIterable<string>;
|
|
2271
2297
|
|
|
2272
|
-
export { AZURE_DANISH_VOICES, AZURE_DANISH_VOICE_LIST, type AiClient, type AiConfig, type AzureVoiceInfo, type BatchJob, type BatchRequestItem, type BatchResultItem, type BflAdapterConfig, type BflCredits, type BudgetConfig, BudgetExceededError, BudgetGuard, type BudgetStore, type CallOptions, type Capability, type ChatInput, type ChatRequest, type ChatResult, type ChatStreamEvent, type ClassifyInput, type ClassifyResult, type ContentPart, type Contracts, type CostQuery, type CostSink, type CostSummary, type CostSummaryQuery, type CostTimeseriesQuery, DEFAULT_TIER_MAP, type DesignInput, type DesignResult, type DialogueRequest, type DialogueTurn, type DiscordSinkConfig, ELEVENLABS_DANISH_VOICES, type EmbeddingInput, type EmbeddingRequest, type EmbeddingResult, type ExtractInput, type ExtractResult, type FalAdapterConfig, type HttpResponse, type ImageInput, type ImageRequest, type ImageResult, type LoraWeight, type Message, type MockupInput, type MockupResult, type ModerationInput, type ModerationItem, type ModerationRequest, type ModerationResult, type OcrInput, type OcrPage, type OcrRequest, type OcrResult, type OpenAICompatibleConfig, type PodcastInput, type PodcastResult, type PricingEntry, type ProviderAdapter, type RefreshOptions, type RefreshResult, type RerankInput, type RerankResult, type Role, SDK_TAG, type SqliteBudgetStoreConfig, type SqliteSinkConfig, StreamHttpError, type SubprocessResponse, type Tier, type TierSpec, type Tool, type ToolCall, type TrainStyleInput, type TrainStyleRequest, type TrainStyleResult, type TranscribeInput, type TranscribeRequest, type TranscribeResult, type TranslateInput, type TranslateResult, type Transport, type TransportRequest, type TransportResponse, type TtsInput, type TtsRequest, type UpmetricsCostClientConfig, UpmetricsCostError, type UpmetricsCostRow, type UpmetricsCostSummary, type UpmetricsCostTimeseries, type UpmetricsSinkConfig, type Usage, VERSION, type VideoInput, type VisionInput, aiConfigSchema, anthropicAdapter, anthropicApiAdapter, anthropicSubprocessAdapter, azureAdapter, bflAdapter, bflCredits, chatInputSchema, computeCost, createAI, deepinfraAdapter, defaultProviders, discordSink, elevenlabsAdapter, embeddingInputSchema, falAdapter, falStubAdapter, freshUsage, fromProviderToolCall, geminiAdapter, getCostSummary, getPrice, httpTransport, imageInputSchema, listAzureDanishVoices, makeContracts, makeOpenAICompatibleAdapter, messageSchema, mistralAdapter, multiSink, noopSink, openaiAdapter, openaiStubAdapter, openrouterAdapter, parseClaudeCliJson, parseJsonLoose, refreshAvailability, resetRefreshState, resetRegistry, resolveAzureVoice, resolveTier, resolveVoice, sqliteBudgetStore, sqliteSink, streamTransport, stubProviders, subprocessTransport, tierSpecSchema, toProviderTools, toolSchema, translateInputSchema, upmetricsCostClient, upmetricsSink, usdFromMicro, visionInputSchema };
|
|
2298
|
+
export { AZURE_DANISH_VOICES, AZURE_DANISH_VOICE_LIST, type AiClient, type AiConfig, type AzureVoiceInfo, type BatchJob, type BatchRequestItem, type BatchResultItem, type BflAdapterConfig, type BflCredits, type BudgetConfig, BudgetExceededError, BudgetGuard, type BudgetStore, type CallOptions, type Capability, type ChatInput, type ChatRequest, type ChatResult, type ChatStreamEvent, type ClassifyInput, type ClassifyResult, type ContentPart, type Contracts, type CostQuery, type CostSink, type CostSummary, type CostSummaryQuery, type CostTimeseriesQuery, DEFAULT_TIER_MAP, type DesignInput, type DesignResult, type DialogueRequest, type DialogueTurn, type DiscordSinkConfig, ELEVENLABS_DANISH_VOICES, type EmbeddingInput, type EmbeddingRequest, type EmbeddingResult, type ExtractInput, type ExtractResult, type FalAdapterConfig, type HttpResponse, type ImageInput, type ImageRequest, type ImageResult, type LoraWeight, type Message, type MockupInput, type MockupResult, type ModerationInput, type ModerationItem, type ModerationRequest, type ModerationResult, type OcrInput, type OcrPage, type OcrRequest, type OcrResult, type OpenAICompatibleConfig, type PodcastInput, type PodcastResult, type PricingEntry, type ProviderAdapter, type RefreshOptions, type RefreshResult, type RerankInput, type RerankResult, type Role, SDK_TAG, type SqliteBudgetStoreConfig, type SqliteSinkConfig, StreamHttpError, type SubprocessResponse, type Tier, type TierSpec, type Tool, type ToolCall, type TrainStyleInput, type TrainStyleRequest, type TrainStyleResult, type TranscribeInput, type TranscribeRequest, type TranscribeResult, type TranslateInput, type TranslateResult, type Transport, type TransportRequest, type TransportResponse, type TtsInput, type TtsRequest, type UpmetricsCostClientConfig, UpmetricsCostError, type UpmetricsCostRow, type UpmetricsCostSummary, type UpmetricsCostTimeseries, type UpmetricsSinkConfig, type Usage, VERSION, type VideoInput, type VisionInput, aiConfigSchema, anthropicAdapter, anthropicApiAdapter, anthropicSubprocessAdapter, azureAdapter, bflAdapter, bflCredits, chatInputSchema, computeCost, createAI, deepinfraAdapter, defaultProviders, discordSink, elevenlabsAdapter, embeddingInputSchema, falAdapter, falStubAdapter, freshUsage, fromProviderToolCall, geminiAdapter, getCostSummary, getPrice, httpTransport, imageInputSchema, listAzureDanishVoices, makeContracts, makeOpenAICompatibleAdapter, messageSchema, mistralAdapter, multiSink, noopSink, openaiAdapter, openaiStubAdapter, openrouterAdapter, parseClaudeCliJson, parseJsonLoose, refreshAvailability, requestyAdapter, resetRefreshState, resetRegistry, resolveAzureVoice, resolveTier, resolveVoice, sqliteBudgetStore, sqliteSink, streamTransport, stubProviders, subprocessTransport, tierSpecSchema, toProviderTools, toolSchema, translateInputSchema, upmetricsCostClient, upmetricsSink, usdFromMicro, visionInputSchema };
|
package/dist/index.js
CHANGED
|
@@ -6,6 +6,9 @@ import {
|
|
|
6
6
|
resolveModel,
|
|
7
7
|
setAvailability
|
|
8
8
|
} from "./chunk-HVZSYNZ5.js";
|
|
9
|
+
import {
|
|
10
|
+
getPrice
|
|
11
|
+
} from "./chunk-V5AQYES2.js";
|
|
9
12
|
|
|
10
13
|
// src/routing/tier-map.ts
|
|
11
14
|
var DEFAULT_TIER_MAP = {
|
|
@@ -214,101 +217,6 @@ function parseArgs(raw) {
|
|
|
214
217
|
return {};
|
|
215
218
|
}
|
|
216
219
|
|
|
217
|
-
// src/cost/pricing.ts
|
|
218
|
-
var V = "2026-06-02";
|
|
219
|
-
var MS = "2026-06-04-mistral.ai";
|
|
220
|
-
var PRICING = {
|
|
221
|
-
// Anthropic (direct API). DEFAULT_TIER_MAP: fast/cheap=haiku, smart/vision=sonnet, powerful=opus.
|
|
222
|
-
"anthropic:claude-haiku-4-5": {
|
|
223
|
-
inputPer1M: 0.8,
|
|
224
|
-
outputPer1M: 4,
|
|
225
|
-
cacheReadPer1M: 0.08,
|
|
226
|
-
cacheWritePer1M: 1,
|
|
227
|
-
version: V
|
|
228
|
-
},
|
|
229
|
-
"anthropic:claude-sonnet-4-6": {
|
|
230
|
-
inputPer1M: 3,
|
|
231
|
-
outputPer1M: 15,
|
|
232
|
-
cacheReadPer1M: 0.3,
|
|
233
|
-
cacheWritePer1M: 3.75,
|
|
234
|
-
version: V
|
|
235
|
-
},
|
|
236
|
-
"anthropic:claude-opus-4-8": {
|
|
237
|
-
inputPer1M: 15,
|
|
238
|
-
outputPer1M: 75,
|
|
239
|
-
cacheReadPer1M: 1.5,
|
|
240
|
-
cacheWritePer1M: 18.75,
|
|
241
|
-
version: V
|
|
242
|
-
},
|
|
243
|
-
// OpenAI. embedding default tier = text-embedding-3-small (no output tokens).
|
|
244
|
-
"openai:text-embedding-3-small": { inputPer1M: 0.02, outputPer1M: 0, version: V },
|
|
245
|
-
"openai:text-embedding-3-large": { inputPer1M: 0.13, outputPer1M: 0, version: V },
|
|
246
|
-
"openai:gpt-4o": { inputPer1M: 2.5, outputPer1M: 10, version: V },
|
|
247
|
-
"openai:gpt-4o-mini": { inputPer1M: 0.15, outputPer1M: 0.6, version: V },
|
|
248
|
-
// Whisper is priced per minute, not per token — not representable here; transcribe
|
|
249
|
-
// (F5.6) computes its own cost. Listed as 0 so token-based compute never charges it.
|
|
250
|
-
"openai:whisper-1": { inputPer1M: 0, outputPer1M: 0, version: V },
|
|
251
|
-
// OpenRouter (meta-router — model slugs include the upstream vendor). Slugs use
|
|
252
|
-
// dots (claude-sonnet-4.6) to match OpenRouter's live ids; the dashed forms
|
|
253
|
-
// never matched a real call. Caught by the F014 catalogue research.
|
|
254
|
-
"openrouter:anthropic/claude-sonnet-4.6": { inputPer1M: 3, outputPer1M: 15, version: V },
|
|
255
|
-
// OpenRouter ground-truth $1/$5 — a markup over Anthropic-direct's $0.8/$4
|
|
256
|
-
// (the `anthropic:` entry above). Was masked while the slug used dashes.
|
|
257
|
-
"openrouter:anthropic/claude-haiku-4.5": { inputPer1M: 1, outputPer1M: 5, version: "2026-06-04" },
|
|
258
|
-
"openrouter:google/gemini-2.5-flash": { inputPer1M: 0.3, outputPer1M: 2.5, version: V },
|
|
259
|
-
// Ground-truth from OpenRouter /api/v1/models (was a 0.3 estimate; now 0.279).
|
|
260
|
-
"openrouter:minimax/minimax-m2.7": {
|
|
261
|
-
inputPer1M: 0.279,
|
|
262
|
-
outputPer1M: 1.2,
|
|
263
|
-
version: "2026-06-04"
|
|
264
|
-
},
|
|
265
|
-
// DeepSeek V4 (CN-hosted — NOT GDPR-safe; non-personal-data workloads only).
|
|
266
|
-
// On 2026-05-22 DeepSeek made the "75% off" promo the permanent official price.
|
|
267
|
-
// V4-Pro $0.435/$0.87 is ~34x cheaper than GPT-5.5 on output; flash is cheaper
|
|
268
|
-
// still. Numbers match OpenRouter /api/v1/models 1:1 (no router markup). A strong
|
|
269
|
-
// cheap route for fleet background work once `claude -p` is API-billed (15 Jun).
|
|
270
|
-
"openrouter:deepseek/deepseek-v4-pro": { inputPer1M: 0.435, outputPer1M: 0.87, version: "2026-05-22-deepseek-official" },
|
|
271
|
-
"openrouter:deepseek/deepseek-v4-flash": { inputPer1M: 0.0983, outputPer1M: 0.1966, version: "2026-05-22-deepseek-official" },
|
|
272
|
-
// Google Gemini (direct). Provider key is "gemini" — matches the adapter's
|
|
273
|
-
// usage.provider + the override.provider callers pass. (Image-gen models are
|
|
274
|
-
// priced per-image in the adapter, not here.)
|
|
275
|
-
"gemini:gemini-2.5-flash": { inputPer1M: 0.3, outputPer1M: 2.5, version: V },
|
|
276
|
-
// flash-lite is the default `video` tier (F019) — cheap native video understanding.
|
|
277
|
-
"gemini:gemini-2.5-flash-lite": { inputPer1M: 0.1, outputPer1M: 0.4, version: "2026-06-04-or-xref" },
|
|
278
|
-
// Mistral (direct, La Plateforme). Official prices from mistral.ai/pricing
|
|
279
|
-
// (2026-06-04, per Christian's CD report). EU/Paris-hosted — the designated
|
|
280
|
-
// GDPR-safe provider for client/personal-data workloads (see F015). NB:
|
|
281
|
-
// medium-3.5 is the premium "Vibe" coding tier ($1.5/$7.5); Large 3 ($0.5/$1.5)
|
|
282
|
-
// is the cheaper frontier general-purpose model despite the higher number.
|
|
283
|
-
"mistral:mistral-large-latest": { inputPer1M: 0.5, outputPer1M: 1.5, version: MS },
|
|
284
|
-
"mistral:mistral-large-2512": { inputPer1M: 0.5, outputPer1M: 1.5, version: MS },
|
|
285
|
-
"mistral:mistral-medium-latest": { inputPer1M: 1.5, outputPer1M: 7.5, version: MS },
|
|
286
|
-
"mistral:mistral-medium-3.5": { inputPer1M: 1.5, outputPer1M: 7.5, version: MS },
|
|
287
|
-
"mistral:mistral-medium-3": { inputPer1M: 0.4, outputPer1M: 2, version: "2026-06-04-or-xref" },
|
|
288
|
-
"mistral:mistral-small-latest": { inputPer1M: 0.1, outputPer1M: 0.3, version: MS },
|
|
289
|
-
"mistral:mistral-small-2603": { inputPer1M: 0.1, outputPer1M: 0.3, version: MS },
|
|
290
|
-
"mistral:ministral-3b-latest": { inputPer1M: 0.1, outputPer1M: 0.1, version: MS },
|
|
291
|
-
"mistral:ministral-8b-latest": { inputPer1M: 0.15, outputPer1M: 0.15, version: MS },
|
|
292
|
-
"mistral:ministral-14b-latest": { inputPer1M: 0.2, outputPer1M: 0.2, version: MS },
|
|
293
|
-
"mistral:magistral-medium-latest": { inputPer1M: 2, outputPer1M: 5, version: MS },
|
|
294
|
-
"mistral:magistral-small-latest": { inputPer1M: 0.5, outputPer1M: 1.5, version: MS },
|
|
295
|
-
"mistral:devstral-latest": { inputPer1M: 0.4, outputPer1M: 2, version: MS },
|
|
296
|
-
"mistral:codestral-latest": { inputPer1M: 0.3, outputPer1M: 0.9, version: MS },
|
|
297
|
-
"mistral:open-mistral-nemo": { inputPer1M: 0.15, outputPer1M: 0.15, version: MS },
|
|
298
|
-
// Moderation (F016.4) — per input token; output 0. (OCR is per-page in the adapter.)
|
|
299
|
-
"mistral:mistral-moderation-latest": { inputPer1M: 0.1, outputPer1M: 0, version: MS },
|
|
300
|
-
// Embeddings (F016.5) — per input token.
|
|
301
|
-
"mistral:mistral-embed": { inputPer1M: 0.1, outputPer1M: 0, version: MS },
|
|
302
|
-
"mistral:codestral-embed": { inputPer1M: 0.15, outputPer1M: 0, version: MS }
|
|
303
|
-
};
|
|
304
|
-
function getPrice(provider, model) {
|
|
305
|
-
const exact = PRICING[`${provider}:${model}`];
|
|
306
|
-
if (exact) return exact;
|
|
307
|
-
const base = model.replace(/-\d{8}$/, "");
|
|
308
|
-
if (base !== model) return PRICING[`${provider}:${base}`];
|
|
309
|
-
return void 0;
|
|
310
|
-
}
|
|
311
|
-
|
|
312
220
|
// src/cost/usage.ts
|
|
313
221
|
function computeCost(provider, model, inputTokens, outputTokens, cacheReadTokens = 0, cacheCreationTokens = 0) {
|
|
314
222
|
const price = getPrice(provider, model);
|
|
@@ -1148,6 +1056,24 @@ function openrouterAdapter(config = {}) {
|
|
|
1148
1056
|
});
|
|
1149
1057
|
}
|
|
1150
1058
|
|
|
1059
|
+
// src/providers/requesty.ts
|
|
1060
|
+
var US_BASE = "https://router.requesty.ai/v1";
|
|
1061
|
+
var EU_BASE = "https://router.eu.requesty.ai/v1";
|
|
1062
|
+
function requestyAdapter(config = {}) {
|
|
1063
|
+
return makeOpenAICompatibleAdapter({
|
|
1064
|
+
name: "requesty",
|
|
1065
|
+
baseUrl: config.baseUrl ?? (config.eu ? EU_BASE : US_BASE),
|
|
1066
|
+
apiKey: config.apiKey,
|
|
1067
|
+
extraHeaders: {
|
|
1068
|
+
"HTTP-Referer": config.referer ?? "https://broberg.ai",
|
|
1069
|
+
"X-Title": config.title ?? "@broberg/ai-sdk"
|
|
1070
|
+
},
|
|
1071
|
+
// Requesty returns ground-truth usage.cost (USD) by default — use it over the
|
|
1072
|
+
// local pricing-table estimate (same as OpenRouter, F010).
|
|
1073
|
+
costFromResponseField: true
|
|
1074
|
+
});
|
|
1075
|
+
}
|
|
1076
|
+
|
|
1151
1077
|
// src/providers/mistral.ts
|
|
1152
1078
|
var MISTRAL_OCR_PRICE_PER_PAGE = 2e-3;
|
|
1153
1079
|
var VOXTRAL_PRICE_PER_MIN = {
|
|
@@ -1397,8 +1323,29 @@ function elevenlabsAdapter(config = {}) {
|
|
|
1397
1323
|
|
|
1398
1324
|
// src/providers/azure.ts
|
|
1399
1325
|
var AZURE_TTS_PRICE_PER_1K_CHARS = 0.016;
|
|
1326
|
+
var AZURE_STT_PRICE_PER_MIN = 0.0167;
|
|
1327
|
+
var DEFAULT_STT_API_VERSION = "2025-10-15";
|
|
1400
1328
|
var DEFAULT_REGION = "westeurope";
|
|
1401
1329
|
var DEFAULT_FORMAT = "audio-24khz-48kbitrate-mono-mp3";
|
|
1330
|
+
var AZURE_LOCALE_MAP = {
|
|
1331
|
+
da: "da-DK",
|
|
1332
|
+
en: "en-US",
|
|
1333
|
+
de: "de-DE",
|
|
1334
|
+
sv: "sv-SE",
|
|
1335
|
+
nb: "nb-NO",
|
|
1336
|
+
no: "nb-NO",
|
|
1337
|
+
fi: "fi-FI",
|
|
1338
|
+
nl: "nl-NL",
|
|
1339
|
+
fr: "fr-FR",
|
|
1340
|
+
es: "es-ES",
|
|
1341
|
+
it: "it-IT",
|
|
1342
|
+
pt: "pt-PT"
|
|
1343
|
+
};
|
|
1344
|
+
function toAzureLocale(lang) {
|
|
1345
|
+
if (!lang) return "da-DK";
|
|
1346
|
+
if (lang.includes("-")) return lang;
|
|
1347
|
+
return AZURE_LOCALE_MAP[lang.toLowerCase()] ?? lang;
|
|
1348
|
+
}
|
|
1402
1349
|
var AZURE_DANISH_VOICE_LIST = [
|
|
1403
1350
|
{ name: "christel", voiceId: "da-DK-ChristelNeural", gender: "female", display: "Christel", native: true, defaultRate: 0.85 },
|
|
1404
1351
|
{ name: "seraphina", voiceId: "de-DE-SeraphinaMultilingualNeural", gender: "female", display: "Seraphina", native: false },
|
|
@@ -1433,6 +1380,12 @@ function azureAdapter(config = {}) {
|
|
|
1433
1380
|
function region() {
|
|
1434
1381
|
return config.region ?? process.env.AZURE_SPEECH_REGION ?? DEFAULT_REGION;
|
|
1435
1382
|
}
|
|
1383
|
+
function sttBaseUrl() {
|
|
1384
|
+
if (config.sttBaseUrl) return config.sttBaseUrl.replace(/\/$/, "");
|
|
1385
|
+
const resource = config.resource ?? process.env.AZURE_SPEECH_RESOURCE;
|
|
1386
|
+
if (resource) return `https://${resource}.cognitiveservices.azure.com`;
|
|
1387
|
+
return `https://${region()}.api.cognitive.microsoft.com`;
|
|
1388
|
+
}
|
|
1436
1389
|
function priceFor(chars, model) {
|
|
1437
1390
|
const usage = freshUsage({
|
|
1438
1391
|
provider: "azure",
|
|
@@ -1472,7 +1425,40 @@ function azureAdapter(config = {}) {
|
|
|
1472
1425
|
const audio = new Uint8Array(await res.arrayBuffer());
|
|
1473
1426
|
return { audio, mimeType: "audio/mpeg", usage: priceFor(req.text.length, req.spec.model) };
|
|
1474
1427
|
}
|
|
1475
|
-
|
|
1428
|
+
async function transcribe(req) {
|
|
1429
|
+
const locale = toAzureLocale(req.language);
|
|
1430
|
+
const definition = { locales: [locale] };
|
|
1431
|
+
if (req.phrases && req.phrases.length > 0) {
|
|
1432
|
+
definition.phraseList = { phrases: req.phrases, biasingWeight: config.sttBiasingWeight ?? 1.5 };
|
|
1433
|
+
}
|
|
1434
|
+
const form = new FormData();
|
|
1435
|
+
form.append("audio", new Blob([req.audio]), "audio");
|
|
1436
|
+
form.append("definition", JSON.stringify(definition));
|
|
1437
|
+
const url = `${sttBaseUrl()}/speechtotext/transcriptions:transcribe?api-version=${config.sttApiVersion ?? DEFAULT_STT_API_VERSION}`;
|
|
1438
|
+
const res = await fetchImpl(url, {
|
|
1439
|
+
method: "POST",
|
|
1440
|
+
headers: { "Ocp-Apim-Subscription-Key": key() },
|
|
1441
|
+
body: form
|
|
1442
|
+
});
|
|
1443
|
+
if (!res.ok) {
|
|
1444
|
+
const body = await res.text().catch(() => "");
|
|
1445
|
+
throw new Error(`azure transcribe ${res.status}: ${body.slice(0, 300)}`);
|
|
1446
|
+
}
|
|
1447
|
+
const data = await res.json();
|
|
1448
|
+
const text = data.combinedPhrases?.[0]?.text ?? "";
|
|
1449
|
+
const minutes = data.durationMilliseconds != null ? data.durationMilliseconds / 6e4 : (req.durationSec ?? 0) / 60;
|
|
1450
|
+
const usage = freshUsage({
|
|
1451
|
+
provider: "azure",
|
|
1452
|
+
model: req.spec.model,
|
|
1453
|
+
transport: "http",
|
|
1454
|
+
capability: "transcribe",
|
|
1455
|
+
inputTokens: 0,
|
|
1456
|
+
outputTokens: 0
|
|
1457
|
+
});
|
|
1458
|
+
usage.costUsd = minutes * (config.sttPricePerMin ?? AZURE_STT_PRICE_PER_MIN);
|
|
1459
|
+
return { text, usage };
|
|
1460
|
+
}
|
|
1461
|
+
return { name: "azure", tts, transcribe };
|
|
1476
1462
|
}
|
|
1477
1463
|
|
|
1478
1464
|
// src/providers/fal.ts
|
|
@@ -1788,7 +1774,7 @@ function buildZip(files) {
|
|
|
1788
1774
|
}
|
|
1789
1775
|
|
|
1790
1776
|
// src/providers/bfl.ts
|
|
1791
|
-
var
|
|
1777
|
+
var EU_BASE2 = "https://api.eu.bfl.ai";
|
|
1792
1778
|
var BFL_CREDIT_USD = 0.01;
|
|
1793
1779
|
var BFL_IMAGE_PRICE = 0.06;
|
|
1794
1780
|
var sleep2 = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
@@ -1799,7 +1785,7 @@ async function bflCredits(opts = {}) {
|
|
|
1799
1785
|
const apiKey = opts.apiKey ?? process.env.BFL_API_KEY;
|
|
1800
1786
|
if (!apiKey) throw new Error("bflCredits: BFL_API_KEY not set");
|
|
1801
1787
|
const doFetch = opts.fetch ?? fetch;
|
|
1802
|
-
const res = await doFetch(`${opts.baseUrl ??
|
|
1788
|
+
const res = await doFetch(`${opts.baseUrl ?? EU_BASE2}/v1/credits`, { headers: { "x-key": apiKey } });
|
|
1803
1789
|
if (!res.ok) {
|
|
1804
1790
|
throw new Error(`bflCredits ${res.status}: ${(await res.text().catch(() => "")).slice(0, 200)}`);
|
|
1805
1791
|
}
|
|
@@ -1809,7 +1795,7 @@ async function bflCredits(opts = {}) {
|
|
|
1809
1795
|
}
|
|
1810
1796
|
function bflAdapter(config = {}) {
|
|
1811
1797
|
const doFetch = config.fetch ?? fetch;
|
|
1812
|
-
const base = config.baseUrl ??
|
|
1798
|
+
const base = config.baseUrl ?? EU_BASE2;
|
|
1813
1799
|
const pollIntervalMs = config.pollIntervalMs ?? 1500;
|
|
1814
1800
|
const timeoutMs = config.timeoutMs ?? 12e4;
|
|
1815
1801
|
const resolveKey = () => config.apiKey ?? process.env.BFL_API_KEY;
|
|
@@ -1900,6 +1886,7 @@ var defaultProviders = {
|
|
|
1900
1886
|
gemini: geminiAdapter(),
|
|
1901
1887
|
deepinfra: deepinfraAdapter(),
|
|
1902
1888
|
openrouter: openrouterAdapter(),
|
|
1889
|
+
requesty: requestyAdapter(),
|
|
1903
1890
|
mistral: mistralAdapter(),
|
|
1904
1891
|
elevenlabs: elevenlabsAdapter(),
|
|
1905
1892
|
azure: azureAdapter(),
|
|
@@ -2265,6 +2252,8 @@ var transcribeInputSchema = z.object({
|
|
|
2265
2252
|
language: z.string().optional(),
|
|
2266
2253
|
/** Audio length in seconds — enables Whisper per-minute cost. */
|
|
2267
2254
|
durationSec: z.number().positive().optional(),
|
|
2255
|
+
/** Bias toward brand/jargon terms (Azure phraseList, F029.3); others ignore it. */
|
|
2256
|
+
phrases: z.array(z.string()).optional(),
|
|
2268
2257
|
...callOptions
|
|
2269
2258
|
});
|
|
2270
2259
|
var ocrInputSchema = z.object({
|
|
@@ -2781,7 +2770,7 @@ function createAI(config = {}) {
|
|
|
2781
2770
|
invoke: async (spec) => {
|
|
2782
2771
|
const adapter = pickProvider(spec.provider);
|
|
2783
2772
|
if (!adapter.transcribe) throw new Error(`createAI: provider "${spec.provider}" does not support transcribe`);
|
|
2784
|
-
return adapter.transcribe({ audio, language: input.language, durationSec: input.durationSec, spec });
|
|
2773
|
+
return adapter.transcribe({ audio, language: input.language, durationSec: input.durationSec, phrases: input.phrases, spec });
|
|
2785
2774
|
}
|
|
2786
2775
|
});
|
|
2787
2776
|
},
|
|
@@ -2893,8 +2882,8 @@ var stubProviders = {
|
|
|
2893
2882
|
};
|
|
2894
2883
|
|
|
2895
2884
|
// src/version.ts
|
|
2896
|
-
var VERSION = "0.
|
|
2897
|
-
var SDK_TAG = "@broberg/ai-sdk@0.
|
|
2885
|
+
var VERSION = "0.20.0";
|
|
2886
|
+
var SDK_TAG = "@broberg/ai-sdk@0.20.0";
|
|
2898
2887
|
|
|
2899
2888
|
// src/availability/refresh.ts
|
|
2900
2889
|
var NOT_REFRESHED = { refreshed: false, checked: 0, markedUnavailable: [] };
|
|
@@ -3284,6 +3273,7 @@ export {
|
|
|
3284
3273
|
parseClaudeCliJson,
|
|
3285
3274
|
parseJsonLoose,
|
|
3286
3275
|
refreshAvailability,
|
|
3276
|
+
requestyAdapter,
|
|
3287
3277
|
resetRefreshState,
|
|
3288
3278
|
resetRegistry,
|
|
3289
3279
|
resolveAzureVoice,
|