@ai-sdk/provider 0.0.0-01d6317c-20260129172110

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 (138) hide show
  1. package/CHANGELOG.md +967 -0
  2. package/LICENSE +13 -0
  3. package/README.md +1 -0
  4. package/dist/index.d.mts +3814 -0
  5. package/dist/index.d.ts +3814 -0
  6. package/dist/index.js +448 -0
  7. package/dist/index.js.map +1 -0
  8. package/dist/index.mjs +404 -0
  9. package/dist/index.mjs.map +1 -0
  10. package/package.json +63 -0
  11. package/src/embedding-model/index.ts +2 -0
  12. package/src/embedding-model/v2/embedding-model-v2-embedding.ts +5 -0
  13. package/src/embedding-model/v2/embedding-model-v2.ts +113 -0
  14. package/src/embedding-model/v2/index.ts +2 -0
  15. package/src/embedding-model/v3/embedding-model-v3-call-options.ts +26 -0
  16. package/src/embedding-model/v3/embedding-model-v3-embedding.ts +5 -0
  17. package/src/embedding-model/v3/embedding-model-v3-result.ts +48 -0
  18. package/src/embedding-model/v3/embedding-model-v3.ts +54 -0
  19. package/src/embedding-model/v3/index.ts +4 -0
  20. package/src/embedding-model-middleware/index.ts +1 -0
  21. package/src/embedding-model-middleware/v3/embedding-model-v3-middleware.ts +69 -0
  22. package/src/embedding-model-middleware/v3/index.ts +1 -0
  23. package/src/errors/ai-sdk-error.ts +62 -0
  24. package/src/errors/api-call-error.ts +59 -0
  25. package/src/errors/empty-response-body-error.ts +17 -0
  26. package/src/errors/get-error-message.ts +15 -0
  27. package/src/errors/index.ts +16 -0
  28. package/src/errors/invalid-argument-error.ts +32 -0
  29. package/src/errors/invalid-prompt-error.ts +33 -0
  30. package/src/errors/invalid-response-data-error.ts +31 -0
  31. package/src/errors/json-parse-error.ts +29 -0
  32. package/src/errors/load-api-key-error.ts +17 -0
  33. package/src/errors/load-setting-error.ts +17 -0
  34. package/src/errors/no-content-generated-error.ts +22 -0
  35. package/src/errors/no-such-model-error.ts +45 -0
  36. package/src/errors/too-many-embedding-values-for-call-error.ts +40 -0
  37. package/src/errors/type-validation-error.ts +108 -0
  38. package/src/errors/unsupported-functionality-error.ts +26 -0
  39. package/src/image-model/index.ts +2 -0
  40. package/src/image-model/v2/image-model-v2-call-options.ts +60 -0
  41. package/src/image-model/v2/image-model-v2-call-warning.ts +16 -0
  42. package/src/image-model/v2/image-model-v2.ts +104 -0
  43. package/src/image-model/v2/index.ts +6 -0
  44. package/src/image-model/v3/image-model-v3-call-options.ts +74 -0
  45. package/src/image-model/v3/image-model-v3-file.ts +44 -0
  46. package/src/image-model/v3/image-model-v3-usage.ts +19 -0
  47. package/src/image-model/v3/image-model-v3.ts +110 -0
  48. package/src/image-model/v3/index.ts +7 -0
  49. package/src/image-model-middleware/index.ts +1 -0
  50. package/src/image-model-middleware/v3/image-model-v3-middleware.ts +61 -0
  51. package/src/image-model-middleware/v3/index.ts +1 -0
  52. package/src/index.ts +15 -0
  53. package/src/json-value/index.ts +2 -0
  54. package/src/json-value/is-json.ts +40 -0
  55. package/src/json-value/json-value.ts +17 -0
  56. package/src/language-model/index.ts +2 -0
  57. package/src/language-model/v2/index.ts +18 -0
  58. package/src/language-model/v2/language-model-v2-call-options.ts +127 -0
  59. package/src/language-model/v2/language-model-v2-call-warning.ts +23 -0
  60. package/src/language-model/v2/language-model-v2-content.ts +14 -0
  61. package/src/language-model/v2/language-model-v2-data-content.ts +4 -0
  62. package/src/language-model/v2/language-model-v2-file.ts +25 -0
  63. package/src/language-model/v2/language-model-v2-finish-reason.ts +20 -0
  64. package/src/language-model/v2/language-model-v2-function-tool.ts +37 -0
  65. package/src/language-model/v2/language-model-v2-prompt.ts +218 -0
  66. package/src/language-model/v2/language-model-v2-provider-defined-tool.ts +24 -0
  67. package/src/language-model/v2/language-model-v2-reasoning.ts +14 -0
  68. package/src/language-model/v2/language-model-v2-response-metadata.ts +16 -0
  69. package/src/language-model/v2/language-model-v2-source.ts +67 -0
  70. package/src/language-model/v2/language-model-v2-stream-part.ts +102 -0
  71. package/src/language-model/v2/language-model-v2-text.ts +15 -0
  72. package/src/language-model/v2/language-model-v2-tool-call.ts +35 -0
  73. package/src/language-model/v2/language-model-v2-tool-choice.ts +5 -0
  74. package/src/language-model/v2/language-model-v2-tool-result.ts +40 -0
  75. package/src/language-model/v2/language-model-v2-usage.ts +34 -0
  76. package/src/language-model/v2/language-model-v2.ts +137 -0
  77. package/src/language-model/v3/index.ts +21 -0
  78. package/src/language-model/v3/language-model-v3-call-options.ts +125 -0
  79. package/src/language-model/v3/language-model-v3-content.ts +16 -0
  80. package/src/language-model/v3/language-model-v3-data-content.ts +4 -0
  81. package/src/language-model/v3/language-model-v3-file.ts +32 -0
  82. package/src/language-model/v3/language-model-v3-finish-reason.ts +33 -0
  83. package/src/language-model/v3/language-model-v3-function-tool.ts +53 -0
  84. package/src/language-model/v3/language-model-v3-generate-result.ts +63 -0
  85. package/src/language-model/v3/language-model-v3-prompt.ts +422 -0
  86. package/src/language-model/v3/language-model-v3-provider-tool.ts +28 -0
  87. package/src/language-model/v3/language-model-v3-reasoning.ts +14 -0
  88. package/src/language-model/v3/language-model-v3-response-metadata.ts +16 -0
  89. package/src/language-model/v3/language-model-v3-source.ts +67 -0
  90. package/src/language-model/v3/language-model-v3-stream-part.ts +106 -0
  91. package/src/language-model/v3/language-model-v3-stream-result.ts +32 -0
  92. package/src/language-model/v3/language-model-v3-text.ts +15 -0
  93. package/src/language-model/v3/language-model-v3-tool-approval-request.ts +27 -0
  94. package/src/language-model/v3/language-model-v3-tool-call.ts +41 -0
  95. package/src/language-model/v3/language-model-v3-tool-choice.ts +5 -0
  96. package/src/language-model/v3/language-model-v3-tool-result.ts +51 -0
  97. package/src/language-model/v3/language-model-v3-usage.ts +59 -0
  98. package/src/language-model/v3/language-model-v3.ts +61 -0
  99. package/src/language-model-middleware/index.ts +2 -0
  100. package/src/language-model-middleware/v2/index.ts +1 -0
  101. package/src/language-model-middleware/v2/language-model-v2-middleware.ts +82 -0
  102. package/src/language-model-middleware/v3/index.ts +1 -0
  103. package/src/language-model-middleware/v3/language-model-v3-middleware.ts +84 -0
  104. package/src/provider/index.ts +2 -0
  105. package/src/provider/v2/index.ts +1 -0
  106. package/src/provider/v2/provider-v2.ts +64 -0
  107. package/src/provider/v3/index.ts +1 -0
  108. package/src/provider/v3/provider-v3.ts +93 -0
  109. package/src/reranking-model/index.ts +1 -0
  110. package/src/reranking-model/v3/index.ts +2 -0
  111. package/src/reranking-model/v3/reranking-model-v3-call-options.ts +40 -0
  112. package/src/reranking-model/v3/reranking-model-v3.ts +90 -0
  113. package/src/shared/index.ts +2 -0
  114. package/src/shared/v2/index.ts +3 -0
  115. package/src/shared/v2/shared-v2-headers.ts +1 -0
  116. package/src/shared/v2/shared-v2-provider-metadata.ts +27 -0
  117. package/src/shared/v2/shared-v2-provider-options.ts +24 -0
  118. package/src/shared/v3/index.ts +4 -0
  119. package/src/shared/v3/shared-v3-headers.ts +1 -0
  120. package/src/shared/v3/shared-v3-provider-metadata.ts +24 -0
  121. package/src/shared/v3/shared-v3-provider-options.ts +24 -0
  122. package/src/shared/v3/shared-v3-warning.ts +50 -0
  123. package/src/speech-model/index.ts +2 -0
  124. package/src/speech-model/v2/index.ts +3 -0
  125. package/src/speech-model/v2/speech-model-v2-call-options.ts +62 -0
  126. package/src/speech-model/v2/speech-model-v2-call-warning.ts +16 -0
  127. package/src/speech-model/v2/speech-model-v2.ts +89 -0
  128. package/src/speech-model/v3/index.ts +2 -0
  129. package/src/speech-model/v3/speech-model-v3-call-options.ts +62 -0
  130. package/src/speech-model/v3/speech-model-v3.ts +89 -0
  131. package/src/transcription-model/index.ts +2 -0
  132. package/src/transcription-model/v2/index.ts +3 -0
  133. package/src/transcription-model/v2/transcription-model-v2-call-options.ts +48 -0
  134. package/src/transcription-model/v2/transcription-model-v2-call-warning.ts +16 -0
  135. package/src/transcription-model/v2/transcription-model-v2.ts +117 -0
  136. package/src/transcription-model/v3/index.ts +2 -0
  137. package/src/transcription-model/v3/transcription-model-v3-call-options.ts +45 -0
  138. package/src/transcription-model/v3/transcription-model-v3.ts +117 -0
