@sixb/azure-ai-foundry 0.2.6 → 0.2.7

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.js CHANGED
@@ -5,7 +5,7 @@ import {
5
5
  MODEL_REASONING_LEVELS,
6
6
  ModelCatalogUnavailableError as ModelCatalogUnavailableError4,
7
7
  ModelProviderError as ModelProviderError7,
8
- UnsupportedModelFeatureError as UnsupportedModelFeatureError9
8
+ UnsupportedModelFeatureError as UnsupportedModelFeatureError10
9
9
  } from "@sixb/core/models";
10
10
  import { chatEvents } from "@sixb/model-protocols/chat";
11
11
  import { isStrictToolLimitError, messagesEvents } from "@sixb/model-protocols/messages";
@@ -39,19 +39,20 @@ function foundryUsage(raw, reliableReasoning) {
39
39
  const usage = responsesUsage(raw);
40
40
  const { reasoningOutputTokens, ...totals } = usage;
41
41
  const cached = usage.cacheReadInputTokens;
42
+ const written = counter(object(raw?.input_tokens_details)?.cache_write_tokens);
42
43
  const input = usage.inputTokens;
43
44
  const output = usage.outputTokens;
44
45
  const knownReasoning = reasoningOutputTokens !== undefined && output !== undefined && reasoningOutputTokens <= output && (reliableReasoning === true || reliableReasoning === undefined && reasoningOutputTokens > 0);
45
46
  return {
46
47
  ...totals,
47
- ...object(raw?.input_tokens_details)?.cache_write_tokens === 0 ? { cacheWriteInputTokens: 0 } : {},
48
- ...input !== undefined && cached !== undefined && cached <= input && onlyTokenMeters(raw) ? { uncachedInputTokens: input - cached } : {},
48
+ ...written === undefined ? {} : { cacheWriteInputTokens: written },
49
+ ...input !== undefined && cached !== undefined && cached + (written ?? 0) <= input && onlyTokenMeters(raw) ? { uncachedInputTokens: input - cached - (written ?? 0) } : {},
49
50
  ...knownReasoning ? { reasoningOutputTokens } : {},
50
51
  ...knownReasoning && reasoningOutputTokens !== undefined && output !== undefined && reasoningOutputTokens <= output && onlyTokenMeters(raw) ? { textOutputTokens: output - reasoningOutputTokens } : {}
51
52
  };
52
53
  }
53
54
  function foundryEstimator(card, request, modelName, modelVersion, aliases) {
54
- return tokenEstimator(card, request, ["temperature", "top_p", "metadata"], onlyTokenMeters, modelName, modelVersion, aliases);
55
+ return tokenEstimator(card, request, ["temperature", "top_p", "metadata", "prompt_cache_key", "prompt_cache_retention"], onlyTokenMeters, modelName, modelVersion, aliases);
55
56
  }
56
57
  function tokenEstimator(card, request, requestKeys, tokenMeters, modelName, modelVersion, aliases) {
57
58
  const rateCard = card && defineModelRateCard(card);
@@ -78,7 +79,38 @@ function onlyTokenMeters(raw) {
78
79
  "output_tokens_details"
79
80
  ].includes(key)))
80
81
  return false;
81
- return Object.entries(object(raw.input_tokens_details) ?? {}).every(([key, value]) => key === "cached_tokens" || key === "cache_write_tokens" && value === 0) && Object.keys(object(raw.output_tokens_details) ?? {}).every((key) => key === "reasoning_tokens");
82
+ return Object.entries(object(raw.input_tokens_details) ?? {}).every(([key, value]) => key === "cached_tokens" || key === "cache_write_tokens" || key === "cache_write_tokens_details" && defaultLifetimeWrites(value)) && Object.keys(object(raw.output_tokens_details) ?? {}).every((key) => key === "reasoning_tokens");
83
+ }
84
+ function defaultLifetimeWrites(details) {
85
+ const lifetimes = object(details);
86
+ return lifetimes !== undefined && Object.entries(lifetimes).every(([key, value]) => key === "ttl_30m_tokens" && counter(value) !== undefined || key === "ttl_12h_tokens" && value === 0);
87
+ }
88
+
89
+ // src/caching.ts
90
+ import { billsPromptCacheWrites } from "@sixb/model-protocols/responses";
91
+ var CACHING_FIELDS = ["prompt_cache_key", "prompt_cache_retention", "prompt_cache_options"];
92
+ var refusals = new Set;
93
+ function promptCaching(input) {
94
+ const { caching, deployment } = input;
95
+ const openai = deployment?.modelPublisher.toLowerCase() === "openai";
96
+ const billsWrites = openai && billsPromptCacheWrites(deployment.modelName);
97
+ const reusable = caching === "auto" || caching !== "off" && (input.localTools > 0 || input.messages.some((message) => message.role === "assistant"));
98
+ const intent = typeof caching === "object" ? caching : undefined;
99
+ const settings = {
100
+ ...intent?.key ? { prompt_cache_key: intent.key } : {},
101
+ ...!reusable && billsWrites ? { prompt_cache_options: { mode: "explicit" } } : {},
102
+ ...reusable && openai && !billsWrites && intent?.lifetime === "long" ? { prompt_cache_retention: "24h" } : {}
103
+ };
104
+ return Object.fromEntries(Object.entries(settings).filter(([field]) => !Object.hasOwn(input.request ?? {}, field) && !refusals.has(`${input.scope}\x00${field}`)));
105
+ }
106
+ function refusedCaching(error, body, request, scope) {
107
+ if (error.status !== 400)
108
+ return false;
109
+ const field = CACHING_FIELDS.find((name) => Object.hasOwn(body, name) && !Object.hasOwn(request ?? {}, name) && error.message.includes(name));
110
+ if (!field)
111
+ return false;
112
+ refusals.add(`${scope}\x00${field}`);
113
+ return true;
82
114
  }
83
115
 
84
116
  // src/catalog.ts
@@ -88,7 +120,11 @@ import {
88
120
  MODEL_REASONING_EFFORTS,
89
121
  ModelCatalogUnavailableError
90
122
  } from "@sixb/core/models";
91
- import { downloadModelsDev, modelsDevRateCard } from "@sixb/model-protocols/models-dev";
123
+ import {
124
+ downloadModelsDev,
125
+ modelsDevRateCard,
126
+ scaleTokenPrice
127
+ } from "@sixb/model-protocols/models-dev";
92
128
 
93
129
  // src/publisher.ts
