@jerome-benoit/sap-ai-provider-v2 4.9.1 → 5.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/README.md +114 -66
  2. package/dist/{chunk-5ZKQJNHO.js → chunk-2KOXKYVT.js} +482 -220
  3. package/dist/chunk-2KOXKYVT.js.map +1 -0
  4. package/dist/{chunk-5EDF6MHL.js → chunk-643USI3B.js} +8 -7
  5. package/dist/chunk-643USI3B.js.map +1 -0
  6. package/dist/{chunk-VHZSAQBJ.js → chunk-AFZC2DH2.js} +2 -2
  7. package/dist/chunk-AFZC2DH2.js.map +1 -0
  8. package/dist/{chunk-5JVF4555.js → chunk-JRUSQTKB.js} +3 -3
  9. package/dist/{chunk-4JIMBRMV.js → chunk-MF3VO3ER.js} +154 -20
  10. package/dist/chunk-MF3VO3ER.js.map +1 -0
  11. package/dist/{chunk-RJFB6VFO.js → chunk-U23M3VYO.js} +2 -2
  12. package/dist/{foundation-models-embedding-model-strategy-VKBRG7RT.js → foundation-models-embedding-model-strategy-2GUADNXT.js} +4 -4
  13. package/dist/{foundation-models-language-model-strategy-FBGKZSTU.js → foundation-models-language-model-strategy-5AYZ5KHA.js} +5 -5
  14. package/dist/index.cjs +712 -352
  15. package/dist/index.cjs.map +1 -1
  16. package/dist/index.d.cts +1680 -34
  17. package/dist/index.d.ts +1680 -34
  18. package/dist/index.js +13 -14
  19. package/dist/index.js.map +1 -1
  20. package/dist/{orchestration-embedding-model-strategy-DVPO2TP3.js → orchestration-embedding-model-strategy-F7WHDLX7.js} +5 -5
  21. package/dist/{orchestration-language-model-strategy-KEJWB4E2.js → orchestration-language-model-strategy-Z72AFW62.js} +42 -78
  22. package/dist/orchestration-language-model-strategy-Z72AFW62.js.map +1 -0
  23. package/package.json +30 -22
  24. package/dist/chunk-4JIMBRMV.js.map +0 -1
  25. package/dist/chunk-5EDF6MHL.js.map +0 -1
  26. package/dist/chunk-5ZKQJNHO.js.map +0 -1
  27. package/dist/chunk-VHZSAQBJ.js.map +0 -1
  28. package/dist/orchestration-language-model-strategy-KEJWB4E2.js.map +0 -1
  29. /package/dist/{chunk-5JVF4555.js.map → chunk-JRUSQTKB.js.map} +0 -0
  30. /package/dist/{chunk-RJFB6VFO.js.map → chunk-U23M3VYO.js.map} +0 -0
  31. /package/dist/{foundation-models-embedding-model-strategy-VKBRG7RT.js.map → foundation-models-embedding-model-strategy-2GUADNXT.js.map} +0 -0
  32. /package/dist/{foundation-models-language-model-strategy-FBGKZSTU.js.map → foundation-models-language-model-strategy-5AYZ5KHA.js.map} +0 -0
  33. /package/dist/{orchestration-embedding-model-strategy-DVPO2TP3.js.map → orchestration-embedding-model-strategy-F7WHDLX7.js.map} +0 -0
package/dist/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import { EmbeddingModelV2, SharedV2ProviderOptions, SharedV2ProviderMetadata, SharedV2Headers, LanguageModelV2, LanguageModelV2CallOptions, LanguageModelV2Content, LanguageModelV2FinishReason, LanguageModelV2ResponseMetadata, LanguageModelV2Usage, LanguageModelV2CallWarning, LanguageModelV2StreamPart, ProviderV2, ImageModelV2 } from '@ai-sdk/provider';
2
1
  import { DeploymentIdConfig, ResourceGroupConfig } from '@sap-ai-sdk/ai-api/internal.js';
3
2
  import { CustomRequestConfig } from '@sap-ai-sdk/core';
4
3
  export { CustomRequestConfig } from '@sap-ai-sdk/core';
@@ -7,6 +6,7 @@ export { HttpDestinationOrFetchOptions } from '@sap-cloud-sdk/connectivity';
7
6
  import { AzureOpenAiChatCompletionParameters } from '@sap-ai-sdk/foundation-models';
8
7
  import { OrchestrationConfigRefOverride, OrchestrationModuleConfig, FilteringModule, GroundingModule, MaskingModule, OrchestrationConfigRefById, OrchestrationConfigRefByName, ChatCompletionTool, TranslationModule, ChatModel } from '@sap-ai-sdk/orchestration';
9
8
  export { AssistantChatMessage, ChatCompletionRequest, ChatCompletionTool, ChatMessage, ChatMessageContent, ChatMessages, Citation, DeveloperChatMessage, DocumentTranslationApplyToSelector, FileContent, FilteringModule, FunctionObject, GroundingModule, ImageContentUrl, LlmModelDetails, LlmModelParams, MaskingModule, OrchestrationClient, OrchestrationConfigRef, OrchestrationConfigRefById, OrchestrationConfigRefByName, OrchestrationConfigRefOverride, OrchestrationEmbeddingClient, OrchestrationEmbeddingResponse, OrchestrationError, OrchestrationErrorResponse, OrchestrationModuleConfig, OrchestrationModuleConfigList, OrchestrationResponse, OrchestrationStream, OrchestrationStreamChunkResponse, OrchestrationStreamResponse, PromptTemplatingModule, SystemChatMessage, ToolChatMessage, TranslationApplyToCategory, TranslationInputParameters, TranslationModule, TranslationOutputParameters, TranslationTargetLanguage, UserChatMessage, UserChatMessageContent, UserChatMessageContentItem, buildAzureContentSafetyFilter, buildDocumentGroundingConfig, buildDpiMaskingProvider, buildLlamaGuard38BFilter, buildTranslationConfig } from '@sap-ai-sdk/orchestration';
9
+ import { SharedV3Warning, LanguageModelV3StreamPart, LanguageModelV2 as LanguageModelV2$1, LanguageModelV2CallOptions as LanguageModelV2CallOptions$1, LanguageModelV3CallOptions } from '@ai-sdk/provider';
10
10
  import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
11
11
  import { InferSchema } from '@ai-sdk/provider-utils';
12
12
 
@@ -15,7 +15,7 @@ declare const SAP_AI_PROVIDER_NAME: "sap-ai";
15
15
  /**
16
16
  * Extracts the provider name from a provider identifier (e.g., "sap-ai.chat" → "sap-ai").
17
17
  * @param providerIdentifier - The full provider identifier string.
18
- * @returns The provider name without any suffix.
18
+ * @returns The prefix before the first dot, or the unchanged identifier when no dot exists.
19
19
  */
20
20
  declare function getProviderName(providerIdentifier: string): string;
21
21
  /** @internal */
@@ -81,7 +81,6 @@ type SAPAIEmbeddingProviderOptions = InferSchema<typeof sapAIEmbeddingProviderOp
81
81
  declare function escapeOrchestrationPlaceholders(text: string): string;
82
82
  /**
83
83
  * Reverses escaping by removing zero-width spaces from template delimiters.
84
- *
85
84
  * Useful for processing model responses that may contain escaped delimiters.
86
85
  * @param text - The text to unescape.
87
86
  * @returns The unescaped text with zero-width spaces removed.
@@ -89,13 +88,1602 @@ declare function escapeOrchestrationPlaceholders(text: string): string;
89
88
  */
90
89
  declare function unescapeOrchestrationPlaceholders(text: string): string;
91
90
 