@@ -0,0 +1,93 @@
1
+ import { EmbeddingModelV3 } from '../../embedding-model/v3/embedding-model-v3';
2
+ import { ImageModelV3 } from '../../image-model/v3/image-model-v3';
3
+ import { LanguageModelV3 } from '../../language-model/v3/language-model-v3';
4
+ import { RerankingModelV3 } from '../../reranking-model/v3/reranking-model-v3';
5
+ import { SpeechModelV3 } from '../../speech-model/v3/speech-model-v3';
6
+ import { TranscriptionModelV3 } from '../../transcription-model/v3/transcription-model-v3';
7
+
8
+ /**
9
+ * Provider for language, text embedding, and image generation models.
10
+ */
11
+ export interface ProviderV3 {
12
+ readonly specificationVersion: 'v3';
13
+
14
+ /**
15
+ * Returns the language model with the given id.
16
+ * The model id is then passed to the provider function to get the model.
17
+ *
18
+ * @param {string} modelId - The id of the model to return.
19
+ *
20
+ * @returns {LanguageModel} The language model associated with the id
21
+ *
22
+ * @throws {NoSuchModelError} If no such model exists.
23
+ */
24
+ languageModel(modelId: string): LanguageModelV3;
25
+
26
+ /**
27
+ * Returns the text embedding model with the given id.
28
+ * The model id is then passed to the provider function to get the model.
29
+ *
30
+ * @param {string} modelId - The id of the model to return.
31
+ *
32
+ * @returns {LanguageModel} The language model associated with the id
33
+ *
34
+ * @throws {NoSuchModelError} If no such model exists.
35
+ */
36
+ embeddingModel(modelId: string): EmbeddingModelV3;
37
+
38
+ /**
39
+ * Returns the text embedding model with the given id.
40
+ * The model id is then passed to the provider function to get the model.
41
+ *
42
+ * @param {string} modelId - The id of the model to return.
43
+ *
44
+ * @returns {EmbeddingModel} The embedding model associated with the id
45
+ *
46
+ * @throws {NoSuchModelError} If no such model exists.
47
+ *
48
+ * @deprecated Use `embeddingModel` instead.
49
+ */
50
+ textEmbeddingModel?(modelId: string): EmbeddingModelV3;
51
+
52
+ /**
53
+ * Returns the image model with the given id.
54
+ * The model id is then passed to the provider function to get the model.
55
+ *
56
+ * @param {string} modelId - The id of the model to return.
57
+ *
58
+ * @returns {ImageModel} The image model associated with the id
59
+ */
60
+ imageModel(modelId: string): ImageModelV3;
61
+
62
+ /**
63
+ * Returns the transcription model with the given id.
64
+ * The model id is then passed to the provider function to get the model.
65
+ *
66
+ * @param {string} modelId - The id of the model to return.
67
+ *
68
+ * @returns {TranscriptionModel} The transcription model associated with the id
69
+ */
70
+ transcriptionModel?(modelId: string): TranscriptionModelV3;
71
+
72
+ /**
73
+ * Returns the speech model with the given id.
74
+ * The model id is then passed to the provider function to get the model.
75
+ *
76
+ * @param {string} modelId - The id of the model to return.
77
+ *
78
+ * @returns {SpeechModel} The speech model associated with the id
79
+ */
80
+ speechModel?(modelId: string): SpeechModelV3;
81
+
82
+ /**
83
+ * Returns the reranking model with the given id.
84
+ * The model id is then passed to the provider function to get the model.
85
+ *
86
+ * @param {string} modelId - The id of the model to return.
87
+ *
88
+ * @returns {RerankingModel} The reranking model associated with the id
89
+ *
90
+ * @throws {NoSuchModelError} If no such model exists.
91
+ */
92
+ rerankingModel?(modelId: string): RerankingModelV3;
93
+ }
@@ -0,0 +1 @@
1
+ export * from './v3/index';
@@ -0,0 +1,2 @@
1
+ export type { RerankingModelV3 } from './reranking-model-v3';
2
+ export type { RerankingModelV3CallOptions } from './reranking-model-v3-call-options';
@@ -0,0 +1,40 @@
1
+ import { JSONObject } from '../../json-value';
2
+ import { SharedV3Headers, SharedV3ProviderOptions } from '../../shared/v3';
3
+
4
+ export type RerankingModelV3CallOptions = {
5
+ /**
6
+ * Documents to rerank.
7
+ * Either a list of texts or a list of JSON objects.
8
+ */
9
+ documents:
10
+ | { type: 'text'; values: string[] }
11
+ | { type: 'object'; values: JSONObject[] };
12
+
13
+ /**
14
+ * The query is a string that represents the query to rerank the documents against.
15
+ */
16
+ query: string;
17
+
18
+ /**
19
+ * Optional limit returned documents to the top n documents.
20
+ */
21
+ topN?: number;
22
+
23
+ /**
24
+ * Abort signal for cancelling the operation.
25
+ */
26
+ abortSignal?: AbortSignal;
27
+
28
+ /**
29
+ * Additional provider-specific options. They are passed through
30
+ * to the provider from the AI SDK and enable provider-specific
31
+ * functionality that can be fully encapsulated in the provider.
32
+ */
33
+ providerOptions?: SharedV3ProviderOptions;
34
+
35
+ /**
36
+ * Additional HTTP headers to be sent with the request.
37
+ * Only applicable for HTTP-based providers.
38
+ */
39
+ headers?: SharedV3Headers;
40
+ };
@@ -0,0 +1,90 @@
1
+ import {
2
+ SharedV3Headers,
3
+ SharedV3ProviderMetadata,
4
+ SharedV3Warning,
5
+ } from '../../shared/v3/';
6
+ import { RerankingModelV3CallOptions } from './reranking-model-v3-call-options';
7
+
8
+ /**
9
+ * Specification for a reranking model that implements the reranking model interface version 3.
10
+ */
11
+ export type RerankingModelV3 = {
12
+ /**
13
+ * The reranking model must specify which reranking model interface version it implements.
14
+ */
15
+ readonly specificationVersion: 'v3';
16
+
17
+ /**
18
+ * Provider ID.
19
+ */
20
+ readonly provider: string;
21
+
22
+ /**
23
+ * Provider-specific model ID.
24
+ */
25
+ readonly modelId: string;
26
+
27
+ /**
28
+ * Reranking a list of documents using the query.
29
+ */
30
+ // Naming: "do" prefix to prevent accidental direct usage of the method by the user.
31
+ doRerank(options: RerankingModelV3CallOptions): PromiseLike<{
32
+ /**
33
+ * Ordered list of reranked documents (via index before reranking).
34
+ * The documents are sorted by the descending order of relevance scores.
35
+ */
36
+ ranking: Array<{
37
+ /**
38
+ * The index of the document in the original list of documents before reranking.
39
+ */
40
+ index: number;
41
+
42
+ /**
43
+ * The relevance score of the document after reranking.
44
+ */
45
+ relevanceScore: number;
46
+ }>;
47
+
48
+ /**
49
+ * Additional provider-specific metadata. They are passed through
50
+ * to the provider from the AI SDK and enable provider-specific
51
+ * functionality that can be fully encapsulated in the provider.
52
+ */
53
+ providerMetadata?: SharedV3ProviderMetadata;
54
+
55
+ /**
56
+ * Warnings for the call, e.g. unsupported settings.
57
+ */
58
+ warnings?: Array<SharedV3Warning>;
59
+
60
+ /**
61
+ * Optional response information for debugging purposes.
62
+ */
63
+ response?: {
64
+ /**
65
+ * ID for the generated response, if the provider sends one.
66
+ */
67
+ id?: string;
68
+
69
+ /**
70
+ * Timestamp for the start of the generated response, if the provider sends one.
71
+ */
72
+ timestamp?: Date;
73
+
74
+ /**
75
+ * The ID of the response model that was used to generate the response, if the provider sends one.
76
+ */
77
+ modelId?: string;
78
+
79
+ /**
80
+ * Response headers.
81
+ */
82
+ headers?: SharedV3Headers;
83
+
84
+ /**
85
+ * Response body.
86
+ */
87
+ body?: unknown;
88
+ };
89
+ }>;
90
+ };
@@ -0,0 +1,2 @@
1
+ export * from './v3/index';
2
+ export * from './v2/index';
@@ -0,0 +1,3 @@
1
+ export * from './shared-v2-headers';
2
+ export * from './shared-v2-provider-metadata';
3
+ export * from './shared-v2-provider-options';
@@ -0,0 +1 @@
1
+ export type SharedV2Headers = Record<string, string>;
@@ -0,0 +1,27 @@
1
+ import { JSONValue } from '../../json-value/json-value';
2
+
3
+ /**
4
+ * Additional provider-specific metadata.
5
+ * Metadata are additional outputs from the provider.
6
+ * They are passed through to the provider from the AI SDK
7
+ * and enable provider-specific functionality
8
+ * that can be fully encapsulated in the provider.
9
+ *
10
+ * This enables us to quickly ship provider-specific functionality
11
+ * without affecting the core AI SDK.
12
+ *
13
+ * The outer record is keyed by the provider name, and the inner
14
+ * record is keyed by the provider-specific metadata key.
15
+ *
16
+ * ```ts
17
+ * {
18
+ * "anthropic": {
19
+ * "cacheControl": { "type": "ephemeral" }
20
+ * }
21
+ * }
22
+ * ```
23
+ */
24
+ export type SharedV2ProviderMetadata = Record<
25
+ string,
26
+ Record<string, JSONValue>
27
+ >;
@@ -0,0 +1,24 @@
1
+ import { JSONValue } from '../../json-value/json-value';
2
+
3
+ /**
4
+ * Additional provider-specific options.
5
+ * Options are additional input to the provider.
6
+ * They are passed through to the provider from the AI SDK
7
+ * and enable provider-specific functionality
8
+ * that can be fully encapsulated in the provider.
9
+ *
10
+ * This enables us to quickly ship provider-specific functionality
11
+ * without affecting the core AI SDK.
12
+ *
13
+ * The outer record is keyed by the provider name, and the inner
14
+ * record is keyed by the provider-specific metadata key.
15
+ *
16
+ * ```ts
17
+ * {
18
+ * "anthropic": {
19
+ * "cacheControl": { "type": "ephemeral" }
20
+ * }
21
+ * }
22
+ * ```
23
+ */
24
+ export type SharedV2ProviderOptions = Record<string, Record<string, JSONValue>>;
@@ -0,0 +1,4 @@
1
+ export * from './shared-v3-headers';
2
+ export * from './shared-v3-provider-metadata';
3
+ export * from './shared-v3-provider-options';
4
+ export * from './shared-v3-warning';
@@ -0,0 +1 @@
1
+ export type SharedV3Headers = Record<string, string>;
@@ -0,0 +1,24 @@
1
+ import { JSONObject } from '../../json-value/json-value';
2
+
3
+ /**
4
+ * Additional provider-specific metadata.
5
+ * Metadata are additional outputs from the provider.
6
+ * They are passed through to the provider from the AI SDK
7
+ * and enable provider-specific functionality
8
+ * that can be fully encapsulated in the provider.
9
+ *
10
+ * This enables us to quickly ship provider-specific functionality
11
+ * without affecting the core AI SDK.
12
+ *
13
+ * The outer record is keyed by the provider name, and the inner
14
+ * record is keyed by the provider-specific metadata key.
15
+ *
16
+ * ```ts
17
+ * {
18
+ * "anthropic": {
19
+ * "cacheControl": { "type": "ephemeral" }
20
+ * }
21
+ * }
22
+ * ```
23
+ */
24
+ export type SharedV3ProviderMetadata = Record<string, JSONObject>;
@@ -0,0 +1,24 @@
1
+ import { JSONObject } from '../../json-value/json-value';
2
+
3
+ /**
4
+ * Additional provider-specific options.
5
+ * Options are additional input to the provider.
6
+ * They are passed through to the provider from the AI SDK
7
+ * and enable provider-specific functionality
8
+ * that can be fully encapsulated in the provider.
9
+ *
10
+ * This enables us to quickly ship provider-specific functionality
11
+ * without affecting the core AI SDK.
12
+ *
13
+ * The outer record is keyed by the provider name, and the inner
14
+ * record is keyed by the provider-specific metadata key.
15
+ *
16
+ * ```ts
17
+ * {
18
+ * "anthropic": {
19
+ * "cacheControl": { "type": "ephemeral" }
20
+ * }
21
+ * }
22
+ * ```
23
+ */
24
+ export type SharedV3ProviderOptions = Record<string, JSONObject>;
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Warning from the model.
3
+ *
4
+ * For example, that certain features are unsupported or compatibility
5
+ * functionality is used (which might lead to suboptimal results).
6
+ */
7
+ export type SharedV3Warning =
8
+ | {
9
+ /**
10
+ * A feature is not supported by the model.
11
+ */
12
+ type: 'unsupported';
13
+
14
+ /**
15
+ * The feature that is not supported.
16
+ */
17
+ feature: string;
18
+
19
+ /**
20
+ * Additional details about the warning.
21
+ */
22
+ details?: string;
23
+ }
24
+ | {
25
+ /**
26
+ * A compatibility feature is used that might lead to suboptimal results.
27
+ */
28
+ type: 'compatibility';
29
+
30
+ /**
31
+ * The feature that is used in a compatibility mode.
32
+ */
33
+ feature: string;
34
+
35
+ /**
36
+ * Additional details about the warning.
37
+ */
38
+ details?: string;
39
+ }
40
+ | {
41
+ /**
42
+ * Other warning.
43
+ */
44
+ type: 'other';
45
+
46
+ /**
47
+ * The message of the warning.
48
+ */
49
+ message: string;
50
+ };
@@ -0,0 +1,2 @@
1
+ export * from './v2/index';
2
+ export * from './v3/index';
@@ -0,0 +1,3 @@
1
+ export type { SpeechModelV2 } from './speech-model-v2';
2
+ export type { SpeechModelV2CallOptions } from './speech-model-v2-call-options';
3
+ export type { SpeechModelV2CallWarning } from './speech-model-v2-call-warning';
@@ -0,0 +1,62 @@
1
+ import { JSONValue } from '../../json-value/json-value';
2
+
3
+ type SpeechModelV2ProviderOptions = Record<string, Record<string, JSONValue>>;
4
+
5
+ export type SpeechModelV2CallOptions = {
6
+ /**
7
+ * Text to convert to speech.
8
+ */
9
+ text: string;
10
+
11
+ /**
12
+ * The voice to use for speech synthesis.
13
+ * This is provider-specific and may be a voice ID, name, or other identifier.
14
+ */
15
+ voice?: string;
16
+
17
+ /**
18
+ * The desired output format for the audio e.g. "mp3", "wav", etc.
19
+ */
20
+ outputFormat?: string;
21
+
22
+ /**
23
+ * Instructions for the speech generation e.g. "Speak in a slow and steady tone".
24
+ */
25
+ instructions?: string;
26
+
27
+ /**
28
+ * The speed of the speech generation.
29
+ */
30
+ speed?: number;
31
+
32
+ /**
33
+ * The language for speech generation. This should be an ISO 639-1 language code (e.g. "en", "es", "fr")
34
+ * or "auto" for automatic language detection. Provider support varies.
35
+ */
36
+ language?: string;
37
+
38
+ /**
39
+ * Additional provider-specific options that are passed through to the provider
40
+ * as body parameters.
41
+ *
42
+ * The outer record is keyed by the provider name, and the inner
43
+ * record is keyed by the provider-specific metadata key.
44
+ * ```ts
45
+ * {
46
+ * "openai": {}
47
+ * }
48
+ * ```
49
+ */
50
+ providerOptions?: SpeechModelV2ProviderOptions;
51
+
52
+ /**
53
+ * Abort signal for cancelling the operation.
54
+ */
55
+ abortSignal?: AbortSignal;
56
+
57
+ /**
58
+ * Additional HTTP headers to be sent with the request.
59
+ * Only applicable for HTTP-based providers.
60
+ */
61
+ headers?: Record<string, string | undefined>;
62
+ };
@@ -0,0 +1,16 @@
1
+ import { SpeechModelV2CallOptions } from './speech-model-v2-call-options';
2
+
3
+ /**
4
+ * Warning from the model provider for this call. The call will proceed, but e.g.
5
+ * some settings might not be supported, which can lead to suboptimal results.
6
+ */
7
+ export type SpeechModelV2CallWarning =
8
+ | {
9
+ type: 'unsupported-setting';
10
+ setting: keyof SpeechModelV2CallOptions;
11
+ details?: string;
12
+ }
13
+ | {
14
+ type: 'other';
15
+ message: string;
16
+ };
@@ -0,0 +1,89 @@
1
+ import { JSONValue } from '../../json-value';
2
+ import { SharedV2Headers } from '../../shared';
3
+ import { SpeechModelV2CallOptions } from './speech-model-v2-call-options';
4
+ import { SpeechModelV2CallWarning } from './speech-model-v2-call-warning';
5
+
6
+ /**
7
+ * Speech model specification version 2.
8
+ */
9
+ export type SpeechModelV2 = {
10
+ /**
11
+ * The speech model must specify which speech model interface
12
+ * version it implements. This will allow us to evolve the speech
13
+ * model interface and retain backwards compatibility. The different
14
+ * implementation versions can be handled as a discriminated union
15
+ * on our side.
16
+ */
17
+ readonly specificationVersion: 'v2';
18
+
19
+ /**
20
+ * Name of the provider for logging purposes.
21
+ */
22
+ readonly provider: string;
23
+
24
+ /**
25
+ * Provider-specific model ID for logging purposes.
26
+ */
27
+ readonly modelId: string;
28
+
29
+ /**
30
+ * Generates speech audio from text.
31
+ */
32
+ doGenerate(options: SpeechModelV2CallOptions): PromiseLike<{
33
+ /**
34
+ * Generated audio as an ArrayBuffer.
35
+ * The audio should be returned without any unnecessary conversion.
36
+ * If the API returns base64 encoded strings, the audio should be returned
37
+ * as base64 encoded strings. If the API returns binary data, the audio
38
+ * should be returned as binary data.
39
+ */
40
+ audio: string | Uint8Array;
41
+
42
+ /**
43
+ * Warnings for the call, e.g. unsupported settings.
44
+ */
45
+ warnings: Array<SpeechModelV2CallWarning>;
46
+
47
+ /**
48
+ * Optional request information for telemetry and debugging purposes.
49
+ */
50
+ request?: {
51
+ /**
52
+ * Response body (available only for providers that use HTTP requests).
53
+ */
54
+ body?: unknown;
55
+ };
56
+
57
+ /**
58
+ * Response information for telemetry and debugging purposes.
59
+ */
60
+ response: {
61
+ /**
62
+ * Timestamp for the start of the generated response.
63
+ */
64
+ timestamp: Date;
65
+
66
+ /**
67
+ * The ID of the response model that was used to generate the response.
68
+ */
69
+ modelId: string;
70
+
71
+ /**
72
+ * Response headers.
73
+ */
74
+ headers?: SharedV2Headers;
75
+
76
+ /**
77
+ * Response body.
78
+ */
79
+ body?: unknown;
80
+ };
81
+
82
+ /**
83
+ * Additional provider-specific metadata. They are passed through
84
+ * from the provider to the AI SDK and enable provider-specific
85
+ * results that can be fully encapsulated in the provider.
86
+ */
87
+ providerMetadata?: Record<string, Record<string, JSONValue>>;
88
+ }>;
89
+ };
@@ -0,0 +1,2 @@
1
+ export type { SpeechModelV3 } from './speech-model-v3';
2
+ export type { SpeechModelV3CallOptions } from './speech-model-v3-call-options';
@@ -0,0 +1,62 @@
1
+ import { JSONObject } from '../../json-value/json-value';
2
+
3
+ type SpeechModelV3ProviderOptions = Record<string, JSONObject>;
4
+
5
+ export type SpeechModelV3CallOptions = {
6
+ /**
7
+ * Text to convert to speech.
8
+ */
9
+ text: string;
10
+
11
+ /**
12
+ * The voice to use for speech synthesis.
13
+ * This is provider-specific and may be a voice ID, name, or other identifier.
14
+ */
15
+ voice?: string;
16
+
17
+ /**
18
+ * The desired output format for the audio e.g. "mp3", "wav", etc.
19
+ */
20
+ outputFormat?: string;
21
+
22
+ /**
23
+ * Instructions for the speech generation e.g. "Speak in a slow and steady tone".
24
+ */
25
+ instructions?: string;
26
+
27
+ /**
28
+ * The speed of the speech generation.
29
+ */
30
+ speed?: number;
31
+
32
+ /**
33
+ * The language for speech generation. This should be an ISO 639-1 language code (e.g. "en", "es", "fr")
34
+ * or "auto" for automatic language detection. Provider support varies.
35
+ */
36
+ language?: string;
37
+
38
+ /**
39
+ * Additional provider-specific options that are passed through to the provider
40
+ * as body parameters.
41
+ *
42
+ * The outer record is keyed by the provider name, and the inner
43
+ * record is keyed by the provider-specific metadata key.
44
+ * ```ts
45
+ * {
46
+ * "openai": {}
47
+ * }
48
+ * ```
49
+ */
50
+ providerOptions?: SpeechModelV3ProviderOptions;
51
+
52
+ /**
53
+ * Abort signal for cancelling the operation.
54
+ */
55
+ abortSignal?: AbortSignal;
56
+
57
+ /**
58
+ * Additional HTTP headers to be sent with the request.
59
+ * Only applicable for HTTP-based providers.
60
+ */
61
+ headers?: Record<string, string | undefined>;
62
+ };