94
130
  var publishers = {
@@ -278,7 +314,11 @@ function rates(raw, protocol) {
278
314
  if (protocol !== "messages" || card?.cacheWriteInput === undefined)
279
315
  return card;
280
316
  const { cacheWriteInput, ...rest } = card;
281
- return defineModelRateCard2({ ...rest, cacheWriteInput5m: cacheWriteInput });
317
+ return defineModelRateCard2({
318
+ ...rest,
319
+ cacheWriteInput5m: cacheWriteInput,
320
+ ...rest.input === undefined ? {} : { cacheWriteInput1h: scaleTokenPrice(rest.input, [2n, 1n]) }
321
+ });
282
322
  }
283
323
 
284
324
  // src/chat-accounting.ts
@@ -286,6 +326,7 @@ function foundryChatUsage(raw, reliableReasoning) {
286
326
  const input = counter(raw?.prompt_tokens);
287
327
  const output = counter(raw?.completion_tokens);
288
328
  const read = counter(object(raw?.prompt_tokens_details)?.cached_tokens);
329
+ const written = counter(object(raw?.prompt_tokens_details)?.cache_write_tokens);
289
330
  const reported = reasoningTokens(raw);
290
331
  const reasoning = reported !== undefined && reported !== false && (reliableReasoning === true || reliableReasoning === undefined && reported > 0) ? reported : undefined;
291
332
  const known = tokenMeters(raw);
@@ -293,15 +334,15 @@ function foundryChatUsage(raw, reliableReasoning) {
293
334
  ...input === undefined ? {} : { inputTokens: input },
294
335
  ...output === undefined ? {} : { outputTokens: output },
295
336
  ...read === undefined ? {} : { cacheReadInputTokens: read },
296
- ...object(raw?.prompt_tokens_details)?.cache_write_tokens === 0 ? { cacheWriteInputTokens: 0 } : {},
297
- ...input !== undefined && read !== undefined && read <= input && known ? { uncachedInputTokens: input - read } : {},
337
+ ...written === undefined ? {} : { cacheWriteInputTokens: written },
338
+ ...input !== undefined && read !== undefined && read + (written ?? 0) <= input && known ? { uncachedInputTokens: input - read - (written ?? 0) } : {},
298
339
  ...reasoning === undefined ? {} : { reasoningOutputTokens: reasoning },
299
340
  ...output !== undefined && reasoning !== undefined && reasoning <= output && known ? { textOutputTokens: output - reasoning } : {},
300
341
  ...raw ? { raw } : {}
301
342
  };
302
343
  }
303
344
  function foundryChatEstimator(card, request, modelName, modelVersion, aliases) {
304
- const estimator = tokenEstimator(card, request, ["temperature", "top_p", "metadata"], tokenMeters, modelName, modelVersion, aliases);
345
+ const estimator = tokenEstimator(card, request, ["temperature", "top_p", "metadata", "prompt_cache_key", "prompt_cache_retention"], tokenMeters, modelName, modelVersion, aliases);
305
346
  return {
306
347
  ...estimator.rateCard ? { rateCard: estimator.rateCard } : {},
307
348
  estimateReservation: estimator.estimateReservation,
@@ -327,9 +368,12 @@ function tokenMeters(raw) {
327
368
  if (!details)
328
369
  return false;
329
370
  for (const [meter, count] of Object.entries(details)) {
330
- if (key === "prompt_tokens_details" && meter === "cached_tokens" || key !== "prompt_tokens_details" && meter === "reasoning_tokens") {
371
+ if (key === "prompt_tokens_details" && (meter === "cached_tokens" || meter === "cache_write_tokens") || key !== "prompt_tokens_details" && meter === "reasoning_tokens") {
331
372
  if (counter(count) === undefined)
332
373
  return false;
374
+ } else if (key === "prompt_tokens_details" && meter === "cache_write_tokens_details") {
375
+ if (!defaultLifetimeWrites(count))
376
+ return false;
333
377
  } else if (key === "prompt_tokens_details" && meter === "image_tokens") {
334
378
  const image = counter(count);
335
379
  const input = counter(raw.prompt_tokens);
@@ -337,7 +381,7 @@ function tokenMeters(raw) {
337
381
  return false;
338
382
  } else if (![
339
383
  "audio_tokens",
340
- ...key === "prompt_tokens_details" ? ["cache_write_tokens"] : ["accepted_prediction_tokens", "rejected_prediction_tokens"]
384
+ ...key === "prompt_tokens_details" ? [] : ["accepted_prediction_tokens", "rejected_prediction_tokens"]
341
385
  ].includes(meter) || count !== 0)
342
386
  return false;
343
387
  }
@@ -526,8 +570,8 @@ function validateOptions(options) {
526
570
  throw new TypeError(`${PREFIX} Invalid reasoningSummary.`);
527
571
  }
528
572
  function responsesRequest(request, definition, options, scope, deployment) {
529
- const max = prepareRequest(request, definition, options, scope);
530
- const replayed = responsesInput(request.messages, definition.providerId, definition.modelId);
573
+ const { max, messages } = prepareRequest(request, definition, options, scope);
574
+ const replayed = responsesInput(messages, definition.providerId, definition.modelId);
531
575
  const input = replayed.map((item) => {
532
576
  if (!isJsonObject3(item))
533
577
  return item;
@@ -576,6 +620,14 @@ function responsesRequest(request, definition, options, scope, deployment) {
576
620
  stream: true,
577
621
  store: false,
578
622
  ...options.encryptedReasoning === false ? {} : { include: ["reasoning.encrypted_content"] },
623
+ ...promptCaching({
624
+ caching: request.caching,
625
+ messages: request.messages,
626
+ localTools: request.tools.length,
627
+ deployment,
628
+ request: options.request,
629
+ scope
630
+ }),
579
631
  ...max === undefined ? {} : { max_output_tokens: max },
580
632
  ...tools.length ? {
581
633
  tools,
@@ -603,28 +655,44 @@ function responsesRequest(request, definition, options, scope, deployment) {
603
655
  }
604
656
  function prepareRequest(request, definition, options, scope, remotePdf = false) {
605
657
  positiveInteger(request.maxOutputTokens, "maxOutputTokens");
606
- validateMessages(request.messages, definition, options.maxInputFileBytes ?? 20 * 1024 * 1024, scope, remotePdf);
658
+ validateMessages(request.messages, definition, options.maxInputFileBytes ?? 20 * 1024 * 1024, remotePdf);
607
659
  const limits = [
608
660
  definition.maxOutputTokens,
609
661
  options.maxOutputTokens,
610
662
  request.maxOutputTokens
611
663
  ].filter((n) => n !== undefined);
612
- return limits.length ? Math.min(...limits) : undefined;
664
+ return {
665
+ max: limits.length ? Math.min(...limits) : undefined,
666
+ messages: ownReplayState(request.messages, definition.providerId, scope)
667
+ };
613
668
  }
614
- function validateMessages(messages, definition, budget, scope, remotePdf = false) {
669
+ function ownReplayState(messages, providerId, scope) {
670
+ const foreign = (data) => data !== undefined && object(data)?.scope !== scope;
671
+ const own = (part) => {
672
+ if (!part.providerData || !foreign(part.providerData[providerId]))
673
+ return part;
674
+ const { [providerId]: _foreign, ...others } = part.providerData;
675
+ return { ...part, providerData: others };
676
+ };
677
+ return messages.map((message) => {
678
+ if (message.role === "system")
679
+ return own(message);
680
+ if (message.role === "user")
681
+ return { ...message, content: message.content.map(own) };
682
+ if (message.role === "tool")
683
+ return { ...message, content: message.content.map(own) };
684
+ return {
685
+ ...message,
686
+ content: message.content.flatMap((part) => part.type !== "provider-state" ? [own(part)] : part.providerId === providerId && foreign(part.data) ? [] : [part])
687
+ };
688
+ });
689
+ }
690
+ function validateMessages(messages, definition, budget, remotePdf = false) {
615
691
  let bytes = 0;
616
692
  for (const message of messages) {
617
- if (message.role === "system") {
618
- checkScope(message.providerData?.[definition.providerId], scope);
693
+ if (message.role === "system")
619
694
  continue;
620
- }
621
695
  for (const part of message.content) {
622
- if (part.type === "provider-state") {
623
- if (part.providerId === definition.providerId)
624
- checkScope(part.data, scope);
625
- continue;
626
- }
627
- checkScope(part.providerData?.[definition.providerId], scope);
628
696
  if (part.type !== "file")
629
697
  continue;
630
698
  const allowed = definition.capabilities.inputMediaTypes;
@@ -651,11 +719,6 @@ function validateMessages(messages, definition, budget, scope, remotePdf = false
651
719
  }
652
720
  }
653
721
  }
654
- function checkScope(data, scope) {
655
- if (data !== undefined && object(data)?.scope !== scope) {
656
- throw new UnsupportedModelFeatureError(`${PREFIX} Replay state belongs to a different endpoint, deployment, or protocol.`);
657
- }
658
- }
659
722
  function foundryStrictTool(tool) {
660
723
  if (!tool.strict)
661
724
  return;
@@ -703,8 +766,8 @@ function validateChatOptions(options) {
703
766
  if (options.includeUsage !== undefined && typeof options.includeUsage !== "boolean")
704
767
  throw new TypeError(`${PREFIX} includeUsage must be boolean.`);
705
768
  }
706
- function foundryChatRequest(request, definition, options, scope) {
707
- const max = prepareRequest(request, definition, options, scope);
769
+ function foundryChatRequest(request, definition, options, scope, deployment) {
770
+ const { max, messages } = prepareRequest(request, definition, options, scope);
708
771
  const profile = options.profile ?? "openai";
709
772
  if (profile !== "deepseek" && options.reasoningReplay === "tool-continuation")
710
773
  throw new UnsupportedModelFeatureError2(`${PREFIX} Reasoning-content replay requires the DeepSeek Chat profile.`);
@@ -736,7 +799,7 @@ function foundryChatRequest(request, definition, options, scope) {
736
799
  return {
737
800
  ...options.request,
738
801
  model: definition.modelId,
739
- messages: chatInput(request.messages, {
802
+ messages: chatInput(messages, {
740
803
  providerId: definition.providerId,
741
804
  errorPrefix: PREFIX,
742
805
  systemRole: options.systemRole,
@@ -744,6 +807,14 @@ function foundryChatRequest(request, definition, options, scope) {
744
807
  }),
745
808
  stream: true,
746
809
  ...options.includeUsage === false ? {} : { stream_options: { include_usage: true } },
810
+ ...promptCaching({
811
+ caching: request.caching,
812
+ messages: request.messages,
813
+ localTools: request.tools.length,
814
+ deployment,
815
+ request: options.request,
816
+ scope
817
+ }),
747
818
  ...max === undefined ? {} : { [options.maxTokensParameter ?? "max_completion_tokens"]: max },
748
819
  ...explicitReasoning && typeof reasoning === "string" ? { reasoning_effort: reasoning } : {},
749
820
  ...tools.length ? {
@@ -777,7 +848,8 @@ import { systemOneRequest, systemOneResult } from "@sixb/model-protocols/systemo
777
848
  // src/discovery.ts
778
849
  import {
779
850
  ModelCatalogUnavailableError as ModelCatalogUnavailableError2,
780
- ModelProviderError as ModelProviderError3
851
+ ModelProviderError as ModelProviderError3,
852
+ UnsupportedModelFeatureError as UnsupportedModelFeatureError3
781
853
  } from "@sixb/core/models";
782
854
 
783
855
  // src/diagnostics.ts
@@ -827,28 +899,38 @@ var ONE_SHOT = new Set([
827
899
  ]);
828
900
  var AUDIO_API_VERSION = "2024-10-21";
829
901
  var IMAGE_API_VERSION = "2025-04-01-preview";
902
+ var ENTRA_SCOPE = "https://ai.azure.com/.default";
903
+ var RENEW_BEFORE_EXPIRY_MS = 2 * 60000;
904
+ var EXPIRING_MS = 1000;
905
+ var RENEW_RETRY_MS = 3000;
906
+ var TOKEN_TIMEOUT_MS = 30000;
830
907
 
831
908
  class FoundryTransport {
832
909
  diagnostics = new WeakMap;
833
- baseUrl;
834
910
  projectUrl;
911
+ resourceUrl;
835
912
  options;
836
- constructor(options, target = "project") {
913
+ token;
914
+ renewal;
915
+ constructor(options) {
837
916
  if (!URL.canParse(options.endpoint))
838
- throw new TypeError(`${PREFIX} endpoint must be a valid ${target} URL.`);
917
+ throw new TypeError(`${PREFIX} endpoint must be a valid project URL.`);
839
918
  const url = new URL(options.endpoint);
840
919
  if (!["https:", "http:"].includes(url.protocol) || url.username || url.password || url.search || url.hash) {
841
- throw new TypeError(`${PREFIX} endpoint must be an HTTP(S) ${target} URL without credentials, query, or fragment.`);
920
+ throw new TypeError(`${PREFIX} endpoint must be an HTTP(S) project URL without credentials, query, or fragment.`);
842
921
  }
843
922
  const path = url.pathname.replace(/\/+$/, "");
844
- if (target === "project" && !/^\/api\/projects\/[^/]+$/.test(path))
923
+ if (!/^\/api\/projects\/[^/]+$/.test(path))
845
924
  throw new TypeError(`${PREFIX} endpoint must be a Foundry project URL: https://<resource>.services.ai.azure.com/api/projects/<project>.`);
846
- if (target === "resource" && path !== "" && path !== "/openai/v1")
847
- throw new TypeError(`${PREFIX} embeddings.endpoint must be a resource origin or /openai/v1 URL.`);
848
925
  this.projectUrl = `${url.origin}${path}`;
849
- this.baseUrl = target === "project" ? `${this.projectUrl}/openai/v1` : `${url.origin}/openai/v1`;
850
- if (typeof options.apiKey !== "function" && (typeof options.apiKey !== "string" || !options.apiKey.trim()))
851
- throw new TypeError(`${PREFIX} apiKey is required.`);
926
+ this.resourceUrl = url.origin;
927
+ if (options.credential !== undefined) {
928
+ if (options.apiKey !== undefined)
929
+ throw new TypeError(`${PREFIX} Configure either apiKey or credential, not both.`);
930
+ if (typeof options.credential?.getToken !== "function")
931
+ throw new TypeError(`${PREFIX} credential must have a getToken method, such as DefaultAzureCredential from @azure/identity.`);
932
+ } else if (typeof options.apiKey !== "function" && (typeof options.apiKey !== "string" || !options.apiKey.trim()))
933
+ throw new TypeError(`${PREFIX} apiKey or credential is required.`);
852
934
  if (options.maxRetries !== undefined && (!Number.isSafeInteger(options.maxRetries) || options.maxRetries < 0)) {
853
935
  throw new TypeError(`${PREFIX} maxRetries must be a nonnegative safe integer.`);
854
936
  }
@@ -916,35 +998,78 @@ class FoundryTransport {
916
998
  diagnostics.add(value);
917
999
  for (const reserved of ["authorization", "api-key", "x-api-key"])
918
1000
  if (headers.has(reserved))
919
- throw new TypeError(`${PREFIX} Use apiKey instead of '${reserved}' headers.`);
1001
+ throw new TypeError(`${PREFIX} Use apiKey or credential instead of '${reserved}' headers.`);
1002
+ if (this.options.credential) {
1003
+ const token = await this.bearerToken(signal);
1004
+ diagnostics.add(token);
1005
+ headers.set("authorization", `Bearer ${token}`);
1006
+ return headers;
1007
+ }
920
1008
  const key = await resolve(this.options.apiKey, signal);
921
1009
  if (typeof key !== "string" || !key.trim())
922
- throw new TypeError(`${PREFIX} apiKey must resolve to a nonempty string.`);
1010
+ throw new TypeError(`${PREFIX} apiKey must resolve to a nonempty string: pass apiKey or credential, or set AZURE_AI_FOUNDRY_API_KEY.`);
923
1011
  diagnostics.add(key);
924
1012
  headers.set(keyHeader, key);
925
1013
  return headers;
926
1014
  }
1015
+ bearerToken(signal) {
1016
+ const token = this.token;
1017
+ const now = Date.now();
1018
+ if (!token || now >= token.expiresAt - EXPIRING_MS)
1019
+ return abortable(() => this.renewToken(), signal);
1020
+ if (now >= token.renewAt)
1021
+ this.renewToken().catch(() => {
1022
+ if (this.token === token)
1023
+ this.token = { ...token, renewAt: Date.now() + RENEW_RETRY_MS };
1024
+ });
1025
+ return Promise.resolve(token.value);
1026
+ }
1027
+ renewToken() {
1028
+ this.renewal ??= (async () => {
1029
+ const controller = new AbortController;
1030
+ const timer = setTimeout(() => controller.abort(new Error(`${PREFIX} credential.getToken timed out.`)), TOKEN_TIMEOUT_MS);
1031
+ try {
1032
+ const signal = controller.signal;
1033
+ const token = await abortable(() => this.options.credential.getToken(ENTRA_SCOPE, { abortSignal: signal }), signal);
1034
+ if (typeof token?.token !== "string" || !token.token.trim())
1035
+ throw new TypeError(`${PREFIX} credential returned no token for ${ENTRA_SCOPE}.`);
1036
+ const expiresAt = token.expiresOnTimestamp ?? 0;
1037
+ this.token = {
1038
+ value: token.token,
1039
+ expiresAt,
1040
+ renewAt: Math.min(token.refreshAfterTimestamp ?? expiresAt, expiresAt - RENEW_BEFORE_EXPIRY_MS)
1041
+ };
1042
+ return token.token;
1043
+ } finally {
1044
+ clearTimeout(timer);
1045
+ this.renewal = undefined;
1046
+ }
1047
+ })();
1048
+ return this.renewal;
1049
+ }
927
1050
  fetch(url, init) {
928
1051
  return (this.options.fetch ?? fetch)(url, init);
929
1052
  }
930
1053
  url(protocol, deployment) {
931
- if (protocol === "embeddings")
932
- return `${this.baseUrl}/embeddings`;
1054
+ const resource = this.resourceUrl;
1055
+ const path = encodeURIComponent(deployment ?? "");
933
1056
  if (protocol === "transcription")
934
- return `${new URL(this.baseUrl).origin}/openai/deployments/${encodeURIComponent(deployment ?? "")}/audio/transcriptions?api-version=${AUDIO_API_VERSION}`;
935
- if (protocol === "decision")
936
- return `${new URL(this.baseUrl).origin}/providers/microsoft/v1/systemone`;
1057
+ return `${resource}/openai/deployments/${path}/audio/transcriptions?api-version=${AUDIO_API_VERSION}`;
937
1058
  if (protocol === "image" || protocol === "image-edit")
938
- return `${new URL(this.baseUrl).origin}/openai/deployments/${encodeURIComponent(deployment ?? "")}/images/${protocol === "image" ? "generations" : "edits"}?api-version=${IMAGE_API_VERSION}`;
1059
+ return `${resource}/openai/deployments/${path}/images/${protocol === "image" ? "generations" : "edits"}?api-version=${IMAGE_API_VERSION}`;
1060
+ if (protocol === "decision")
1061
+ return `${resource}/providers/microsoft/v1/systemone`;
939
1062
  if (protocol === "reranking")
940
- return `${new URL(this.baseUrl).origin}/providers/cohere/v2/rerank`;
1063
+ return `${resource}/providers/cohere/v2/rerank`;
1064
+ if (protocol === "messages")
1065
+ return `${resource}/anthropic/v1/messages`;
1066
+ if (protocol === "embeddings")
1067
+ return `${resource}/openai/v1/embeddings`;
941
1068
  if (protocol === "speech")
942
- return `${new URL(this.baseUrl).origin}/openai/v1/audio/speech`;
943
- if (protocol === "responses")
944
- return `${this.baseUrl}/responses`;
1069
+ return `${resource}/openai/v1/audio/speech`;
945
1070
  if (protocol === "chat")
946
- return `${this.baseUrl}/chat/completions`;
947
- return `${new URL(this.baseUrl).origin}/anthropic/v1/messages`;
1071
+ return `${resource}/openai/v1/chat/completions`;
1072
+ return `${resource}/openai/v1/responses`;
948
1073
  }
949
1074
  }
950
1075
  async function readJson(response, signal, maxBytes) {
@@ -1109,6 +1234,8 @@ class FoundryDeployments {
1109
1234
  const deployment = snapshot?.byName.get(name);
1110
1235
  if (!snapshot || !deployment)
1111
1236
  throw this.invalid(`Deployment '${name}' was not found in ${offline ? "cached project deployments; resolve online first" : "this project"}.`);
1237
+ if (deployment.connectionName)
1238
+ throw new UnsupportedModelFeatureError3(`${PREFIX} Deployment '${name}' comes from project connection '${deployment.connectionName}', on another resource. Configure a provider with that resource's project URL.`);
1112
1239
  return {
1113
1240
  deployment,
1114
1241
  discoveredAt: snapshot.fetchedAt
@@ -1332,7 +1459,7 @@ function deploymentRecord(raw, invalid) {
1332
1459
  }
1333
1460
 
1334
1461
  // src/kinds.ts
1335
- import { UnsupportedModelFeatureError as UnsupportedModelFeatureError3 } from "@sixb/core/models";
1462
+ import { UnsupportedModelFeatureError as UnsupportedModelFeatureError4 } from "@sixb/core/models";
1336
1463
  var KIND_BINDINGS = {
1337
1464
  language: "foundry() or foundry.chat()",
1338
1465
  embedding: "foundry.embedding()",
@@ -1360,16 +1487,11 @@ function deploymentKind(deployment) {
1360
1487
  function assertDeploymentKind(deployment, deploymentName, kind) {
1361
1488
  const actual = deploymentKind(deployment);
1362
1489
  if (actual !== kind)
1363
- throw new UnsupportedModelFeatureError3(`${PREFIX} Deployment '${deploymentName}' runs ${deployment.modelName}, not ${article(kind)} ${kind} model. Use ${KIND_BINDINGS[actual]}.`);
1364
- if (deployment.connectionName)
1365
- throw new UnsupportedModelFeatureError3(`${PREFIX} ${capitalize(article(kind))} ${kind} deployment from a project connection cannot be routed; use the owning resource's project URL and API key.`);
1490
+ throw new UnsupportedModelFeatureError4(`${PREFIX} Deployment '${deploymentName}' runs ${deployment.modelName}, not ${article(kind)} ${kind} model. Use ${KIND_BINDINGS[actual]}.`);
1366
1491
  }
1367
1492
  function article(kind) {
1368
1493
  return /^[aeiou]/.test(kind) ? "an" : "a";
1369
1494
  }
1370
- function capitalize(word) {
1371
- return word.charAt(0).toUpperCase() + word.slice(1);
1372
- }
1373
1495
  function isEmbeddingDeployment(deployment) {
1374
1496
  return deployment.capabilities.embeddings === "true" || deployment.capabilities.embedding === "true" || /^(text-embedding-|cohere-embed)/i.test(deployment.modelName);
1375
1497
  }
@@ -1491,7 +1613,7 @@ import {
1491
1613
  defineModelRateCard as defineModelRateCard4,
1492
1614
  EmbeddingModelResponseError,
1493
1615
  ModelCatalogUnavailableError as ModelCatalogUnavailableError3,
1494
- UnsupportedModelFeatureError as UnsupportedModelFeatureError4
1616
+ UnsupportedModelFeatureError as UnsupportedModelFeatureError5
1495
1617
  } from "@sixb/core/models";
1496
1618
  function createFoundryEmbedding(providerId, modelId, options, transport, deployments, catalog, resolution) {
1497
1619
  const dimensions = options.dimensions;
@@ -1590,7 +1712,7 @@ function validateDeployment(resolved, dimensions) {
1590
1712
  const name = deployment.modelName.toLowerCase();
1591
1713
  const maxDimensions = name === "text-embedding-3-small" ? 1536 : name === "text-embedding-3-large" ? 3072 : name === "text-embedding-ada-002" ? 1536 : undefined;
1592
1714
  if (deployment.modelPublisher.toLowerCase() !== "openai" || !maxDimensions || deployment.capabilities.embeddings === "false" || deployment.capabilities.embedding === "false")
1593
- throw new UnsupportedModelFeatureError4(`${PREFIX} This embedding deployment is not supported. Use an OpenAI text-embedding-3-small, text-embedding-3-large, or text-embedding-ada-002 deployment.`);
1715
+ throw new UnsupportedModelFeatureError5(`${PREFIX} This embedding deployment is not supported. Use an OpenAI text-embedding-3-small, text-embedding-3-large, or text-embedding-ada-002 deployment.`);
1594
1716
  const configurable = name !== "text-embedding-ada-002";
1595
1717
  if (dimensions > maxDimensions || !configurable && dimensions !== maxDimensions)
1596
1718
  throw new TypeError(`${PREFIX} ${name} requires ${configurable ? `1\u2013${maxDimensions}` : maxDimensions} dimensions.`);
@@ -1674,7 +1796,7 @@ import {
1674
1796
  estimateModelReservation as estimateModelReservation2,
1675
1797
  ImageModelResponseError,
1676
1798
  rateModelCall as rateModelCall2,
1677
- UnsupportedModelFeatureError as UnsupportedModelFeatureError5
1799
+ UnsupportedModelFeatureError as UnsupportedModelFeatureError6
1678
1800
  } from "@sixb/core/models";
1679
1801
  var MAX_RESPONSE_BYTES2 = 512 * 1024 * 1024;
1680
1802
  var MAX_TIMEOUT_MS2 = 2 ** 31 - 1;
@@ -1713,7 +1835,7 @@ function family(deployment) {
1713
1835
  };
1714
1836
  if (name === "flux-1.1-pro")
1715
1837
  return { gpt: false, definition: { maxImagesPerCall: 1 } };
1716
- throw new UnsupportedModelFeatureError5(`${PREFIX} ${deployment.modelName} is not supported: use a GPT Image, FLUX.1 Kontext [pro] or FLUX1.1 [pro] deployment.`);
1838
+ throw new UnsupportedModelFeatureError6(`${PREFIX} ${deployment.modelName} is not supported: use a GPT Image, FLUX.1 Kontext [pro] or FLUX1.1 [pro] deployment.`);
1717
1839
  }
1718
1840
  var gpt = (input, imageOutput, textOutput) => ({
1719
1841
  card: textOutput === undefined ? { currency: "USD", input, output: imageOutput } : { currency: "USD", input, output: textOutput, imageOutput },
@@ -2014,7 +2136,7 @@ function tokenMeters2(raw) {
2014
2136
  const tools = object(value);
2015
2137
  if (!tools || Object.entries(tools).some(([k, v]) => !["web_search_requests", "web_fetch_requests"].includes(k) || v !== 0))
2016
2138
  return false;
2017
- } else if (key === "service_tier" && value === "standard") {} else
2139
+ } else if (key === "service_tier" && value === "standard" || key === "speed" && value === "standard" || key === "inference_geo" && value === "global") {} else
2018
2140
  return false;
2019
2141
  }
2020
2142
  return true;
@@ -2023,10 +2145,11 @@ function tokenMeters2(raw) {
2023
2145
  // src/messages-request.ts
2024
2146
  import {
2025
2147
  modelReasoningSupportIssue as modelReasoningSupportIssue3,
2026
- UnsupportedModelFeatureError as UnsupportedModelFeatureError6
2148
+ UnsupportedModelFeatureError as UnsupportedModelFeatureError7
2027
2149
  } from "@sixb/core/models";
2028
2150
  import {
2029
2151
  messagesInput,
2152
+ messagesPromptCaching,
2030
2153
  messagesStrictTools,
2031
2154
  StrictToolRefusals,
2032
2155
  strictToolsKey
@@ -2141,11 +2264,11 @@ function validateMessagesOptions(options) {
2141
2264
  }
2142
2265
  }
2143
2266
  function foundryMessagesRequest(request, definition, options, scope, unconstrained = false) {
2144
- const max = prepareRequest(request, definition, options, scope, true);
2267
+ const { max, messages } = prepareRequest(request, definition, options, scope, true);
2145
2268
  let conversation = false;
2146
- for (const message of request.messages) {
2269
+ for (const message of messages) {
2147
2270
  if (message.role === "system" && conversation)
2148
- throw new UnsupportedModelFeatureError6(`${PREFIX} Messages system instructions must precede the conversation.`);
2271
+ throw new UnsupportedModelFeatureError7(`${PREFIX} Messages system instructions must precede the conversation.`);
2149
2272
  if (message.role !== "system")
2150
2273
  conversation = true;
2151
2274
  }
@@ -2153,14 +2276,14 @@ function foundryMessagesRequest(request, definition, options, scope, unconstrain
2153
2276
  throw new TypeError(`${PREFIX} Native Messages requires maxOutputTokens in the definition, binding, or request.`);
2154
2277
  const caps = definition.capabilities;
2155
2278
  if (request.tools.length && caps.localTools !== true)
2156
- throw new UnsupportedModelFeatureError6(`${PREFIX} Configure localTools capability before using Messages tools.`);
2279
+ throw new UnsupportedModelFeatureError7(`${PREFIX} Configure localTools capability before using Messages tools.`);
2157
2280
  const schema = request.responseFormat && messagesOutputSchema(request.responseFormat.schema);
2158
2281
  if (request.responseFormat && (caps.nativeStructuredOutput !== true || !schema))
2159
- throw new UnsupportedModelFeatureError6(`${PREFIX} Messages structured output requires a declared capability and a supported closed-object Claude schema.`);
2282
+ throw new UnsupportedModelFeatureError7(`${PREFIX} Messages structured output requires a declared capability and a supported closed-object Claude schema.`);
2160
2283
  const thinking = reasoningRequest(request, definition, options, max);
2161
2284
  if (thinking.thinking && object(thinking.thinking)?.type !== "disabled" && ["temperature", "top_p", "top_k"].some((key) => options.request?.[key] !== undefined))
2162
- throw new UnsupportedModelFeatureError6(`${PREFIX} Explicit sampling controls cannot be combined with Messages thinking.`);
2163
- const mapped = messagesInput(request.messages, definition.providerId, PREFIX);
2285
+ throw new UnsupportedModelFeatureError7(`${PREFIX} Explicit sampling controls cannot be combined with Messages thinking.`);
2286
+ const mapped = messagesInput(messages, definition.providerId, PREFIX);
2164
2287
  const output = {
2165
2288
  ...thinking.effort === undefined ? {} : { effort: thinking.effort },
2166
2289
  ...schema ? { format: { type: "json_schema", schema } } : {}
@@ -2175,7 +2298,7 @@ function foundryMessagesRequest(request, definition, options, scope, unconstrain
2175
2298
  const refused = unconstrained || key !== undefined && strictToolRefusals.has(key);
2176
2299
  const strict = chosen.map((choice) => choice && !refused);
2177
2300
  const strictTools = refused ? undefined : key;
2178
- const body = {
2301
+ const body = messagesPromptCaching({
2179
2302
  ...options.request,
2180
2303
  model: definition.modelId,
2181
2304
  messages: mapped.messages,
@@ -2191,9 +2314,12 @@ function foundryMessagesRequest(request, definition, options, scope, unconstrain
2191
2314
  input_schema: tool.inputSchema,
2192
2315
  ...strict[index] ? { strict: true } : {}
2193
2316
  })),
2194
- tool_choice: { type: "auto", disable_parallel_tool_use: caps.parallelToolCalls !== true }
2317
+ tool_choice: {
2318
+ type: "auto",
2319
+ disable_parallel_tool_use: caps.parallelToolCalls !== true
2320
+ }
2195
2321
  } : {}
2196
- };
2322
+ }, request.caching, request.tools.length);
2197
2323
  return { body, ...strictTools === undefined ? {} : { strictTools } };
2198
2324
  }
2199
2325
  function reasoningRequest(request, definition, options, max) {
@@ -2203,7 +2329,7 @@ function reasoningRequest(request, definition, options, max) {
2203
2329
  const caps = definition.capabilities.reasoning;
2204
2330
  const issue = modelReasoningSupportIssue3(caps, reasoning);
2205
2331
  if (caps === undefined || issue)
2206
- throw new UnsupportedModelFeatureError6(`${PREFIX} ${issue ?? "Configure reasoning capabilities for this deployment"}.`);
2332
+ throw new UnsupportedModelFeatureError7(`${PREFIX} ${issue ?? "Configure reasoning capabilities for this deployment"}.`);
2207
2333
  if (reasoning === "none") {
2208
2334
  return {
2209
2335
  thinking: { type: "disabled" }
@@ -2211,13 +2337,13 @@ function reasoningRequest(request, definition, options, max) {
2211
2337
  }
2212
2338
  if (typeof reasoning === "string") {
2213
2339
  if (reasoning === "minimal" || options.thinkingMode === "manual")
2214
- throw new UnsupportedModelFeatureError6(`${PREFIX} Named efforts require an adaptive-thinking Claude offering.`);
2340
+ throw new UnsupportedModelFeatureError7(`${PREFIX} Named efforts require an adaptive-thinking Claude offering.`);
2215
2341
  return { thinking: { type: "adaptive" }, effort: reasoning };
2216
2342
  }
2217
2343
  if (options.thinkingMode === "adaptive")
2218
- throw new UnsupportedModelFeatureError6(`${PREFIX} This Claude offering only supports adaptive thinking, not manual budgets.`);
2344
+ throw new UnsupportedModelFeatureError7(`${PREFIX} This Claude offering only supports adaptive thinking, not manual budgets.`);
2219
2345
  if (reasoning.budgetTokens < 1024 || reasoning.budgetTokens >= max)
2220
- throw new UnsupportedModelFeatureError6(`${PREFIX} Messages reasoning budget must be at least 1024 and below maxOutputTokens (${max}).`);
2346
+ throw new UnsupportedModelFeatureError7(`${PREFIX} Messages reasoning budget must be at least 1024 and below maxOutputTokens (${max}).`);
2221
2347
  return { thinking: { type: "enabled", budget_tokens: reasoning.budgetTokens } };
2222
2348
  }
2223
2349
 
@@ -2377,7 +2503,7 @@ import {
2377
2503
  defineLanguageModel as defineLanguageModel2,
2378
2504
  defineLanguageModelLabel,
2379
2505
  defineModelRateCard as defineModelRateCard7,
2380
- UnsupportedModelFeatureError as UnsupportedModelFeatureError7
2506
+ UnsupportedModelFeatureError as UnsupportedModelFeatureError8
2381
2507
  } from "@sixb/core/models";
2382
2508
  function resolveModel(input) {
2383
2509
  const { deployment, options } = input;
@@ -2392,12 +2518,10 @@ function resolveModel(input) {
2392
2518
  const entry = input.catalogModel;
2393
2519
  const deploymentPublisher = deployment && azurePublisher(deployment.modelPublisher);
2394
2520
  const publisher = deploymentPublisher?.id === "fireworks-ai" ? entry?.definition.publisher ?? deploymentPublisher : deploymentPublisher ?? entry?.definition.publisher;
2395
- const protocol = input.protocol ?? entry?.protocol ?? (deployment?.capabilities.responses === "true" ? "responses" : deployment?.capabilities.chatCompletion === "true" || deployment?.capabilities.chat_completion === "true" ? "chat" : deployment?.capabilities.messages === "true" ? "messages" : "responses");
2396
- if (protocol === "messages" && deployment?.connectionName)
2397
- throw new UnsupportedModelFeatureError7(`${PREFIX} Native Messages cannot route a deployment from a project connection; use the owning resource's project URL and API key.`);
2521
+ const protocol = input.protocol ?? (deployment ? publisherProtocol(deployment.modelPublisher) : "responses");
2398
2522
  const flag = deployment?.capabilities[protocol === "chat" ? "chatCompletion" : protocol] ?? (protocol === "chat" ? deployment?.capabilities.chat_completion : undefined);
2399
2523
  if (flag === "false")
2400
- throw new UnsupportedModelFeatureError7(`${PREFIX} Deployment '${input.modelId}' reports that ${protocol === "chat" ? "Chat" : protocol === "responses" ? "Responses" : "Messages"} is unsupported.`);
2524
+ throw new UnsupportedModelFeatureError8(`${PREFIX} Deployment '${input.modelId}' reports that ${protocol === "chat" ? "Chat" : protocol === "responses" ? "Responses" : "Messages"} is unsupported.`);
2401
2525
  const definition = defineLanguageModel2({
2402
2526
  ...entry?.definition,
2403
2527
  publisher,
@@ -2448,6 +2572,10 @@ function resolveModel(input) {
2448
2572
  ])
2449
2573
  };
2450
2574
  }
2575
+ function publisherProtocol(publisher) {
2576
+ const name = publisher.toLowerCase();
2577
+ return name === "openai" ? "responses" : name === "anthropic" ? "messages" : "chat";
2578
+ }
2451
2579
  function effectiveDefinition(definition, protocol, options) {
2452
2580
  const caps = definition.capabilities;
2453
2581
  const media = caps.inputMediaTypes;
@@ -2489,7 +2617,7 @@ import {
2489
2617
  defineModelRateCard as defineModelRateCard8,
2490
2618
  rateModelCall as rateModelCall4,
2491
2619
  SpeechModelResponseError,
2492
- UnsupportedModelFeatureError as UnsupportedModelFeatureError8
2620
+ UnsupportedModelFeatureError as UnsupportedModelFeatureError9
2493
2621
  } from "@sixb/core/models";
2494
2622
  var FORMATS2 = {
2495
2623
  "audio/mpeg": "mp3",
@@ -2559,7 +2687,7 @@ function speechBinding(providerId, modelId, settings, transport, deployments, re
2559
2687
  const resolved = await deployments.resolve(modelId, input?.offline === true);
2560
2688
  assertDeploymentKind(resolved.deployment, modelId, "speech");
2561
2689
  if (!/^gpt-4o-mini-tts$/i.test(resolved.deployment.modelName))
2562
- throw new UnsupportedModelFeatureError8(`${PREFIX} ${resolved.deployment.modelName} is not supported: deploy gpt-4o-mini-tts, which reports its usage.`);
2690
+ throw new UnsupportedModelFeatureError9(`${PREFIX} ${resolved.deployment.modelName} is not supported: deploy gpt-4o-mini-tts, which reports its usage.`);
2563
2691
  const rateCard = settings.costEstimator ? undefined : settings.rateCard ?? publishedRateCard2(resolved.deployment);
2564
2692
  return speechBinding(providerId, modelId, settings, transport, deployments, {
2565
2693
  ...resolved,
@@ -2941,19 +3069,23 @@ function transcriptionEstimator(rateCard) {
2941
3069
  }
2942
3070
 
2943
3071
  // src/provider.ts
2944
- function createAzureAIFoundry(options) {
2945
- const transport = new FoundryTransport(options);
3072
+ function createAzureAIFoundry(options = {}) {
3073
+ if ("embeddings" in options)
3074
+ throw new TypeError(`${PREFIX} Remove the embeddings option: embedding deployments are called on the project's resource with its credentials.`);
3075
+ const endpoint = options.endpoint ?? process.env.AZURE_AI_FOUNDRY_ENDPOINT;
3076
+ if (!endpoint)
3077
+ throw new TypeError(`${PREFIX} endpoint is required: pass the project endpoint or set AZURE_AI_FOUNDRY_ENDPOINT.`);
3078
+ const transport = new FoundryTransport({
3079
+ ...options,
3080
+ endpoint,
3081
+ ...options.credential || options.apiKey !== undefined ? {} : { apiKey: () => process.env.AZURE_AI_FOUNDRY_API_KEY }
3082
+ });
2946
3083
  const providerId = options.providerId ?? "azure-ai-foundry";
2947
3084
  if (!providerId.trim())
2948
3085
  throw new TypeError(`${PREFIX} providerId must not be empty.`);
2949
3086
  const deployments = new FoundryDeployments(providerId, transport, options.discovery);
2950
3087
  const modelCatalog = new RemoteModelsDevCatalog(options.catalog);
2951
- const embeddingTransport = options.embeddings ? new FoundryTransport(options.embeddings, "resource") : undefined;
2952
- const embedding = (name, input) => {
2953
- if (!embeddingTransport)
2954
- throw new TypeError(`${PREFIX} Configure embeddings.endpoint and embeddings.apiKey before declaring an embedding model.`);
2955
- return createFoundryEmbedding(providerId, name, input, embeddingTransport, deployments, modelCatalog);
2956
- };
3088
+ const embedding = (name, input) => createFoundryEmbedding(providerId, name, input, transport, deployments, modelCatalog);
2957
3089
  const model = (protocol, deploymentName, modelOptions) => {
2958
3090
  if (!deploymentName.trim() || deploymentName !== deploymentName.trim())
2959
3091
  throw new TypeError(`${PREFIX} deploymentName must be nonempty without surrounding whitespace.`);
@@ -2975,7 +3107,7 @@ function createAzureAIFoundry(options) {
2975
3107
  const results = [];
2976
3108
  for (const deployment of records) {
2977
3109
  const name = deployment.name;
2978
- if (deploymentKind(deployment) !== "language" || await modelCatalog.getEmbedding(deployment.modelName, true))
3110
+ if (deployment.connectionName || deploymentKind(deployment) !== "language" || await modelCatalog.getEmbedding(deployment.modelName, true))
2979
3111
  continue;
2980
3112
  try {
2981
3113
  const profile = resolveModel({
@@ -2987,11 +3119,12 @@ function createAzureAIFoundry(options) {
2987
3119
  catalogModel: lookup?.(deployment.modelName)
2988
3120
  });
2989
3121
  const flags = deployment.capabilities;
2990
- const supported = profile.metadata.catalog || (profile.protocol === "responses" ? flags?.responses === "true" : profile.protocol === "chat" ? flags?.chatCompletion === "true" || flags?.chat_completion === "true" : flags?.messages === "true");
3122
+ const offers = (offered) => offered === "chat" ? flags.chatCompletion === "true" || flags.chat_completion === "true" : flags[offered] === "true";
3123
+ const supported = profile.metadata.catalog || (protocol ? offers(protocol) : ["responses", "chat", "messages"].some(offers));
2991
3124
  if (supported)
2992
3125
  results.push(profile.definition);
2993
3126
  } catch (error) {
2994
- if (!(error instanceof UnsupportedModelFeatureError9))
3127
+ if (!(error instanceof UnsupportedModelFeatureError10))
2995
3128
  throw error;
2996
3129
  }
2997
3130
  }
@@ -3091,11 +3224,7 @@ class FoundryModel {
3091
3224
  ...structuredClone(serializable),
3092
3225
  ...costEstimator ? { costEstimator } : {}
3093
3226
  };
3094
- this.scope = JSON.stringify([
3095
- protocol === "messages" ? transport.url(protocol) : transport.baseUrl,
3096
- this.protocol,
3097
- modelId
3098
- ]);
3227
+ this.scope = JSON.stringify([transport.url(protocol), protocol, modelId]);
3099
3228
  this.reliableReasoning = options.reasoningUsage === "unknown" ? false : options.reasoningUsage === "reported" || this.metadata.publisher?.toLowerCase() === "openai" ? true : undefined;
3100
3229
  this.estimator = options.costEstimator ?? (protocol === "messages" ? foundryMessagesEstimator : protocol === "chat" ? foundryChatEstimator : foundryEstimator)(this.profile.rateCard, this.options.request, this.metadata.modelName, this.metadata.modelVersion, this.profile.aliases);
3101
3230
  Object.freeze(this);
@@ -3106,7 +3235,7 @@ class FoundryModel {
3106
3235
  const resolution = await this.deployments.resolve(this.modelId, options?.offline === true);
3107
3236
  const kind = deploymentKind(resolution.deployment);
3108
3237
  if (kind !== "language")
3109
- throw new UnsupportedModelFeatureError9(`${PREFIX} Use ${KIND_BINDINGS[kind]} for ${article(kind)} ${kind} deployment.`);
3238
+ throw new UnsupportedModelFeatureError10(`${PREFIX} Use ${KIND_BINDINGS[kind]} for ${article(kind)} ${kind} deployment.`);
3110
3239
  let catalogModel;
3111
3240
  try {
3112
3241
  catalogModel = await this.modelCatalog.get(resolution.deployment.modelName, options?.offline);
@@ -3118,7 +3247,7 @@ class FoundryModel {
3118
3247
  throw error;
3119
3248
  }
3120
3249
  if (await this.modelCatalog.getEmbedding(resolution.deployment.modelName, true))
3121
- throw new UnsupportedModelFeatureError9(`${PREFIX} Use foundry.embedding() for an embedding deployment.`);
3250
+ throw new UnsupportedModelFeatureError10(`${PREFIX} Use foundry.embedding() for an embedding deployment.`);
3122
3251
  return new FoundryModel(this.requestedProtocol, this.transport, this.deployments, this.providerId, this.modelId, this.options, this.modelCatalog, {
3123
3252
  ...resolution,
3124
3253
  catalogModel
@@ -3137,7 +3266,7 @@ class FoundryModel {
3137
3266
  const model = await abortable(() => this.#pendingExecution, request.signal);
3138
3267
  return model.stream(request);
3139
3268
  }
3140
- const response = this.protocol === "messages" ? await this.postMessages(request) : await this.transport.post(JSON.stringify(this.protocol === "chat" ? foundryChatRequest(request, this.definition, this.options, this.scope) : responsesRequest(request, this.definition, this.options, this.scope, this.resolution?.deployment)), request.signal, this.providerId, this.modelId, this.protocol);
3269
+ const response = this.protocol === "messages" ? await this.postMessages(request) : await this.postOpenAICompatible(request);
3141
3270
  const id = this.transport.redactText(response, requestId(response));
3142
3271
  if (!response.body)
3143
3272
  throw new ModelProviderError7(`${PREFIX} Provider returned an empty streaming response.`, this.providerId, this.modelId, { requestId: id, status: response.status });
@@ -3175,6 +3304,18 @@ class FoundryModel {
3175
3304
  }), response)
3176
3305
  };
3177
3306
  }
3307
+ async postOpenAICompatible(request) {
3308
+ const deployment = this.resolution?.deployment;
3309
+ for (let attempt = 0;; attempt++) {
3310
+ const body = this.protocol === "chat" ? foundryChatRequest(request, this.definition, this.options, this.scope, deployment) : responsesRequest(request, this.definition, this.options, this.scope, deployment);
3311
+ try {
3312
+ return await this.transport.post(JSON.stringify(body), request.signal, this.providerId, this.modelId, this.protocol);
3313
+ } catch (error) {
3314
+ if (attempt >= 3 || !(error instanceof ModelProviderError7) || !refusedCaching(error, body, this.options.request, this.scope))
3315
+ throw error;
3316
+ }
3317
+ }
3318
+ }
3178
3319
  async postMessages(request) {
3179
3320
  const prepared = foundryMessagesRequest(request, this.definition, this.options, this.scope);
3180
3321
  const post = (body) => this.transport.post(JSON.stringify(body), request.signal, this.providerId, this.modelId, "messages");
@@ -3217,4 +3358,4 @@ export {
3217
3358
  createAzureAIFoundry
3218
3359
  };
3219
3360
 
3220
- //# debugId=9B58BDA9107C694A64756E2164756E21
3361
+ //# debugId=31DEE47D5A3829A864756E2164756E21