91
+ // ==================================================================================================
92
+ // JSON Schema Draft 07
93
+ // ==================================================================================================
94
+ // https://tools.ietf.org/html/draft-handrews-json-schema-validation-01
95
+ // --------------------------------------------------------------------------------------------------
96
+
97
+ /**
98
+ * Primitive type
99
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.1.1
100
+ */
101
+ type JSONSchema7TypeName =
102
+ | "string" //
103
+ | "number"
104
+ | "integer"
105
+ | "boolean"
106
+ | "object"
107
+ | "array"
108
+ | "null";
109
+
110
+ /**
111
+ * Primitive type
112
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.1.1
113
+ */
114
+ type JSONSchema7Type =
115
+ | string //
116
+ | number
117
+ | boolean
118
+ | JSONSchema7Object
119
+ | JSONSchema7Array
120
+ | null;
121
+
122
+ // Workaround for infinite type recursion
123
+ interface JSONSchema7Object {
124
+ [key: string]: JSONSchema7Type;
125
+ }
126
+
127
+ // Workaround for infinite type recursion
128
+ // https://github.com/Microsoft/TypeScript/issues/3496#issuecomment-128553540
129
+ interface JSONSchema7Array extends Array<JSONSchema7Type> {}
130
+
131
+ /**
132
+ * Meta schema
133
+ *
134
+ * Recommended values:
135
+ * - 'http://json-schema.org/schema#'
136
+ * - 'http://json-schema.org/hyper-schema#'
137
+ * - 'http://json-schema.org/draft-07/schema#'
138
+ * - 'http://json-schema.org/draft-07/hyper-schema#'
139
+ *
140
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-5
141
+ */
142
+ type JSONSchema7Version = string;
143
+
144
+ /**
145
+ * JSON Schema v7
146
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01
147
+ */
148
+ type JSONSchema7Definition = JSONSchema7 | boolean;
149
+ interface JSONSchema7 {
150
+ $id?: string | undefined;
151
+ $ref?: string | undefined;
152
+ $schema?: JSONSchema7Version | undefined;
153
+ $comment?: string | undefined;
154
+
155
+ /**
156
+ * @see https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-00#section-8.2.4
157
+ * @see https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-validation-00#appendix-A
158
+ */
159
+ $defs?: {
160
+ [key: string]: JSONSchema7Definition;
161
+ } | undefined;
162
+
163
+ /**
164
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.1
165
+ */
166
+ type?: JSONSchema7TypeName | JSONSchema7TypeName[] | undefined;
167
+ enum?: JSONSchema7Type[] | undefined;
168
+ const?: JSONSchema7Type | undefined;
169
+
170
+ /**
171
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.2
172
+ */
173
+ multipleOf?: number | undefined;
174
+ maximum?: number | undefined;
175
+ exclusiveMaximum?: number | undefined;
176
+ minimum?: number | undefined;
177
+ exclusiveMinimum?: number | undefined;
178
+
179
+ /**
180
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.3
181
+ */
182
+ maxLength?: number | undefined;
183
+ minLength?: number | undefined;
184
+ pattern?: string | undefined;
185
+
186
+ /**
187
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.4
188
+ */
189
+ items?: JSONSchema7Definition | JSONSchema7Definition[] | undefined;
190
+ additionalItems?: JSONSchema7Definition | undefined;
191
+ maxItems?: number | undefined;
192
+ minItems?: number | undefined;
193
+ uniqueItems?: boolean | undefined;
194
+ contains?: JSONSchema7Definition | undefined;
195
+
196
+ /**
197
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.5
198
+ */
199
+ maxProperties?: number | undefined;
200
+ minProperties?: number | undefined;
201
+ required?: string[] | undefined;
202
+ properties?: {
203
+ [key: string]: JSONSchema7Definition;
204
+ } | undefined;
205
+ patternProperties?: {
206
+ [key: string]: JSONSchema7Definition;
207
+ } | undefined;
208
+ additionalProperties?: JSONSchema7Definition | undefined;
209
+ dependencies?: {
210
+ [key: string]: JSONSchema7Definition | string[];
211
+ } | undefined;
212
+ propertyNames?: JSONSchema7Definition | undefined;
213
+
214
+ /**
215
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.6
216
+ */
217
+ if?: JSONSchema7Definition | undefined;
218
+ then?: JSONSchema7Definition | undefined;
219
+ else?: JSONSchema7Definition | undefined;
220
+
221
+ /**
222
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.7
223
+ */
224
+ allOf?: JSONSchema7Definition[] | undefined;
225
+ anyOf?: JSONSchema7Definition[] | undefined;
226
+ oneOf?: JSONSchema7Definition[] | undefined;
227
+ not?: JSONSchema7Definition | undefined;
228
+
229
+ /**
230
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-7
231
+ */
232
+ format?: string | undefined;
233
+
234
+ /**
235
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-8
236
+ */
237
+ contentMediaType?: string | undefined;
238
+ contentEncoding?: string | undefined;
239
+
240
+ /**
241
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-9
242
+ */
243
+ definitions?: {
244
+ [key: string]: JSONSchema7Definition;
245
+ } | undefined;
246
+
247
+ /**
248
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-10
249
+ */
250
+ title?: string | undefined;
251
+ description?: string | undefined;
252
+ default?: JSONSchema7Type | undefined;
253
+ readOnly?: boolean | undefined;
254
+ writeOnly?: boolean | undefined;
255
+ examples?: JSONSchema7Type | undefined;
256
+ }
257
+
258
+ type SharedV2Headers = Record<string, string>;
259
+
260
+ /**
261
+ A JSON value can be a string, number, boolean, object, array, or null.
262
+ JSON values can be serialized and deserialized by the JSON.stringify and JSON.parse methods.
263
+ */
264
+ type JSONValue = null | string | number | boolean | JSONObject | JSONArray;
265
+ type JSONObject = {
266
+ [key: string]: JSONValue;
267
+ };
268
+ type JSONArray = JSONValue[];
269
+
270
+ /**
271
+ * Additional provider-specific metadata.
272
+ * Metadata are additional outputs from the provider.
273
+ * They are passed through to the provider from the AI SDK
274
+ * and enable provider-specific functionality
275
+ * that can be fully encapsulated in the provider.
276
+ *
277
+ * This enables us to quickly ship provider-specific functionality
278
+ * without affecting the core AI SDK.
279
+ *
280
+ * The outer record is keyed by the provider name, and the inner
281
+ * record is keyed by the provider-specific metadata key.
282
+ *
283
+ * ```ts
284
+ * {
285
+ * "anthropic": {
286
+ * "cacheControl": { "type": "ephemeral" }
287
+ * }
288
+ * }
289
+ * ```
290
+ */
291
+ type SharedV2ProviderMetadata = Record<string, Record<string, JSONValue>>;
292
+
293
+ /**
294
+ * Additional provider-specific options.
295
+ * Options are additional input to the provider.
296
+ * They are passed through to the provider from the AI SDK
297
+ * and enable provider-specific functionality
298
+ * that can be fully encapsulated in the provider.
299
+ *
300
+ * This enables us to quickly ship provider-specific functionality
301
+ * without affecting the core AI SDK.
302
+ *
303
+ * The outer record is keyed by the provider name, and the inner
304
+ * record is keyed by the provider-specific metadata key.
305
+ *
306
+ * ```ts
307
+ * {
308
+ * "anthropic": {
309
+ * "cacheControl": { "type": "ephemeral" }
310
+ * }
311
+ * }
312
+ * ```
313
+ */
314
+ type SharedV2ProviderOptions = Record<string, Record<string, JSONValue>>;
315
+
316
+ /**
317
+ An embedding is a vector, i.e. an array of numbers.
318
+ It is e.g. used to represent a text as a vector of word embeddings.
319
+ */
320
+ type EmbeddingModelV2Embedding = Array<number>;
321
+
322
+ /**
323
+ Specification for an embedding model that implements the embedding model
324
+ interface version 1.
325
+
326
+ VALUE is the type of the values that the model can embed.
327
+ This will allow us to go beyond text embeddings in the future,
328
+ e.g. to support image embeddings
329
+ */
330
+ type EmbeddingModelV2<VALUE> = {
331
+ /**
332
+ The embedding model must specify which embedding model interface
333
+ version it implements. This will allow us to evolve the embedding
334
+ model interface and retain backwards compatibility. The different
335
+ implementation versions can be handled as a discriminated union
336
+ on our side.
337
+ */
338
+ readonly specificationVersion: 'v2';
339
+ /**
340
+ Name of the provider for logging purposes.
341
+ */
342
+ readonly provider: string;
343
+ /**
344
+ Provider-specific model ID for logging purposes.
345
+ */
346
+ readonly modelId: string;
347
+ /**
348
+ Limit of how many embeddings can be generated in a single API call.
349
+
350
+ Use Infinity for models that do not have a limit.
351
+ */
352
+ readonly maxEmbeddingsPerCall: PromiseLike<number | undefined> | number | undefined;
353
+ /**
354
+ True if the model can handle multiple embedding calls in parallel.
355
+ */
356
+ readonly supportsParallelCalls: PromiseLike<boolean> | boolean;
357
+ /**
358
+ Generates a list of embeddings for the given input text.
359
+
360
+ Naming: "do" prefix to prevent accidental direct usage of the method
361
+ by the user.
362
+ */
363
+ doEmbed(options: {
364
+ /**
365
+ List of values to embed.
366
+ */
367
+ values: Array<VALUE>;
368
+ /**
369
+ Abort signal for cancelling the operation.
370
+ */
371
+ abortSignal?: AbortSignal;
372
+ /**
373
+ Additional provider-specific options. They are passed through
374
+ to the provider from the AI SDK and enable provider-specific
375
+ functionality that can be fully encapsulated in the provider.
376
+ */
377
+ providerOptions?: SharedV2ProviderOptions;
378
+ /**
379
+ Additional HTTP headers to be sent with the request.
380
+ Only applicable for HTTP-based providers.
381
+ */
382
+ headers?: Record<string, string | undefined>;
383
+ }): PromiseLike<{
384
+ /**
385
+ Generated embeddings. They are in the same order as the input values.
386
+ */
387
+ embeddings: Array<EmbeddingModelV2Embedding>;
388
+ /**
389
+ Token usage. We only have input tokens for embeddings.
390
+ */
391
+ usage?: {
392
+ tokens: number;
393
+ };
394
+ /**
395
+ Additional provider-specific metadata. They are passed through
396
+ from the provider to the AI SDK and enable provider-specific
397
+ results that can be fully encapsulated in the provider.
398
+ */
399
+ providerMetadata?: SharedV2ProviderMetadata;
400
+ /**
401
+ Optional response information for debugging purposes.
402
+ */
403
+ response?: {
404
+ /**
405
+ Response headers.
406
+ */
407
+ headers?: SharedV2Headers;
408
+ /**
409
+ The response body.
410
+ */
411
+ body?: unknown;
412
+ };
413
+ }>;
414
+ };
415
+
416
+ type ImageModelV2CallOptions = {
417
+ /**
418
+ Prompt for the image generation.
419
+ */
420
+ prompt: string;
421
+ /**
422
+ Number of images to generate.
423
+ */
424
+ n: number;
425
+ /**
426
+ Size of the images to generate.
427
+ Must have the format `{width}x{height}`.
428
+ `undefined` will use the provider's default size.
429
+ */
430
+ size: `${number}x${number}` | undefined;
431
+ /**
432
+ Aspect ratio of the images to generate.
433
+ Must have the format `{width}:{height}`.
434
+ `undefined` will use the provider's default aspect ratio.
435
+ */
436
+ aspectRatio: `${number}:${number}` | undefined;
437
+ /**
438
+ Seed for the image generation.
439
+ `undefined` will use the provider's default seed.
440
+ */
441
+ seed: number | undefined;
442
+ /**
443
+ Additional provider-specific options that are passed through to the provider
444
+ as body parameters.
445
+
446
+ The outer record is keyed by the provider name, and the inner
447
+ record is keyed by the provider-specific metadata key.
448
+ ```ts
449
+ {
450
+ "openai": {
451
+ "style": "vivid"
452
+ }
453
+ }
454
+ ```
455
+ */
456
+ providerOptions: SharedV2ProviderOptions;
457
+ /**
458
+ Abort signal for cancelling the operation.
459
+ */
460
+ abortSignal?: AbortSignal;
461
+ /**
462
+ Additional HTTP headers to be sent with the request.
463
+ Only applicable for HTTP-based providers.
464
+ */
465
+ headers?: Record<string, string | undefined>;
466
+ };
467
+
468
+ /**
469
+ Warning from the model provider for this call. The call will proceed, but e.g.
470
+ some settings might not be supported, which can lead to suboptimal results.
471
+ */
472
+ type ImageModelV2CallWarning = {
473
+ type: 'unsupported-setting';
474
+ setting: keyof ImageModelV2CallOptions;
475
+ details?: string;
476
+ } | {
477
+ type: 'other';
478
+ message: string;
479
+ };
480
+
481
+ type ImageModelV2ProviderMetadata = Record<string, {
482
+ images: JSONArray;
483
+ } & JSONValue>;
484
+ type GetMaxImagesPerCallFunction = (options: {
485
+ modelId: string;
486
+ }) => PromiseLike<number | undefined> | number | undefined;
487
+ /**
488
+ Image generation model specification version 2.
489
+ */
490
+ type ImageModelV2 = {
491
+ /**
492
+ The image model must specify which image model interface
493
+ version it implements. This will allow us to evolve the image
494
+ model interface and retain backwards compatibility. The different
495
+ implementation versions can be handled as a discriminated union
496
+ on our side.
497
+ */
498
+ readonly specificationVersion: 'v2';
499
+ /**
500
+ Name of the provider for logging purposes.
501
+ */
502
+ readonly provider: string;
503
+ /**
504
+ Provider-specific model ID for logging purposes.
505
+ */
506
+ readonly modelId: string;
507
+ /**
508
+ Limit of how many images can be generated in a single API call.
509
+ Can be set to a number for a fixed limit, to undefined to use
510
+ the global limit, or a function that returns a number or undefined,
511
+ optionally as a promise.
512
+ */
513
+ readonly maxImagesPerCall: number | undefined | GetMaxImagesPerCallFunction;
514
+ /**
515
+ Generates an array of images.
516
+ */
517
+ doGenerate(options: ImageModelV2CallOptions): PromiseLike<{
518
+ /**
519
+ Generated images as base64 encoded strings or binary data.
520
+ The images should be returned without any unnecessary conversion.
521
+ If the API returns base64 encoded strings, the images should be returned
522
+ as base64 encoded strings. If the API returns binary data, the images should
523
+ be returned as binary data.
524
+ */
525
+ images: Array<string> | Array<Uint8Array>;
526
+ /**
527
+ Whether an unsuccessful result, such as an empty image result, can be
528
+ retried. When omitted, the result is unclassified.
529
+ */
530
+ isRetryable?: boolean;
531
+ /**
532
+ Warnings for the call, e.g. unsupported settings.
533
+ */
534
+ warnings: Array<ImageModelV2CallWarning>;
535
+ /**
536
+ Additional provider-specific metadata. They are passed through
537
+ from the provider to the AI SDK and enable provider-specific
538
+ results that can be fully encapsulated in the provider.
539
+
540
+ The outer record is keyed by the provider name, and the inner
541
+ record is provider-specific metadata. It always includes an
542
+ `images` key with image-specific metadata
543
+
544
+ ```ts
545
+ {
546
+ "openai": {
547
+ "images": ["revisedPrompt": "Revised prompt here."]
548
+ }
549
+ }
550
+ ```
551
+ */
552
+ providerMetadata?: ImageModelV2ProviderMetadata;
553
+ /**
554
+ Response information for telemetry and debugging purposes.
555
+ */
556
+ response: {
557
+ /**
558
+ Timestamp for the start of the generated response.
559
+ */
560
+ timestamp: Date;
561
+ /**
562
+ The ID of the response model that was used to generate the response.
563
+ */
564
+ modelId: string;
565
+ /**
566
+ Response headers.
567
+ */
568
+ headers: Record<string, string> | undefined;
569
+ };
570
+ }>;
571
+ };
572
+
573
+ /**
574
+ A tool has a name, a description, and a set of parameters.
575
+
576
+ Note: this is **not** the user-facing tool definition. The AI SDK methods will
577
+ map the user-facing tool definitions to this format.
578
+ */
579
+ type LanguageModelV2FunctionTool = {
580
+ /**
581
+ The type of the tool (always 'function').
582
+ */
583
+ type: 'function';
584
+ /**
585
+ The name of the tool. Unique within this model call.
586
+ */
587
+ name: string;
588
+ /**
589
+ A description of the tool. The language model uses this to understand the
590
+ tool's purpose and to provide better completion suggestions.
591
+ */
592
+ description?: string;
593
+ /**
594
+ The parameters that the tool expects. The language model uses this to
595
+ understand the tool's input requirements and to provide matching suggestions.
596
+ */
597
+ inputSchema: JSONSchema7;
598
+ /**
599
+ The provider-specific options for the tool.
600
+ */
601
+ providerOptions?: SharedV2ProviderOptions;
602
+ };
603
+
604
+ /**
605
+ Data content. Can be a Uint8Array, base64 encoded data as a string or a URL.
606
+ */
607
+ type LanguageModelV2DataContent = Uint8Array | string | URL;
608
+
609
+ /**
610
+ A prompt is a list of messages.
611
+
612
+ Note: Not all models and prompt formats support multi-modal inputs and
613
+ tool calls. The validation happens at runtime.
614
+
615
+ Note: This is not a user-facing prompt. The AI SDK methods will map the
616
+ user-facing prompt types such as chat or instruction prompts to this format.
617
+ */
618
+ type LanguageModelV2Prompt = Array<LanguageModelV2Message>;
619
+ type LanguageModelV2Message = ({
620
+ role: 'system';
621
+ content: string;
622
+ } | {
623
+ role: 'user';
624
+ content: Array<LanguageModelV2TextPart | LanguageModelV2FilePart>;
625
+ } | {
626
+ role: 'assistant';
627
+ content: Array<LanguageModelV2TextPart | LanguageModelV2FilePart | LanguageModelV2ReasoningPart | LanguageModelV2ToolCallPart | LanguageModelV2ToolResultPart>;
628
+ } | {
629
+ role: 'tool';
630
+ content: Array<LanguageModelV2ToolResultPart>;
631
+ }) & {
632
+ /**
633
+ * Additional provider-specific options. They are passed through
634
+ * to the provider from the AI SDK and enable provider-specific
635
+ * functionality that can be fully encapsulated in the provider.
636
+ */
637
+ providerOptions?: SharedV2ProviderOptions;
638
+ };
639
+ /**
640
+ Text content part of a prompt. It contains a string of text.
641
+ */
642
+ interface LanguageModelV2TextPart {
643
+ type: 'text';
644
+ /**
645
+ The text content.
646
+ */
647
+ text: string;
648
+ /**
649
+ * Additional provider-specific options. They are passed through
650
+ * to the provider from the AI SDK and enable provider-specific
651
+ * functionality that can be fully encapsulated in the provider.
652
+ */
653
+ providerOptions?: SharedV2ProviderOptions;
654
+ }
655
+ /**
656
+ Reasoning content part of a prompt. It contains a string of reasoning text.
657
+ */
658
+ interface LanguageModelV2ReasoningPart {
659
+ type: 'reasoning';
660
+ /**
661
+ The reasoning text.
662
+ */
663
+ text: string;
664
+ /**
665
+ * Additional provider-specific options. They are passed through
666
+ * to the provider from the AI SDK and enable provider-specific
667
+ * functionality that can be fully encapsulated in the provider.
668
+ */
669
+ providerOptions?: SharedV2ProviderOptions;
670
+ }
671
+ /**
672
+ File content part of a prompt. It contains a file.
673
+ */
674
+ interface LanguageModelV2FilePart {
675
+ type: 'file';
676
+ /**
677
+ * Optional filename of the file.
678
+ */
679
+ filename?: string;
680
+ /**
681
+ File data. Can be a Uint8Array, base64 encoded data as a string or a URL.
682
+ */
683
+ data: LanguageModelV2DataContent;
684
+ /**
685
+ IANA media type of the file.
686
+
687
+ Can support wildcards, e.g. `image/*` (in which case the provider needs to take appropriate action).
688
+
689
+ @see https://www.iana.org/assignments/media-types/media-types.xhtml
690
+ */
691
+ mediaType: string;
692
+ /**
693
+ * Additional provider-specific options. They are passed through
694
+ * to the provider from the AI SDK and enable provider-specific
695
+ * functionality that can be fully encapsulated in the provider.
696
+ */
697
+ providerOptions?: SharedV2ProviderOptions;
698
+ }
699
+ /**
700
+ Tool call content part of a prompt. It contains a tool call (usually generated by the AI model).
701
+ */
702
+ interface LanguageModelV2ToolCallPart {
703
+ type: 'tool-call';
704
+ /**
705
+ ID of the tool call. This ID is used to match the tool call with the tool result.
706
+ */
707
+ toolCallId: string;
708
+ /**
709
+ Name of the tool that is being called.
710
+ */
711
+ toolName: string;
712
+ /**
713
+ Arguments of the tool call. This is a JSON-serializable object that matches the tool's input schema.
714
+ */
715
+ input: unknown;
716
+ /**
717
+ * Whether the tool call will be executed by the provider.
718
+ * If this flag is not set or is false, the tool call will be executed by the client.
719
+ */
720
+ providerExecuted?: boolean;
721
+ /**
722
+ * Additional provider-specific options. They are passed through
723
+ * to the provider from the AI SDK and enable provider-specific
724
+ * functionality that can be fully encapsulated in the provider.
725
+ */
726
+ providerOptions?: SharedV2ProviderOptions;
727
+ }
728
+ /**
729
+ Tool result content part of a prompt. It contains the result of the tool call with the matching ID.
730
+ */
731
+ interface LanguageModelV2ToolResultPart {
732
+ type: 'tool-result';
733
+ /**
734
+ ID of the tool call that this result is associated with.
735
+ */
736
+ toolCallId: string;
737
+ /**
738
+ Name of the tool that generated this result.
739
+ */
740
+ toolName: string;
741
+ /**
742
+ Result of the tool call.
743
+ */
744
+ output: LanguageModelV2ToolResultOutput;
745
+ /**
746
+ * Additional provider-specific options. They are passed through
747
+ * to the provider from the AI SDK and enable provider-specific
748
+ * functionality that can be fully encapsulated in the provider.
749
+ */
750
+ providerOptions?: SharedV2ProviderOptions;
751
+ }
752
+ type LanguageModelV2ToolResultOutput = {
753
+ type: 'text';
754
+ value: string;
755
+ } | {
756
+ type: 'json';
757
+ value: JSONValue;
758
+ } | {
759
+ type: 'error-text';
760
+ value: string;
761
+ } | {
762
+ type: 'error-json';
763
+ value: JSONValue;
764
+ } | {
765
+ type: 'content';
766
+ value: Array<{
767
+ type: 'text';
768
+ /**
769
+ Text content.
770
+ */
771
+ text: string;
772
+ } | {
773
+ type: 'media';
774
+ /**
775
+ Base-64 encoded media data.
776
+ */
777
+ data: string;
778
+ /**
779
+ IANA media type.
780
+ @see https://www.iana.org/assignments/media-types/media-types.xhtml
781
+ */
782
+ mediaType: string;
783
+ }>;
784
+ };
785
+
786
+ /**
787
+ The configuration of a tool that is defined by the provider.
788
+ */
789
+ type LanguageModelV2ProviderDefinedTool = {
790
+ /**
791
+ The type of the tool (always 'provider-defined').
792
+ */
793
+ type: 'provider-defined';
794
+ /**
795
+ The ID of the tool. Should follow the format `<provider-name>.<unique-tool-name>`.
796
+ */
797
+ id: `${string}.${string}`;
798
+ /**
799
+ The name of the tool that the user must use in the tool set.
800
+ */
801
+ name: string;
802
+ /**
803
+ The arguments for configuring the tool. Must match the expected arguments defined by the provider for this tool.
804
+ */
805
+ args: Record<string, unknown>;
806
+ };
807
+
808
+ type LanguageModelV2ToolChoice = {
809
+ type: 'auto';
810
+ } | {
811
+ type: 'none';
812
+ } | {
813
+ type: 'required';
814
+ } | {
815
+ type: 'tool';
816
+ toolName: string;
817
+ };
818
+
819
+ type LanguageModelV2CallOptions = {
820
+ /**
821
+ A language mode prompt is a standardized prompt type.
822
+
823
+ Note: This is **not** the user-facing prompt. The AI SDK methods will map the
824
+ user-facing prompt types such as chat or instruction prompts to this format.
825
+ That approach allows us to evolve the user facing prompts without breaking
826
+ the language model interface.
827
+ */
828
+ prompt: LanguageModelV2Prompt;
829
+ /**
830
+ Maximum number of tokens to generate.
831
+ */
832
+ maxOutputTokens?: number;
833
+ /**
834
+ Temperature setting. The range depends on the provider and model.
835
+ */
836
+ temperature?: number;
837
+ /**
838
+ Stop sequences.
839
+ If set, the model will stop generating text when one of the stop sequences is generated.
840
+ Providers may have limits on the number of stop sequences.
841
+ */
842
+ stopSequences?: string[];
843
+ /**
844
+ Nucleus sampling.
845
+ */
846
+ topP?: number;
847
+ /**
848
+ Only sample from the top K options for each subsequent token.
849
+
850
+ Used to remove "long tail" low probability responses.
851
+ Recommended for advanced use cases only. You usually only need to use temperature.
852
+ */
853
+ topK?: number;
854
+ /**
855
+ Presence penalty setting. It affects the likelihood of the model to
856
+ repeat information that is already in the prompt.
857
+ */
858
+ presencePenalty?: number;
859
+ /**
860
+ Frequency penalty setting. It affects the likelihood of the model
861
+ to repeatedly use the same words or phrases.
862
+ */
863
+ frequencyPenalty?: number;
864
+ /**
865
+ Response format. The output can either be text or JSON. Default is text.
866
+
867
+ If JSON is selected, a schema can optionally be provided to guide the LLM.
868
+ */
869
+ responseFormat?: {
870
+ type: 'text';
871
+ } | {
872
+ type: 'json';
873
+ /**
874
+ * JSON schema that the generated output should conform to.
875
+ */
876
+ schema?: JSONSchema7;
877
+ /**
878
+ * Name of output that should be generated. Used by some providers for additional LLM guidance.
879
+ */
880
+ name?: string;
881
+ /**
882
+ * Description of the output that should be generated. Used by some providers for additional LLM guidance.
883
+ */
884
+ description?: string;
885
+ };
886
+ /**
887
+ The seed (integer) to use for random sampling. If set and supported
888
+ by the model, calls will generate deterministic results.
889
+ */
890
+ seed?: number;
891
+ /**
892
+ The tools that are available for the model.
893
+ */
894
+ tools?: Array<LanguageModelV2FunctionTool | LanguageModelV2ProviderDefinedTool>;
895
+ /**
896
+ Specifies how the tool should be selected. Defaults to 'auto'.
897
+ */
898
+ toolChoice?: LanguageModelV2ToolChoice;
899
+ /**
900
+ Include raw chunks in the stream. Only applicable for streaming calls.
901
+ */
902
+ includeRawChunks?: boolean;
903
+ /**
904
+ Abort signal for cancelling the operation.
905
+ */
906
+ abortSignal?: AbortSignal;
907
+ /**
908
+ Additional HTTP headers to be sent with the request.
909
+ Only applicable for HTTP-based providers.
910
+ */
911
+ headers?: Record<string, string | undefined>;
912
+ /**
913
+ * Additional provider-specific options. They are passed through
914
+ * to the provider from the AI SDK and enable provider-specific
915
+ * functionality that can be fully encapsulated in the provider.
916
+ */
917
+ providerOptions?: SharedV2ProviderOptions;
918
+ };
919
+
920
+ /**
921
+ Warning from the model provider for this call. The call will proceed, but e.g.
922
+ some settings might not be supported, which can lead to suboptimal results.
923
+ */
924
+ type LanguageModelV2CallWarning = {
925
+ type: 'unsupported-setting';
926
+ setting: Omit<keyof LanguageModelV2CallOptions, 'prompt'>;
927
+ details?: string;
928
+ } | {
929
+ type: 'unsupported-tool';
930
+ tool: LanguageModelV2FunctionTool | LanguageModelV2ProviderDefinedTool;
931
+ details?: string;
932
+ } | {
933
+ type: 'other';
934
+ message: string;
935
+ };
936
+
937
+ /**
938
+ A file that has been generated by the model.
939
+ Generated files as base64 encoded strings or binary data.
940
+ The files should be returned without any unnecessary conversion.
941
+ */
942
+ type LanguageModelV2File = {
943
+ type: 'file';
944
+ /**
945
+ The IANA media type of the file, e.g. `image/png` or `audio/mp3`.
946
+
947
+ @see https://www.iana.org/assignments/media-types/media-types.xhtml
948
+ */
949
+ mediaType: string;
950
+ /**
951
+ Generated file data as base64 encoded strings or binary data.
952
+
953
+ The file data should be returned without any unnecessary conversion.
954
+ If the API returns base64 encoded strings, the file data should be returned
955
+ as base64 encoded strings. If the API returns binary data, the file data should
956
+ be returned as binary data.
957
+ */
958
+ data: string | Uint8Array;
959
+ };
960
+
961
+ /**
962
+ Reasoning that the model has generated.
963
+ */
964
+ type LanguageModelV2Reasoning = {
965
+ type: 'reasoning';
966
+ text: string;
967
+ /**
968
+ * Optional provider-specific metadata for the reasoning part.
969
+ */
970
+ providerMetadata?: SharedV2ProviderMetadata;
971
+ };
972
+
973
+ /**
974
+ A source that has been used as input to generate the response.
975
+ */
976
+ type LanguageModelV2Source = {
977
+ type: 'source';
978
+ /**
979
+ * The type of source - URL sources reference web content.
980
+ */
981
+ sourceType: 'url';
982
+ /**
983
+ * The ID of the source.
984
+ */
985
+ id: string;
986
+ /**
987
+ * The URL of the source.
988
+ */
989
+ url: string;
990
+ /**
991
+ * The title of the source.
992
+ */
993
+ title?: string;
994
+ /**
995
+ * Additional provider metadata for the source.
996
+ */
997
+ providerMetadata?: SharedV2ProviderMetadata;
998
+ } | {
999
+ type: 'source';
1000
+ /**
1001
+ * The type of source - document sources reference files/documents.
1002
+ */
1003
+ sourceType: 'document';
1004
+ /**
1005
+ * The ID of the source.
1006
+ */
1007
+ id: string;
1008
+ /**
1009
+ * IANA media type of the document (e.g., 'application/pdf').
1010
+ */
1011
+ mediaType: string;
1012
+ /**
1013
+ * The title of the document.
1014
+ */
1015
+ title: string;
1016
+ /**
1017
+ * Optional filename of the document.
1018
+ */
1019
+ filename?: string;
1020
+ /**
1021
+ * Additional provider metadata for the source.
1022
+ */
1023
+ providerMetadata?: SharedV2ProviderMetadata;
1024
+ };
1025
+
1026
+ /**
1027
+ Text that the model has generated.
1028
+ */
1029
+ type LanguageModelV2Text = {
1030
+ type: 'text';
1031
+ /**
1032
+ The text content.
1033
+ */
1034
+ text: string;
1035
+ providerMetadata?: SharedV2ProviderMetadata;
1036
+ };
1037
+
1038
+ /**
1039
+ * Tool calls that the model has generated.
1040
+ */
1041
+ type LanguageModelV2ToolCall = {
1042
+ type: 'tool-call';
1043
+ /**
1044
+ * The identifier of the tool call. It must be unique across all tool calls.
1045
+ */
1046
+ toolCallId: string;
1047
+ /**
1048
+ * The name of the tool that should be called.
1049
+ */
1050
+ toolName: string;
1051
+ /**
1052
+ * Stringified JSON object with the tool call arguments. Must match the
1053
+ * parameters schema of the tool.
1054
+ */
1055
+ input: string;
1056
+ /**
1057
+ * Whether the tool call will be executed by the provider.
1058
+ * If this flag is not set or is false, the tool call will be executed by the client.
1059
+ */
1060
+ providerExecuted?: boolean;
1061
+ /**
1062
+ * Additional provider-specific metadata for the tool call.
1063
+ */
1064
+ providerMetadata?: SharedV2ProviderMetadata;
1065
+ };
1066
+
1067
+ /**
1068
+ Result of a tool call that has been executed by the provider.
1069
+ */
1070
+ type LanguageModelV2ToolResult = {
1071
+ type: 'tool-result';
1072
+ /**
1073
+ * The ID of the tool call that this result is associated with.
1074
+ */
1075
+ toolCallId: string;
1076
+ /**
1077
+ * Name of the tool that generated this result.
1078
+ */
1079
+ toolName: string;
1080
+ /**
1081
+ * Result of the tool call. This is a JSON-serializable object.
1082
+ */
1083
+ result: unknown;
1084
+ /**
1085
+ * Optional flag if the result is an error or an error message.
1086
+ */
1087
+ isError?: boolean;
1088
+ /**
1089
+ * Whether the tool result was generated by the provider.
1090
+ * If this flag is set to true, the tool result was generated by the provider.
1091
+ * If this flag is not set or is false, the tool result was generated by the client.
1092
+ */
1093
+ providerExecuted?: boolean;
1094
+ /**
1095
+ * Additional provider-specific metadata for the tool result.
1096
+ */
1097
+ providerMetadata?: SharedV2ProviderMetadata;
1098
+ };
1099
+
1100
+ type LanguageModelV2Content = LanguageModelV2Text | LanguageModelV2Reasoning | LanguageModelV2File | LanguageModelV2Source | LanguageModelV2ToolCall | LanguageModelV2ToolResult;
1101
+
1102
+ /**
1103
+ Reason why a language model finished generating a response.
1104
+
1105
+ Can be one of the following:
1106
+ - `stop`: model generated stop sequence
1107
+ - `length`: model generated maximum number of tokens
1108
+ - `content-filter`: content filter violation stopped the model
1109
+ - `tool-calls`: model triggered tool calls
1110
+ - `error`: model stopped because of an error
1111
+ - `other`: model stopped for other reasons
1112
+ - `unknown`: the model has not transmitted a finish reason
1113
+ */
1114
+ type LanguageModelV2FinishReason = 'stop' | 'length' | 'content-filter' | 'tool-calls' | 'error' | 'other' | 'unknown';
1115
+
1116
+ interface LanguageModelV2ResponseMetadata {
1117
+ /**
1118
+ ID for the generated response, if the provider sends one.
1119
+ */
1120
+ id?: string;
1121
+ /**
1122
+ Timestamp for the start of the generated response, if the provider sends one.
1123
+ */
1124
+ timestamp?: Date;
1125
+ /**
1126
+ The ID of the response model that was used to generate the response, if the provider sends one.
1127
+ */
1128
+ modelId?: string;
1129
+ }
1130
+
1131
+ /**
1132
+ Usage information for a language model call.
1133
+
1134
+ If your API return additional usage information, you can add it to the
1135
+ provider metadata under your provider's key.
1136
+ */
1137
+ type LanguageModelV2Usage = {
1138
+ /**
1139
+ The number of input (prompt) tokens used.
1140
+ */
1141
+ inputTokens: number | undefined;
1142
+ /**
1143
+ The number of output (completion) tokens used.
1144
+ */
1145
+ outputTokens: number | undefined;
1146
+ /**
1147
+ The total number of tokens as reported by the provider.
1148
+ This number might be different from the sum of `inputTokens` and `outputTokens`
1149
+ and e.g. include reasoning tokens or other overhead.
1150
+ */
1151
+ totalTokens: number | undefined;
1152
+ /**
1153
+ The number of reasoning tokens used.
1154
+ */
1155
+ reasoningTokens?: number | undefined;
1156
+ /**
1157
+ The number of cached input tokens.
1158
+ */
1159
+ cachedInputTokens?: number | undefined;
1160
+ };
1161
+
1162
+ type LanguageModelV2StreamPart = {
1163
+ type: 'text-start';
1164
+ providerMetadata?: SharedV2ProviderMetadata;
1165
+ id: string;
1166
+ } | {
1167
+ type: 'text-delta';
1168
+ id: string;
1169
+ providerMetadata?: SharedV2ProviderMetadata;
1170
+ delta: string;
1171
+ } | {
1172
+ type: 'text-end';
1173
+ providerMetadata?: SharedV2ProviderMetadata;
1174
+ id: string;
1175
+ } | {
1176
+ type: 'reasoning-start';
1177
+ providerMetadata?: SharedV2ProviderMetadata;
1178
+ id: string;
1179
+ } | {
1180
+ type: 'reasoning-delta';
1181
+ id: string;
1182
+ providerMetadata?: SharedV2ProviderMetadata;
1183
+ delta: string;
1184
+ } | {
1185
+ type: 'reasoning-end';
1186
+ id: string;
1187
+ providerMetadata?: SharedV2ProviderMetadata;
1188
+ } | {
1189
+ type: 'tool-input-start';
1190
+ id: string;
1191
+ toolName: string;
1192
+ providerMetadata?: SharedV2ProviderMetadata;
1193
+ providerExecuted?: boolean;
1194
+ } | {
1195
+ type: 'tool-input-delta';
1196
+ id: string;
1197
+ delta: string;
1198
+ providerMetadata?: SharedV2ProviderMetadata;
1199
+ } | {
1200
+ type: 'tool-input-end';
1201
+ id: string;
1202
+ providerMetadata?: SharedV2ProviderMetadata;
1203
+ } | LanguageModelV2ToolCall | LanguageModelV2ToolResult | LanguageModelV2File | LanguageModelV2Source | {
1204
+ type: 'stream-start';
1205
+ warnings: Array<LanguageModelV2CallWarning>;
1206
+ } | ({
1207
+ type: 'response-metadata';
1208
+ } & LanguageModelV2ResponseMetadata) | {
1209
+ type: 'finish';
1210
+ usage: LanguageModelV2Usage;
1211
+ finishReason: LanguageModelV2FinishReason;
1212
+ providerMetadata?: SharedV2ProviderMetadata;
1213
+ } | {
1214
+ type: 'raw';
1215
+ rawValue: unknown;
1216
+ } | {
1217
+ type: 'error';
1218
+ error: unknown;
1219
+ };
1220
+
1221
+ /**
1222
+ Specification for a language model that implements the language model interface version 2.
1223
+ */
1224
+ type LanguageModelV2 = {
1225
+ /**
1226
+ The language model must specify which language model interface version it implements.
1227
+ */
1228
+ readonly specificationVersion: 'v2';
1229
+ /**
1230
+ Name of the provider for logging purposes.
1231
+ */
1232
+ readonly provider: string;
1233
+ /**
1234
+ Provider-specific model ID for logging purposes.
1235
+ */
1236
+ readonly modelId: string;
1237
+ /**
1238
+ Supported URL patterns by media type for the provider.
1239
+
1240
+ The keys are media type patterns or full media types (e.g. `*\/*` for everything, `audio/*`, `video/*`, or `application/pdf`).
1241
+ and the values are arrays of regular expressions that match the URL paths.
1242
+
1243
+ The matching should be against lower-case URLs.
1244
+
1245
+ Matched URLs are supported natively by the model and are not downloaded.
1246
+
1247
+ @returns A map of supported URL patterns by media type (as a promise or a plain object).
1248
+ */
1249
+ supportedUrls: PromiseLike<Record<string, RegExp[]>> | Record<string, RegExp[]>;
1250
+ /**
1251
+ Generates a language model output (non-streaming).
1252
+
1253
+ Naming: "do" prefix to prevent accidental direct usage of the method
1254
+ by the user.
1255
+ */
1256
+ doGenerate(options: LanguageModelV2CallOptions): PromiseLike<{
1257
+ /**
1258
+ Ordered content that the model has generated.
1259
+ */
1260
+ content: Array<LanguageModelV2Content>;
1261
+ /**
1262
+ Finish reason.
1263
+ */
1264
+ finishReason: LanguageModelV2FinishReason;
1265
+ /**
1266
+ Usage information.
1267
+ */
1268
+ usage: LanguageModelV2Usage;
1269
+ /**
1270
+ Additional provider-specific metadata. They are passed through
1271
+ from the provider to the AI SDK and enable provider-specific
1272
+ results that can be fully encapsulated in the provider.
1273
+ */
1274
+ providerMetadata?: SharedV2ProviderMetadata;
1275
+ /**
1276
+ Optional request information for telemetry and debugging purposes.
1277
+ */
1278
+ request?: {
1279
+ /**
1280
+ Request HTTP body that was sent to the provider API.
1281
+ */
1282
+ body?: unknown;
1283
+ };
1284
+ /**
1285
+ Optional response information for telemetry and debugging purposes.
1286
+ */
1287
+ response?: LanguageModelV2ResponseMetadata & {
1288
+ /**
1289
+ Response headers.
1290
+ */
1291
+ headers?: SharedV2Headers;
1292
+ /**
1293
+ Response HTTP body.
1294
+ */
1295
+ body?: unknown;
1296
+ };
1297
+ /**
1298
+ Warnings for the call, e.g. unsupported settings.
1299
+ */
1300
+ warnings: Array<LanguageModelV2CallWarning>;
1301
+ }>;
1302
+ /**
1303
+ Generates a language model output (streaming).
1304
+
1305
+ Naming: "do" prefix to prevent accidental direct usage of the method
1306
+ by the user.
1307
+ *
1308
+ @return A stream of higher-level language model output parts.
1309
+ */
1310
+ doStream(options: LanguageModelV2CallOptions): PromiseLike<{
1311
+ stream: ReadableStream<LanguageModelV2StreamPart>;
1312
+ /**
1313
+ Optional request information for telemetry and debugging purposes.
1314
+ */
1315
+ request?: {
1316
+ /**
1317
+ Request HTTP body that was sent to the provider API.
1318
+ */
1319
+ body?: unknown;
1320
+ };
1321
+ /**
1322
+ Optional response data.
1323
+ */
1324
+ response?: {
1325
+ /**
1326
+ Response headers.
1327
+ */
1328
+ headers?: SharedV2Headers;
1329
+ };
1330
+ }>;
1331
+ };
1332
+
1333
+ type SpeechModelV2ProviderOptions = Record<string, Record<string, JSONValue>>;
1334
+ type SpeechModelV2CallOptions = {
1335
+ /**
1336
+ * Text to convert to speech.
1337
+ */
1338
+ text: string;
1339
+ /**
1340
+ * The voice to use for speech synthesis.
1341
+ * This is provider-specific and may be a voice ID, name, or other identifier.
1342
+ */
1343
+ voice?: string;
1344
+ /**
1345
+ * The desired output format for the audio e.g. "mp3", "wav", etc.
1346
+ */
1347
+ outputFormat?: string;
1348
+ /**
1349
+ * Instructions for the speech generation e.g. "Speak in a slow and steady tone".
1350
+ */
1351
+ instructions?: string;
1352
+ /**
1353
+ * The speed of the speech generation.
1354
+ */
1355
+ speed?: number;
1356
+ /**
1357
+ * The language for speech generation. This should be an ISO 639-1 language code (e.g. "en", "es", "fr")
1358
+ * or "auto" for automatic language detection. Provider support varies.
1359
+ */
1360
+ language?: string;
1361
+ /**
1362
+ * Additional provider-specific options that are passed through to the provider
1363
+ * as body parameters.
1364
+ *
1365
+ * The outer record is keyed by the provider name, and the inner
1366
+ * record is keyed by the provider-specific metadata key.
1367
+ * ```ts
1368
+ * {
1369
+ * "openai": {}
1370
+ * }
1371
+ * ```
1372
+ */
1373
+ providerOptions?: SpeechModelV2ProviderOptions;
1374
+ /**
1375
+ * Abort signal for cancelling the operation.
1376
+ */
1377
+ abortSignal?: AbortSignal;
1378
+ /**
1379
+ * Additional HTTP headers to be sent with the request.
1380
+ * Only applicable for HTTP-based providers.
1381
+ */
1382
+ headers?: Record<string, string | undefined>;
1383
+ };
1384
+
1385
+ /**
1386
+ * Warning from the model provider for this call. The call will proceed, but e.g.
1387
+ * some settings might not be supported, which can lead to suboptimal results.
1388
+ */
1389
+ type SpeechModelV2CallWarning = {
1390
+ type: 'unsupported-setting';
1391
+ setting: keyof SpeechModelV2CallOptions;
1392
+ details?: string;
1393
+ } | {
1394
+ type: 'other';
1395
+ message: string;
1396
+ };
1397
+
1398
+ /**
1399
+ * Speech model specification version 2.
1400
+ */
1401
+ type SpeechModelV2 = {
1402
+ /**
1403
+ * The speech model must specify which speech model interface
1404
+ * version it implements. This will allow us to evolve the speech
1405
+ * model interface and retain backwards compatibility. The different
1406
+ * implementation versions can be handled as a discriminated union
1407
+ * on our side.
1408
+ */
1409
+ readonly specificationVersion: 'v2';
1410
+ /**
1411
+ * Name of the provider for logging purposes.
1412
+ */
1413
+ readonly provider: string;
1414
+ /**
1415
+ * Provider-specific model ID for logging purposes.
1416
+ */
1417
+ readonly modelId: string;
1418
+ /**
1419
+ * Generates speech audio from text.
1420
+ */
1421
+ doGenerate(options: SpeechModelV2CallOptions): PromiseLike<{
1422
+ /**
1423
+ * Generated audio as an ArrayBuffer.
1424
+ * The audio should be returned without any unnecessary conversion.
1425
+ * If the API returns base64 encoded strings, the audio should be returned
1426
+ * as base64 encoded strings. If the API returns binary data, the audio
1427
+ * should be returned as binary data.
1428
+ */
1429
+ audio: string | Uint8Array;
1430
+ /**
1431
+ * Warnings for the call, e.g. unsupported settings.
1432
+ */
1433
+ warnings: Array<SpeechModelV2CallWarning>;
1434
+ /**
1435
+ * Optional request information for telemetry and debugging purposes.
1436
+ */
1437
+ request?: {
1438
+ /**
1439
+ * Response body (available only for providers that use HTTP requests).
1440
+ */
1441
+ body?: unknown;
1442
+ };
1443
+ /**
1444
+ * Response information for telemetry and debugging purposes.
1445
+ */
1446
+ response: {
1447
+ /**
1448
+ * Timestamp for the start of the generated response.
1449
+ */
1450
+ timestamp: Date;
1451
+ /**
1452
+ * The ID of the response model that was used to generate the response.
1453
+ */
1454
+ modelId: string;
1455
+ /**
1456
+ * Response headers.
1457
+ */
1458
+ headers?: SharedV2Headers;
1459
+ /**
1460
+ * Response body.
1461
+ */
1462
+ body?: unknown;
1463
+ };
1464
+ /**
1465
+ * Additional provider-specific metadata. They are passed through
1466
+ * from the provider to the AI SDK and enable provider-specific
1467
+ * results that can be fully encapsulated in the provider.
1468
+ */
1469
+ providerMetadata?: Record<string, Record<string, JSONValue>>;
1470
+ }>;
1471
+ };
1472
+
1473
+ type TranscriptionModelV2ProviderOptions = Record<string, Record<string, JSONValue>>;
1474
+ type TranscriptionModelV2CallOptions = {
1475
+ /**
1476
+ Audio data to transcribe.
1477
+ Accepts a `Uint8Array` or `string`, where `string` is a base64 encoded audio file.
1478
+ */
1479
+ audio: Uint8Array | string;
1480
+ /**
1481
+ The IANA media type of the audio data.
1482
+
1483
+ @see https://www.iana.org/assignments/media-types/media-types.xhtml
1484
+ */
1485
+ mediaType: string;
1486
+ /**
1487
+ Additional provider-specific options that are passed through to the provider
1488
+ as body parameters.
1489
+
1490
+ The outer record is keyed by the provider name, and the inner
1491
+ record is keyed by the provider-specific metadata key.
1492
+ ```ts
1493
+ {
1494
+ "openai": {
1495
+ "timestampGranularities": ["word"]
1496
+ }
1497
+ }
1498
+ ```
1499
+ */
1500
+ providerOptions?: TranscriptionModelV2ProviderOptions;
1501
+ /**
1502
+ Abort signal for cancelling the operation.
1503
+ */
1504
+ abortSignal?: AbortSignal;
1505
+ /**
1506
+ Additional HTTP headers to be sent with the request.
1507
+ Only applicable for HTTP-based providers.
1508
+ */
1509
+ headers?: Record<string, string | undefined>;
1510
+ };
1511
+
1512
+ /**
1513
+ Warning from the model provider for this call. The call will proceed, but e.g.
1514
+ some settings might not be supported, which can lead to suboptimal results.
1515
+ */
1516
+ type TranscriptionModelV2CallWarning = {
1517
+ type: 'unsupported-setting';
1518
+ setting: keyof TranscriptionModelV2CallOptions;
1519
+ details?: string;
1520
+ } | {
1521
+ type: 'other';
1522
+ message: string;
1523
+ };
1524
+
1525
+ /**
1526
+ Transcription model specification version 2.
1527
+ */
1528
+ type TranscriptionModelV2 = {
1529
+ /**
1530
+ The transcription model must specify which transcription model interface
1531
+ version it implements. This will allow us to evolve the transcription
1532
+ model interface and retain backwards compatibility. The different
1533
+ implementation versions can be handled as a discriminated union
1534
+ on our side.
1535
+ */
1536
+ readonly specificationVersion: 'v2';
1537
+ /**
1538
+ Name of the provider for logging purposes.
1539
+ */
1540
+ readonly provider: string;
1541
+ /**
1542
+ Provider-specific model ID for logging purposes.
1543
+ */
1544
+ readonly modelId: string;
1545
+ /**
1546
+ Generates a transcript.
1547
+ */
1548
+ doGenerate(options: TranscriptionModelV2CallOptions): PromiseLike<{
1549
+ /**
1550
+ * The complete transcribed text from the audio.
1551
+ */
1552
+ text: string;
1553
+ /**
1554
+ * Array of transcript segments with timing information.
1555
+ * Each segment represents a portion of the transcribed text with start and end times.
1556
+ */
1557
+ segments: Array<{
1558
+ /**
1559
+ * The text content of this segment.
1560
+ */
1561
+ text: string;
1562
+ /**
1563
+ * The start time of this segment in seconds.
1564
+ */
1565
+ startSecond: number;
1566
+ /**
1567
+ * The end time of this segment in seconds.
1568
+ */
1569
+ endSecond: number;
1570
+ }>;
1571
+ /**
1572
+ * The detected language of the audio content, as an ISO-639-1 code (e.g., 'en' for English).
1573
+ * May be undefined if the language couldn't be detected.
1574
+ */
1575
+ language: string | undefined;
1576
+ /**
1577
+ * The total duration of the audio file in seconds.
1578
+ * May be undefined if the duration couldn't be determined.
1579
+ */
1580
+ durationInSeconds: number | undefined;
1581
+ /**
1582
+ Warnings for the call, e.g. unsupported settings.
1583
+ */
1584
+ warnings: Array<TranscriptionModelV2CallWarning>;
1585
+ /**
1586
+ Optional request information for telemetry and debugging purposes.
1587
+ */
1588
+ request?: {
1589
+ /**
1590
+ Raw request HTTP body that was sent to the provider API as a string (JSON should be stringified).
1591
+ Non-HTTP(s) providers should not set this.
1592
+ */
1593
+ body?: string;
1594
+ };
1595
+ /**
1596
+ Response information for telemetry and debugging purposes.
1597
+ */
1598
+ response: {
1599
+ /**
1600
+ Timestamp for the start of the generated response.
1601
+ */
1602
+ timestamp: Date;
1603
+ /**
1604
+ The ID of the response model that was used to generate the response.
1605
+ */
1606
+ modelId: string;
1607
+ /**
1608
+ Response headers.
1609
+ */
1610
+ headers?: SharedV2Headers;
1611
+ /**
1612
+ Response body.
1613
+ */
1614
+ body?: unknown;
1615
+ };
1616
+ /**
1617
+ Additional provider-specific metadata. They are passed through
1618
+ from the provider to the AI SDK and enable provider-specific
1619
+ results that can be fully encapsulated in the provider.
1620
+ */
1621
+ providerMetadata?: Record<string, Record<string, JSONValue>>;
1622
+ }>;
1623
+ };
1624
+
1625
+ /**
1626
+ * Provider for language, text embedding, and image generation models.
1627
+ */
1628
+ interface ProviderV2 {
1629
+ /**
1630
+ Returns the language model with the given id.
1631
+ The model id is then passed to the provider function to get the model.
1632
+
1633
+ @param {string} modelId - The id of the model to return.
1634
+
1635
+ @returns {LanguageModel} The language model associated with the id
1636
+
1637
+ @throws {NoSuchModelError} If no such model exists.
1638
+ */
1639
+ languageModel(modelId: string): LanguageModelV2;
1640
+ /**
1641
+ Returns the text embedding model with the given id.
1642
+ The model id is then passed to the provider function to get the model.
1643
+
1644
+ @param {string} modelId - The id of the model to return.
1645
+
1646
+ @returns {LanguageModel} The language model associated with the id
1647
+
1648
+ @throws {NoSuchModelError} If no such model exists.
1649
+ */
1650
+ textEmbeddingModel(modelId: string): EmbeddingModelV2<string>;
1651
+ /**
1652
+ Returns the image model with the given id.
1653
+ The model id is then passed to the provider function to get the model.
1654
+
1655
+ @param {string} modelId - The id of the model to return.
1656
+
1657
+ @returns {ImageModel} The image model associated with the id
1658
+ */
1659
+ imageModel(modelId: string): ImageModelV2;
1660
+ /**
1661
+ Returns the transcription model with the given id.
1662
+ The model id is then passed to the provider function to get the model.
1663
+
1664
+ @param {string} modelId - The id of the model to return.
1665
+
1666
+ @returns {TranscriptionModel} The transcription model associated with the id
1667
+ */
1668
+ transcriptionModel?(modelId: string): TranscriptionModelV2;
1669
+ /**
1670
+ Returns the speech model with the given id.
1671
+ The model id is then passed to the provider function to get the model.
1672
+
1673
+ @param {string} modelId - The id of the model to return.
1674
+
1675
+ @returns {SpeechModel} The speech model associated with the id
1676
+ */
1677
+ speechModel?(modelId: string): SpeechModelV2;
1678
+ }
1679
+
92
1680
  /** Azure OpenAI chat extension configuration for "On Your Data" RAG scenarios. */
