@broberg/ai-sdk 0.19.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/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.19.0";
1949
- declare const SDK_TAG: "@broberg/ai-sdk@0.19.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
@@ -1056,6 +1056,24 @@ function openrouterAdapter(config = {}) {
1056
1056
  });
1057
1057
  }
1058
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
+
1059
1077
  // src/providers/mistral.ts
1060
1078
  var MISTRAL_OCR_PRICE_PER_PAGE = 2e-3;
1061
1079
  var VOXTRAL_PRICE_PER_MIN = {
@@ -1305,8 +1323,29 @@ function elevenlabsAdapter(config = {}) {
1305
1323
 
1306
1324
  // src/providers/azure.ts
1307
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";
1308
1328
  var DEFAULT_REGION = "westeurope";
1309
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
+ }
1310
1349
  var AZURE_DANISH_VOICE_LIST = [
1311
1350
  { name: "christel", voiceId: "da-DK-ChristelNeural", gender: "female", display: "Christel", native: true, defaultRate: 0.85 },
1312
1351
  { name: "seraphina", voiceId: "de-DE-SeraphinaMultilingualNeural", gender: "female", display: "Seraphina", native: false },
@@ -1341,6 +1380,12 @@ function azureAdapter(config = {}) {
1341
1380
  function region() {
1342
1381
  return config.region ?? process.env.AZURE_SPEECH_REGION ?? DEFAULT_REGION;
1343
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
+ }
1344
1389
  function priceFor(chars, model) {
1345
1390
  const usage = freshUsage({
1346
1391
  provider: "azure",
@@ -1380,7 +1425,40 @@ function azureAdapter(config = {}) {
1380
1425
  const audio = new Uint8Array(await res.arrayBuffer());
1381
1426
  return { audio, mimeType: "audio/mpeg", usage: priceFor(req.text.length, req.spec.model) };
1382
1427
  }
1383
- return { name: "azure", tts };
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 };
1384
1462
  }
1385
1463
 
1386
1464
  // src/providers/fal.ts
@@ -1696,7 +1774,7 @@ function buildZip(files) {
1696
1774
  }
1697
1775
 
1698
1776
  // src/providers/bfl.ts
1699
- var EU_BASE = "https://api.eu.bfl.ai";
1777
+ var EU_BASE2 = "https://api.eu.bfl.ai";
1700
1778
  var BFL_CREDIT_USD = 0.01;
1701
1779
  var BFL_IMAGE_PRICE = 0.06;
1702
1780
  var sleep2 = (ms) => new Promise((r) => setTimeout(r, ms));
@@ -1707,7 +1785,7 @@ async function bflCredits(opts = {}) {
1707
1785
  const apiKey = opts.apiKey ?? process.env.BFL_API_KEY;
1708
1786
  if (!apiKey) throw new Error("bflCredits: BFL_API_KEY not set");
1709
1787
  const doFetch = opts.fetch ?? fetch;
1710
- const res = await doFetch(`${opts.baseUrl ?? EU_BASE}/v1/credits`, { headers: { "x-key": apiKey } });
1788
+ const res = await doFetch(`${opts.baseUrl ?? EU_BASE2}/v1/credits`, { headers: { "x-key": apiKey } });
1711
1789
  if (!res.ok) {
1712
1790
  throw new Error(`bflCredits ${res.status}: ${(await res.text().catch(() => "")).slice(0, 200)}`);
1713
1791
  }
@@ -1717,7 +1795,7 @@ async function bflCredits(opts = {}) {
1717
1795
  }
1718
1796
  function bflAdapter(config = {}) {
1719
1797
  const doFetch = config.fetch ?? fetch;
1720
- const base = config.baseUrl ?? EU_BASE;
1798
+ const base = config.baseUrl ?? EU_BASE2;
1721
1799
  const pollIntervalMs = config.pollIntervalMs ?? 1500;
1722
1800
  const timeoutMs = config.timeoutMs ?? 12e4;
1723
1801
  const resolveKey = () => config.apiKey ?? process.env.BFL_API_KEY;
@@ -1808,6 +1886,7 @@ var defaultProviders = {
1808
1886
  gemini: geminiAdapter(),
1809
1887
  deepinfra: deepinfraAdapter(),
1810
1888
  openrouter: openrouterAdapter(),
1889
+ requesty: requestyAdapter(),
1811
1890
  mistral: mistralAdapter(),
1812
1891
  elevenlabs: elevenlabsAdapter(),
1813
1892
  azure: azureAdapter(),
@@ -2173,6 +2252,8 @@ var transcribeInputSchema = z.object({
2173
2252
  language: z.string().optional(),
2174
2253
  /** Audio length in seconds — enables Whisper per-minute cost. */
2175
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(),
2176
2257
  ...callOptions
2177
2258
  });
2178
2259
  var ocrInputSchema = z.object({
@@ -2689,7 +2770,7 @@ function createAI(config = {}) {
2689
2770
  invoke: async (spec) => {
2690
2771
  const adapter = pickProvider(spec.provider);
2691
2772
  if (!adapter.transcribe) throw new Error(`createAI: provider "${spec.provider}" does not support transcribe`);
2692
- 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 });
2693
2774
  }
2694
2775
  });
2695
2776
  },
@@ -2801,8 +2882,8 @@ var stubProviders = {
2801
2882
  };
2802
2883
 
2803
2884
  // src/version.ts
2804
- var VERSION = "0.19.0";
2805
- var SDK_TAG = "@broberg/ai-sdk@0.19.0";
2885
+ var VERSION = "0.20.0";
2886
+ var SDK_TAG = "@broberg/ai-sdk@0.20.0";
2806
2887
 
2807
2888
  // src/availability/refresh.ts
2808
2889
  var NOT_REFRESHED = { refreshed: false, checked: 0, markedUnavailable: [] };
@@ -3192,6 +3273,7 @@ export {
3192
3273
  parseClaudeCliJson,
3193
3274
  parseJsonLoose,
3194
3275
  refreshAvailability,
3276
+ requestyAdapter,
3195
3277
  resetRefreshState,
3196
3278
  resetRegistry,
3197
3279
  resolveAzureVoice,