93
1681
  type AzureOpenAiChatExtensionConfiguration = NonNullable<AzureOpenAiChatCompletionParameters["data_sources"]>[number];
94
1682
  /**
95
1683
  * Common model parameters shared between both APIs.
96
1684
  *
97
- * These parameters control text generation behavior and are validated by Zod schemas
98
- * when passed via `providerOptions`.
1685
+ * Known parameters are validated by Zod in constructor settings and per-call
1686
+ * `modelParams` provider options; additional model-specific keys are passed through.
99
1687
  */
100
1688
  interface CommonModelParams {
101
1689
  /**
@@ -110,7 +1698,7 @@ interface CommonModelParams {
110
1698
  readonly maxTokens?: number;
111
1699
  /**
112
1700
  * Number of completions to generate.
113
- * Not supported by Amazon/Anthropic models.
1701
+ * Availability depends on the selected SAP API and model; no model-family filtering is applied.
114
1702
  * Range: Positive integer
115
1703
  */
116
1704
  readonly n?: number;
@@ -161,7 +1749,10 @@ interface FoundationModelsModelSettings {
161
1749
  readonly api: "foundation-models";
162
1750
  /** Azure OpenAI "On Your Data" configuration for RAG scenarios. */
163
1751
  readonly dataSources?: AzureOpenAiChatExtensionConfiguration[];
164
- /** @default false */
1752
+ /**
1753
+ * Forward assistant reasoning from the input history as text; does not enable reasoning output.
1754
+ * @default false
1755
+ */
165
1756
  readonly includeReasoning?: boolean;
166
1757
  readonly modelParams?: FoundationModelsModelParams;
167
1758
  readonly modelVersion?: string;
@@ -181,7 +1772,7 @@ interface OrchestrationModelSettings {
181
1772
  readonly escapeTemplatePlaceholders?: boolean;
182
1773
  /**
183
1774
  * Additional module configurations for prompt module fallback.
184
- * The SDK tries the primary configuration first, then each fallback in order until one succeeds.
1775
+ * These entries follow the primary configuration in the list passed to the SAP SDK.
185
1776
  * Each entry is a full `OrchestrationModuleConfig` with its own model, prompt, and modules.
186
1777
  * @example
187
1778
  * ```ts
@@ -198,7 +1789,10 @@ interface OrchestrationModelSettings {
198
1789
  readonly fallbackModuleConfigs?: OrchestrationModuleConfig[];
199
1790
  readonly filtering?: FilteringModule;
200
1791
  readonly grounding?: GroundingModule;
201
- /** @default false */
1792
+ /**
1793
+ * Forward assistant reasoning from the input history as text; does not enable reasoning output.
1794
+ * @default false
1795
+ */
202
1796
  readonly includeReasoning?: boolean;
203
1797
  readonly masking?: MaskingModule | {
204
1798
  providers: MaskingModule["masking_providers"];
@@ -209,7 +1803,8 @@ interface OrchestrationModelSettings {
209
1803
  * Reference to a complete orchestration configuration stored in SAP AI Core Prompt Registry.
210
1804
  * When provided, local module settings (filtering, masking, grounding, translation, tools,
211
1805
  * promptTemplateRef, responseFormat) are ignored as the full configuration is managed
212
- * by the referenced config. Only `placeholderValues` and messages are passed through.
1806
+ * by the referenced config. The reference, including its explicit `overrideConfig`,
1807
+ * is passed to the SAP SDK; messages and `placeholderValues` remain request inputs.
213
1808
  * @example { id: "f47ac10b-58cc-4372-a567-0e02b2c3d479" }
214
1809
  * @example { scenario: "customer-support", name: "prod-config", version: "1.0.0" }
215
1810
  */
@@ -218,8 +1813,8 @@ interface OrchestrationModelSettings {
218
1813
  readonly promptTemplateRef?: PromptTemplateRef;
219
1814
  readonly responseFormat?: ResponseFormat;
220
1815
  /**
221
- * Options for streaming behavior with post-LLM modules.
222
- * Only applies when using `streamText()` with orchestration modules.
1816
+ * Options for streaming behavior with locally configured post-LLM modules.
1817
+ * Includes direct `doStream()` calls; ignored when `orchestrationConfigRef` is used.
223
1818
  */
224
1819
  readonly streamOptions?: OrchestrationStreamOptions;
225
1820
  readonly tools?: ChatCompletionTool[];
@@ -228,6 +1823,8 @@ interface OrchestrationModelSettings {
228
1823
  /**
229
1824
  * Stream options for orchestration post-LLM module processing.
230
1825
  * Controls chunking behavior for translation, filtering, and other modules during streaming.
1826
+ * Ignored with `orchestrationConfigRef`; configure streaming in the stored
1827
+ * configuration or its `overrideConfig` instead.
231
1828
  */
232
1829
  interface OrchestrationStreamOptions {
233
1830
  /**
@@ -237,7 +1834,7 @@ interface OrchestrationStreamOptions {
237
1834
  readonly chunkSize?: number;
238
1835
  /**
239
1836
  * Delimiters for splitting stream into chunks (e.g., sentence boundaries).
240
- * Required when translation module is configured.
1837
+ * Recommended for translation; the provider warns when local translation settings lack them.
241
1838
  * @example ["\n", ".", "?", "!"]
242
1839
  */
243
1840
  readonly delimiters?: readonly string[];
@@ -286,7 +1883,10 @@ interface SAPAIEmbeddingSettings {
286
1883
  readonly modelParams?: FoundationModelsEmbeddingParams | Record<string, unknown>;
287
1884
  readonly modelVersion?: string;
288
1885
  readonly [key: string]: unknown;
289
- /** @default 'text' */
1886
+ /**
1887
+ * Orchestration embedding input type; ignored by Foundation Models.
1888
+ * @default 'text'
1889
+ */
290
1890
  readonly type?: "document" | "query" | "text";
291
1891
  }
292
1892
  /**
@@ -320,7 +1920,10 @@ interface SAPAISettings {
320
1920
  readonly filtering?: FilteringModule;
321
1921
  /** Orchestration API only. */
322
1922
  readonly grounding?: GroundingModule;
323
- /** @default false */
1923
+ /**
1924
+ * Forward assistant reasoning from the input history as text; does not enable reasoning output.
1925
+ * @default false
1926
+ */
324
1927
  readonly includeReasoning?: boolean;
325
1928
  /** Orchestration API only. */
326
1929
  readonly masking?: MaskingModule | {
@@ -335,7 +1938,7 @@ interface SAPAISettings {
335
1938
  /** Orchestration API only. */
336
1939
  readonly promptTemplateRef?: PromptTemplateRef;
337
1940
  readonly responseFormat?: ResponseFormat;
338
- /** Orchestration API only. */
1941
+ /** Orchestration API only; ignored when `orchestrationConfigRef` is used. */
339
1942
  readonly streamOptions?: OrchestrationStreamOptions;
340
1943
  /** Orchestration API only. */
341
1944
  readonly tools?: ChatCompletionTool[];
@@ -480,7 +2083,7 @@ declare class ApiSwitchError extends Error {
480
2083
  * @example
481
2084
  * ```typescript
482
2085
  * throw new UnsupportedFeatureError("Content filtering", "foundation-models", "orchestration");
483
- * // "Content filtering is only available with Orchestration API and will be ignored by Foundation Models API."
2086
+ * // Rejects the request: content filtering requires the Orchestration API.
484
2087
  * ```
485
2088
  * @see {@link validateSettings} - Main validation function that throws this error
486
2089
  * @see {@link ApiSwitchError} - Related error for API switching conflicts
@@ -492,12 +2095,46 @@ declare class UnsupportedFeatureError extends Error {
492
2095
  /**
493
2096
  * Creates a new UnsupportedFeatureError.
494
2097
  * @param feature - The name of the unsupported feature (e.g., "Content filtering").
495
- * @param api - The API being used where the feature will be ignored.
2098
+ * @param api - The API being used that does not support the feature.
496
2099
  * @param suggestedApi - The API that supports this feature.
497
2100
  */
498
2101
  constructor(feature: string, api: SAPAIApiType, suggestedApi: SAPAIApiType);
499
2102
  }
500
2103
 
2104
+ /** Adapters to convert internal (V3) formats to LanguageModelV2 formats for the V2 facade. */
2105
+
2106
+ type ConvertedV2StreamPart = Exclude<LanguageModelV2StreamPart, {
2107
+ type: "stream-start";
2108
+ }> | {
2109
+ type: "stream-start";
2110
+ warnings: ReturnType<typeof convertWarningsToV2>;
2111
+ };
2112
+ /**
2113
+ * Converts internal warnings array to V2 warnings array.
2114
+ * @param internalWarnings - Internal warning objects.
2115
+ * @returns V2 warning objects.
2116
+ * @internal
2117
+ */
2118
+ declare function convertWarningsToV2(internalWarnings: SharedV3Warning[]): ReturnType<typeof convertWarningToV2>[];
2119
+ /**
2120
+ * Converts internal warning to V2 warning format.
2121
+ *
2122
+ * Maps `unsupported`/`compatibility` warnings to V2 `other` type with descriptive message.
2123
+ * @param internalWarning - Internal warning object.
2124
+ * @returns V2 warning object.
2125
+ * @internal
2126
+ */
2127
+ declare function convertWarningToV2(internalWarning: SharedV3Warning): Extract<LanguageModelV2CallWarning, {
2128
+ type: "other";
2129
+ }>;
2130
+ /**
2131
+ * Transforms internal stream to V2 ReadableStream.
2132
+ * @param internalStream - Internal ReadableStream to transform.
2133
+ * @returns V2-formatted ReadableStream.
2134
+ * @internal
2135
+ */
2136
+ declare function createV2StreamFromInternal(internalStream: ReadableStream<LanguageModelV3StreamPart>): ReadableStream<ConvertedV2StreamPart>;
2137
+
501
2138
  /**
502
2139
  * SAP AI Language Model V2 - Vercel AI SDK LanguageModelV2 implementation for SAP AI Core.
503
2140
  *
@@ -507,6 +2144,9 @@ declare class UnsupportedFeatureError extends Error {
507
2144
  * @see {@link https://sdk.vercel.ai/docs/reference/ai-sdk-core/stream-text | Vercel AI SDK streamText()}
508
2145
  */
509
2146
 
2147
+ type CompatibleV2CallOptions = Omit<LanguageModelV2CallOptions$1, "tools"> & {
2148
+ tools?: LanguageModelV2CallOptions$1["tools"] | LanguageModelV3CallOptions["tools"];
2149
+ };
510
2150
  /** @internal */
511
2151
  interface SAPAILanguageModelV2Config {
512
2152
  readonly deploymentConfig: DeploymentIdConfig | ResourceGroupConfig;
@@ -551,7 +2191,7 @@ interface SAPAILanguageModelV2Config {
551
2191
  * @see {@link https://sdk.vercel.ai/docs/ai-sdk-core/generating-text | Vercel AI SDK Text Generation}
552
2192
  * @see {@link createSAPAIProvider} - Factory function to create provider instances
553
2193
  */
554
- declare class SAPAILanguageModelV2 implements LanguageModelV2 {
2194
+ declare class SAPAILanguageModelV2 implements LanguageModelV2$1 {
555
2195
  readonly modelId: SAPAIModelId;
556
2196
  readonly specificationVersion: "v2";
557
2197
  get provider(): string;
@@ -565,7 +2205,7 @@ declare class SAPAILanguageModelV2 implements LanguageModelV2 {
565
2205
  * @internal
566
2206
  */
567
2207
  constructor(modelId: SAPAIModelId, settings: SAPAISettings, config: SAPAILanguageModelV2Config);
568
- doGenerate(options: LanguageModelV2CallOptions): Promise<{
2208
+ doGenerate(options: CompatibleV2CallOptions): Promise<{
569
2209
  content: LanguageModelV2Content[];
570
2210
  finishReason: LanguageModelV2FinishReason;
571
2211
  providerMetadata?: SharedV2ProviderMetadata;
@@ -577,16 +2217,16 @@ declare class SAPAILanguageModelV2 implements LanguageModelV2 {
577
2217
  headers?: SharedV2Headers;
578
2218
  };
579
2219
  usage: LanguageModelV2Usage;
580
- warnings: LanguageModelV2CallWarning[];
2220
+ warnings: ReturnType<typeof convertWarningsToV2>;
581
2221
  }>;
582
- doStream(options: LanguageModelV2CallOptions): Promise<{
2222
+ doStream(options: CompatibleV2CallOptions): Promise<{
583
2223
  request?: {
584
2224
  body?: unknown;
585
2225
  };
586
2226
  response?: {
587
2227
  headers?: SharedV2Headers;
588
2228
  };
589
- stream: ReadableStream<LanguageModelV2StreamPart>;
2229
+ stream: ReturnType<typeof createV2StreamFromInternal>;
590
2230
  }>;
591
2231
  }
592
2232
 
@@ -598,14 +2238,15 @@ type DeploymentConfig = DeploymentIdConfig | ResourceGroupConfig;
598
2238
  */
599
2239
  interface SAPAIProviderSettings {
600
2240
  /**
601
- * SAP AI Core API to use for all models created by this provider.
602
- * Can be overridden at model creation time or per-call via providerOptions.
2241
+ * Default SAP AI Core API for models created by this provider.
2242
+ * `defaultSettings.api`, per-model `api`, and per-call `providerOptions` take precedence.
2243
+ * This option does not enable automatic failover between APIs.
603
2244
  * - `'orchestration'` (default): SAP AI Core Orchestration API - supports filtering, grounding, masking, translation
604
2245
  * - `'foundation-models'`: SAP AI Core Foundation Models API - supports dataSources, logprobs, seed, etc.
605
2246
  * @default 'orchestration'
606
2247
  */
607
2248
  readonly api?: SAPAIApiType;
608
- /** Default model settings applied to every model instance. Per-call settings override these. */
2249
+ /** Default model settings; settings supplied at model creation override these. */
609
2250
  readonly defaultSettings?: SAPAISettings;
610
2251
  /** SAP AI Core deployment ID. If not provided, the SDK resolves deployment automatically. */
611
2252
  readonly deploymentId?: string;
@@ -613,13 +2254,16 @@ interface SAPAIProviderSettings {
613
2254
  readonly destination?: HttpDestinationOrFetchOptions;
614
2255
  /**
615
2256
  * Log level for SAP Cloud SDK loggers.
616
- * Controls verbosity of internal SAP SDK logging (e.g., authentication, service binding).
2257
+ * Controls process-wide SAP SDK logging (e.g., authentication, service binding).
2258
+ * Creating another provider resets this level, using warn when logLevel is omitted.
617
2259
  * Note: SAP_CLOUD_SDK_LOG_LEVEL environment variable takes precedence if set.
618
2260
  * @default 'warn'
619
2261
  */
620
2262
  readonly logLevel?: "debug" | "error" | "info" | "warn";
621
2263
  /**
622
- * Provider name used as key for `providerOptions` and `providerMetadata`.
2264
+ * Name used in model provider identifiers. Call-level `providerOptions` and
2265
+ * `providerMetadata` keys use the prefix before the first dot; avoid dots in names.
2266
+ * Per-part prompt-cache directives always use the fixed `sap-ai` key.
623
2267
  * @default 'sap-ai'
624
2268
  */
625
2269
  readonly name?: string;
@@ -629,8 +2273,9 @@ interface SAPAIProviderSettings {
629
2273
  *
630
2274
  * Provider-level only (not overridable per-call via `providerOptions['sap-ai']`). The
631
2275
  * AI SDK `abortSignal` option always wins over any `signal` on `requestConfig`; the
632
- * latter is dropped before the request is forwarded. Node-only knobs (`httpAgent`,
633
- * `httpsAgent`) are silently ignored on Edge / Cloudflare Workers runtimes.
2276
+ * latter is dropped before the request is forwarded. Other options, including
2277
+ * Node-only agents (`httpAgent`, `httpsAgent`), are forwarded unchanged. The
2278
+ * published package and SAP SDK transport require a Node-compatible runtime.
634
2279
  *
635
2280
  * See the "Note on `requestConfig`" section under `SAPAIProviderSettings` in
636
2281
  * `API_REFERENCE.md` for the full SAP AI Core `AI-*` header guidance.
@@ -656,7 +2301,8 @@ interface SAPAIProviderV2 extends ProviderV2 {
656
2301
  textEmbeddingModel(modelId: SAPAIEmbeddingModelId, settings?: SAPAIEmbeddingSettings): SAPAIEmbeddingModelV2;
657
2302
  }
658
2303
  /**
659
- * Creates an SAP AI Provider instance for use with the Vercel AI SDK.
2304
+ * Creates an SAP AI Provider V2 instance for use with AI SDK 5.
2305
+ * AI SDK 6 can also consume this provider through its V2 compatibility layer.
660
2306
  *
661
2307
  * Uses the official SAP AI SDK (`@sap-ai-sdk/orchestration` and
662
2308
  * `@sap-ai-sdk/foundation-models`) for API communication. Authentication is automatic via service binding
@@ -664,12 +2310,12 @@ interface SAPAIProviderV2 extends ProviderV2 {
664
2310
  * @param options - Provider configuration options.
665
2311
  * @param options.api - Default API type: `'orchestration'` (default) or `'foundation-models'`.
666
2312
  * @param options.defaultSettings - Default model settings applied to every model instance.
667
- * @param options.deploymentId - SAP AI Core deployment ID for automatic deployment resolution.
2313
+ * @param options.deploymentId - Explicit SAP AI Core deployment ID; omit for automatic deployment resolution.
668
2314
  * @param options.destination - Custom SAP Cloud SDK destination configuration.
669
2315
  * @param options.logLevel - Log level for SAP Cloud SDK loggers (`'debug'`, `'info'`, `'warn'`, `'error'`).
670
- * @param options.name - Provider name used as key in `providerOptions` (default: `'sap-ai'`).
2316
+ * @param options.name - Provider name (default: `'sap-ai'`); see {@link SAPAIProviderSettings.name} for namespace rules.
671
2317
  * @param options.requestConfig - Provider-level custom request configuration. See {@link SAPAIProviderSettings.requestConfig} for scope, portability, and abort semantics.
672
- * @param options.resourceGroup - SAP AI Core resource group (default: `'default'`).
2318
+ * @param options.resourceGroup - SAP AI Core resource group (default: `'default'`); ignored when deploymentId is set.
673
2319
  * @param options.warnOnAmbiguousConfig - Whether to warn when both deploymentId and resourceGroup are set.
674
2320
  * @returns A configured SAP AI provider instance that can be used as a callable or via methods.
675
2321
  * @example