@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,108 @@
1
+ import { AISDKError } from './ai-sdk-error';
2
+ import { getErrorMessage } from './get-error-message';
3
+
4
+ const name = 'AI_TypeValidationError';
5
+ const marker = `vercel.ai.error.${name}`;
6
+ const symbol = Symbol.for(marker);
7
+
8
+ export interface TypeValidationContext {
9
+ /**
10
+ * Field path in dot notation (e.g., "message.metadata", "message.parts[3].data")
11
+ */
12
+ field?: string;
13
+
14
+ /**
15
+ * Entity name (e.g., tool name, data type name)
16
+ */
17
+ entityName?: string;
18
+
19
+ /**
20
+ * Entity identifier (e.g., message ID, tool call ID)
21
+ */
22
+ entityId?: string;
23
+ }
24
+
25
+ export class TypeValidationError extends AISDKError {
26
+ private readonly [symbol] = true; // used in isInstance
27
+
28
+ readonly value: unknown;
29
+ readonly context?: TypeValidationContext;
30
+
31
+ constructor({
32
+ value,
33
+ cause,
34
+ context,
35
+ }: {
36
+ value: unknown;
37
+ cause: unknown;
38
+ context?: TypeValidationContext;
39
+ }) {
40
+ let contextPrefix = 'Type validation failed';
41
+
42
+ if (context?.field) {
43
+ contextPrefix += ` for ${context.field}`;
44
+ }
45
+
46
+ if (context?.entityName || context?.entityId) {
47
+ contextPrefix += ' (';
48
+ const parts: string[] = [];
49
+ if (context.entityName) {
50
+ parts.push(context.entityName);
51
+ }
52
+ if (context.entityId) {
53
+ parts.push(`id: "${context.entityId}"`);
54
+ }
55
+ contextPrefix += parts.join(', ');
56
+ contextPrefix += ')';
57
+ }
58
+
59
+ super({
60
+ name,
61
+ message:
62
+ `${contextPrefix}: ` +
63
+ `Value: ${JSON.stringify(value)}.\n` +
64
+ `Error message: ${getErrorMessage(cause)}`,
65
+ cause,
66
+ });
67
+
68
+ this.value = value;
69
+ this.context = context;
70
+ }
71
+
72
+ static isInstance(error: unknown): error is TypeValidationError {
73
+ return AISDKError.hasMarker(error, marker);
74
+ }
75
+
76
+ /**
77
+ * Wraps an error into a TypeValidationError.
78
+ * If the cause is already a TypeValidationError with the same value and context, it returns the cause.
79
+ * Otherwise, it creates a new TypeValidationError.
80
+ *
81
+ * @param {Object} params - The parameters for wrapping the error.
82
+ * @param {unknown} params.value - The value that failed validation.
83
+ * @param {unknown} params.cause - The original error or cause of the validation failure.
84
+ * @param {TypeValidationContext} params.context - Optional context about what is being validated.
85
+ * @returns {TypeValidationError} A TypeValidationError instance.
86
+ */
87
+ static wrap({
88
+ value,
89
+ cause,
90
+ context,
91
+ }: {
92
+ value: unknown;
93
+ cause: unknown;
94
+ context?: TypeValidationContext;
95
+ }): TypeValidationError {
96
+ if (
97
+ TypeValidationError.isInstance(cause) &&
98
+ cause.value === value &&
99
+ cause.context?.field === context?.field &&
100
+ cause.context?.entityName === context?.entityName &&
101
+ cause.context?.entityId === context?.entityId
102
+ ) {
103
+ return cause;
104
+ }
105
+
106
+ return new TypeValidationError({ value, cause, context });
107
+ }
108
+ }
@@ -0,0 +1,26 @@
1
+ import { AISDKError } from './ai-sdk-error';
2
+
3
+ const name = 'AI_UnsupportedFunctionalityError';
4
+ const marker = `vercel.ai.error.${name}`;
5
+ const symbol = Symbol.for(marker);
6
+
7
+ export class UnsupportedFunctionalityError extends AISDKError {
8
+ private readonly [symbol] = true; // used in isInstance
9
+
10
+ readonly functionality: string;
11
+
12
+ constructor({
13
+ functionality,
14
+ message = `'${functionality}' functionality not supported.`,
15
+ }: {
16
+ functionality: string;
17
+ message?: string;
18
+ }) {
19
+ super({ name, message });
20
+ this.functionality = functionality;
21
+ }
22
+
23
+ static isInstance(error: unknown): error is UnsupportedFunctionalityError {
24
+ return AISDKError.hasMarker(error, marker);
25
+ }
26
+ }
@@ -0,0 +1,2 @@
1
+ export * from './v3/index';
2
+ export * from './v2/index';
@@ -0,0 +1,60 @@
1
+ import { SharedV2ProviderOptions } from '../../shared';
2
+
3
+ export type ImageModelV2CallOptions = {
4
+ /**
5
+ * Prompt for the image generation.
6
+ */
7
+ prompt: string;
8
+
9
+ /**
10
+ * Number of images to generate.
11
+ */
12
+ n: number;
13
+
14
+ /**
15
+ * Size of the images to generate.
16
+ * Must have the format `{width}x{height}`.
17
+ * `undefined` will use the provider's default size.
18
+ */
19
+ size: `${number}x${number}` | undefined;
20
+
21
+ /**
22
+ * Aspect ratio of the images to generate.
23
+ * Must have the format `{width}:{height}`.
24
+ * `undefined` will use the provider's default aspect ratio.
25
+ */
26
+ aspectRatio: `${number}:${number}` | undefined;
27
+
28
+ /**
29
+ * Seed for the image generation.
30
+ * `undefined` will use the provider's default seed.
31
+ */
32
+ seed: number | undefined;
33
+
34
+ /**
35
+ * Additional provider-specific options that are passed through to the provider
36
+ * as body parameters.
37
+ *
38
+ * The outer record is keyed by the provider name, and the inner
39
+ * record is keyed by the provider-specific metadata key.
40
+ * ```ts
41
+ * {
42
+ * "openai": {
43
+ * "style": "vivid"
44
+ * }
45
+ * }
46
+ * ```
47
+ */
48
+ providerOptions: SharedV2ProviderOptions;
49
+
50
+ /**
51
+ * Abort signal for cancelling the operation.
52
+ */
53
+ abortSignal?: AbortSignal;
54
+
55
+ /**
56
+ * Additional HTTP headers to be sent with the request.
57
+ * Only applicable for HTTP-based providers.
58
+ */
59
+ headers?: Record<string, string | undefined>;
60
+ };
@@ -0,0 +1,16 @@
1
+ import { ImageModelV2CallOptions } from './image-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 ImageModelV2CallWarning =
8
+ | {
9
+ type: 'unsupported-setting';
10
+ setting: keyof ImageModelV2CallOptions;
11
+ details?: string;
12
+ }
13
+ | {
14
+ type: 'other';
15
+ message: string;
16
+ };
@@ -0,0 +1,104 @@
1
+ import { JSONArray, JSONValue } from '../../json-value';
2
+ import { ImageModelV2CallOptions } from './image-model-v2-call-options';
3
+ import { ImageModelV2CallWarning } from './image-model-v2-call-warning';
4
+
5
+ export type ImageModelV2ProviderMetadata = Record<
6
+ string,
7
+ {
8
+ images: JSONArray;
9
+ } & JSONValue
10
+ >;
11
+
12
+ type GetMaxImagesPerCallFunction = (options: {
13
+ modelId: string;
14
+ }) => PromiseLike<number | undefined> | number | undefined;
15
+
16
+ /**
17
+ * Image generation model specification version 2.
18
+ */
19
+ export type ImageModelV2 = {
20
+ /**
21
+ * The image model must specify which image model interface
22
+ * version it implements. This will allow us to evolve the image
23
+ * model interface and retain backwards compatibility. The different
24
+ * implementation versions can be handled as a discriminated union
25
+ * on our side.
26
+ */
27
+ readonly specificationVersion: 'v2';
28
+
29
+ /**
30
+ * Name of the provider for logging purposes.
31
+ */
32
+ readonly provider: string;
33
+
34
+ /**
35
+ * Provider-specific model ID for logging purposes.
36
+ */
37
+ readonly modelId: string;
38
+
39
+ /**
40
+ * Limit of how many images can be generated in a single API call.
41
+ * Can be set to a number for a fixed limit, to undefined to use
42
+ * the global limit, or a function that returns a number or undefined,
43
+ * optionally as a promise.
44
+ */
45
+ readonly maxImagesPerCall: number | undefined | GetMaxImagesPerCallFunction;
46
+
47
+ /**
48
+ * Generates an array of images.
49
+ */
50
+ doGenerate(options: ImageModelV2CallOptions): PromiseLike<{
51
+ /**
52
+ * Generated images as base64 encoded strings or binary data.
53
+ * The images should be returned without any unnecessary conversion.
54
+ * If the API returns base64 encoded strings, the images should be returned
55
+ * as base64 encoded strings. If the API returns binary data, the images should
56
+ * be returned as binary data.
57
+ */
58
+ images: Array<string> | Array<Uint8Array>;
59
+
60
+ /**
61
+ * Warnings for the call, e.g. unsupported settings.
62
+ */
63
+ warnings: Array<ImageModelV2CallWarning>;
64
+
65
+ /**
66
+ * Additional provider-specific metadata. They are passed through
67
+ * from the provider to the AI SDK and enable provider-specific
68
+ * results that can be fully encapsulated in the provider.
69
+ *
70
+ * The outer record is keyed by the provider name, and the inner
71
+ * record is provider-specific metadata. It always includes an
72
+ * `images` key with image-specific metadata
73
+ *
74
+ * ```ts
75
+ * {
76
+ * "openai": {
77
+ * "images": ["revisedPrompt": "Revised prompt here."]
78
+ * }
79
+ * }
80
+ * ```
81
+ */
82
+ providerMetadata?: ImageModelV2ProviderMetadata;
83
+
84
+ /**
85
+ * Response information for telemetry and debugging purposes.
86
+ */
87
+ response: {
88
+ /**
89
+ * Timestamp for the start of the generated response.
90
+ */
91
+ timestamp: Date;
92
+
93
+ /**
94
+ * The ID of the response model that was used to generate the response.
95
+ */
96
+ modelId: string;
97
+
98
+ /**
99
+ * Response headers.
100
+ */
101
+ headers: Record<string, string> | undefined;
102
+ };
103
+ }>;
104
+ };
@@ -0,0 +1,6 @@
1
+ export type {
2
+ ImageModelV2,
3
+ ImageModelV2ProviderMetadata,
4
+ } from './image-model-v2';
5
+ export type { ImageModelV2CallOptions } from './image-model-v2-call-options';
6
+ export type { ImageModelV2CallWarning } from './image-model-v2-call-warning';
@@ -0,0 +1,74 @@
1
+ import { SharedV3ProviderOptions } from '../../shared';
2
+ import { ImageModelV3File } from './image-model-v3-file';
3
+
4
+ export type ImageModelV3CallOptions = {
5
+ /**
6
+ * Prompt for the image generation. Some operations, like upscaling, may not require a prompt.
7
+ */
8
+ prompt: string | undefined;
9
+
10
+ /**
11
+ * Number of images to generate.
12
+ */
13
+ n: number;
14
+
15
+ /**
16
+ * Size of the images to generate.
17
+ * Must have the format `{width}x{height}`.
18
+ * `undefined` will use the provider's default size.
19
+ */
20
+ size: `${number}x${number}` | undefined;
21
+
22
+ /**
23
+ * Aspect ratio of the images to generate.
24
+ * Must have the format `{width}:{height}`.
25
+ * `undefined` will use the provider's default aspect ratio.
26
+ */
27
+ aspectRatio: `${number}:${number}` | undefined;
28
+
29
+ /**
30
+ * Seed for the image generation.
31
+ * `undefined` will use the provider's default seed.
32
+ */
33
+ seed: number | undefined;
34
+
35
+ /**
36
+ * Array of images for image editing or variation generation.
37
+ * The images should be provided as base64 encoded strings or binary data.
38
+ */
39
+ files: ImageModelV3File[] | undefined;
40
+
41
+ /**
42
+ * Mask image for inpainting operations.
43
+ * The mask should be provided as base64 encoded strings or binary data.
44
+ */
45
+ mask: ImageModelV3File | undefined;
46
+
47
+ /**
48
+ * Additional provider-specific options that are passed through to the provider
49
+ * as body parameters.
50
+ *
51
+ * The outer record is keyed by the provider name, and the inner
52
+ * record is keyed by the provider-specific metadata key.
53
+ *
54
+ * ```ts
55
+ * {
56
+ * "openai": {
57
+ * "style": "vivid"
58
+ * }
59
+ * }
60
+ * ```
61
+ */
62
+ providerOptions: SharedV3ProviderOptions;
63
+
64
+ /**
65
+ * Abort signal for cancelling the operation.
66
+ */
67
+ abortSignal?: AbortSignal;
68
+
69
+ /**
70
+ * Additional HTTP headers to be sent with the request.
71
+ * Only applicable for HTTP-based providers.
72
+ */
73
+ headers?: Record<string, string | undefined>;
74
+ };
@@ -0,0 +1,44 @@
1
+ import { SharedV3ProviderMetadata } from '../../shared';
2
+
3
+ /**
4
+ * An image file that can be used for image editing or variation generation.
5
+ */
6
+ export type ImageModelV3File =
7
+ | {
8
+ type: 'file';
9
+
10
+ /**
11
+ * The IANA media type of the file, e.g. `image/png`. Any string is supported.
12
+ *
13
+ * @see https://www.iana.org/assignments/media-types/media-types.xhtml
14
+ */
15
+ mediaType: string;
16
+
17
+ /**
18
+ * Generated file data as base64 encoded strings or binary data.
19
+ *
20
+ * The file data should be returned without any unnecessary conversion.
21
+ * If the API returns base64 encoded strings, the file data should be returned
22
+ * as base64 encoded strings. If the API returns binary data, the file data should
23
+ * be returned as binary data.
24
+ */
25
+ data: string | Uint8Array;
26
+
27
+ /**
28
+ * Optional provider-specific metadata for the file part.
29
+ */
30
+ providerOptions?: SharedV3ProviderMetadata;
31
+ }
32
+ | {
33
+ type: 'url';
34
+
35
+ /**
36
+ * The URL of the image file.
37
+ */
38
+ url: string;
39
+
40
+ /**
41
+ * Optional provider-specific metadata for the file part.
42
+ */
43
+ providerOptions?: SharedV3ProviderMetadata;
44
+ };
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Usage information for an image model call.
3
+ */
4
+ export type ImageModelV3Usage = {
5
+ /**
6
+ * The number of input (prompt) tokens used.
7
+ */
8
+ inputTokens: number | undefined;
9
+
10
+ /**
11
+ * The number of output tokens used, if reported by the provider.
12
+ */
13
+ outputTokens: number | undefined;
14
+
15
+ /**
16
+ * The total number of tokens as reported by the provider.
17
+ */
18
+ totalTokens: number | undefined;
19
+ };
@@ -0,0 +1,110 @@
1
+ import { JSONArray, JSONValue } from '../../json-value';
2
+ import { ImageModelV3Usage } from './image-model-v3-usage';
3
+ import { ImageModelV3CallOptions } from './image-model-v3-call-options';
4
+ import { SharedV3Warning } from '../../shared/v3/shared-v3-warning';
5
+
6
+ export type ImageModelV3ProviderMetadata = Record<
7
+ string,
8
+ {
9
+ images: JSONArray;
10
+ } & JSONValue
11
+ >;
12
+
13
+ type GetMaxImagesPerCallFunction = (options: {
14
+ modelId: string;
15
+ }) => PromiseLike<number | undefined> | number | undefined;
16
+
17
+ /**
18
+ * Image generation model specification version 3.
19
+ */
20
+ export type ImageModelV3 = {
21
+ /**
22
+ * The image model must specify which image model interface
23
+ * version it implements. This will allow us to evolve the image
24
+ * model interface and retain backwards compatibility. The different
25
+ * implementation versions can be handled as a discriminated union
26
+ * on our side.
27
+ */
28
+ readonly specificationVersion: 'v3';
29
+
30
+ /**
31
+ * Name of the provider for logging purposes.
32
+ */
33
+ readonly provider: string;
34
+
35
+ /**
36
+ * Provider-specific model ID for logging purposes.
37
+ */
38
+ readonly modelId: string;
39
+
40
+ /**
41
+ * Limit of how many images can be generated in a single API call.
42
+ * Can be set to a number for a fixed limit, to undefined to use
43
+ * the global limit, or a function that returns a number or undefined,
44
+ * optionally as a promise.
45
+ */
46
+ readonly maxImagesPerCall: number | undefined | GetMaxImagesPerCallFunction;
47
+
48
+ /**
49
+ * Generates an array of images.
50
+ */
51
+ doGenerate(options: ImageModelV3CallOptions): PromiseLike<{
52
+ /**
53
+ * Generated images as base64 encoded strings or binary data.
54
+ * The images should be returned without any unnecessary conversion.
55
+ * If the API returns base64 encoded strings, the images should be returned
56
+ * as base64 encoded strings. If the API returns binary data, the images should
57
+ * be returned as binary data.
58
+ */
59
+ images: Array<string> | Array<Uint8Array>;
60
+
61
+ /**
62
+ * Warnings for the call, e.g. unsupported features.
63
+ */
64
+ warnings: Array<SharedV3Warning>;
65
+
66
+ /**
67
+ * Additional provider-specific metadata. They are passed through
68
+ * from the provider to the AI SDK and enable provider-specific
69
+ * results that can be fully encapsulated in the provider.
70
+ *
71
+ * The outer record is keyed by the provider name, and the inner
72
+ * record is provider-specific metadata. It always includes an
73
+ * `images` key with image-specific metadata
74
+ *
75
+ * ```ts
76
+ * {
77
+ * "openai": {
78
+ * "images": ["revisedPrompt": "Revised prompt here."]
79
+ * }
80
+ * }
81
+ * ```
82
+ */
83
+ providerMetadata?: ImageModelV3ProviderMetadata;
84
+
85
+ /**
86
+ * Response information for telemetry and debugging purposes.
87
+ */
88
+ response: {
89
+ /**
90
+ * Timestamp for the start of the generated response.
91
+ */
92
+ timestamp: Date;
93
+
94
+ /**
95
+ * The ID of the response model that was used to generate the response.
96
+ */
97
+ modelId: string;
98
+
99
+ /**
100
+ * Response headers.
101
+ */
102
+ headers: Record<string, string> | undefined;
103
+ };
104
+
105
+ /**
106
+ * Optional token usage for the image generation call (if the provider reports it).
107
+ */
108
+ usage?: ImageModelV3Usage;
109
+ }>;
110
+ };
@@ -0,0 +1,7 @@
1
+ export type {
2
+ ImageModelV3,
3
+ ImageModelV3ProviderMetadata,
4
+ } from './image-model-v3';
5
+ export type { ImageModelV3CallOptions } from './image-model-v3-call-options';
6
+ export type { ImageModelV3Usage } from './image-model-v3-usage';
7
+ export type { ImageModelV3File } from './image-model-v3-file';
@@ -0,0 +1 @@
1
+ export * from './v3/index';
@@ -0,0 +1,61 @@
1
+ import { ImageModelV3 } from '../../image-model/v3/image-model-v3';
2
+ import { ImageModelV3CallOptions } from '../../image-model/v3/image-model-v3-call-options';
3
+
4
+ /**
5
+ * Middleware for ImageModelV3.
6
+ * This type defines the structure for middleware that can be used to modify
7
+ * the behavior of ImageModelV3 operations.
8
+ */
9
+ export type ImageModelV3Middleware = {
10
+ /**
11
+ * Middleware specification version. Use `v3` for the current version.
12
+ */
13
+ readonly specificationVersion: 'v3';
14
+
15
+ /**
16
+ * Override the provider name if desired.
17
+ * @param options.model - The image model instance.
18
+ */
19
+ overrideProvider?: (options: { model: ImageModelV3 }) => string;
20
+
21
+ /**
22
+ * Override the model ID if desired.
23
+ * @param options.model - The image model instance.
24
+ */
25
+ overrideModelId?: (options: { model: ImageModelV3 }) => string;
26
+
27
+ /**
28
+ * Override the limit of how many images can be generated in a single API call if desired.
29
+ * @param options.model - The image model instance.
30
+ */
31
+ overrideMaxImagesPerCall?: (options: {
32
+ model: ImageModelV3;
33
+ }) => ImageModelV3['maxImagesPerCall'];
34
+
35
+ /**
36
+ * Transforms the parameters before they are passed to the image model.
37
+ * @param options - Object containing the parameters.
38
+ * @param options.params - The original parameters for the image model call.
39
+ * @returns A promise that resolves to the transformed parameters.
40
+ */
41
+ transformParams?: (options: {
42
+ params: ImageModelV3CallOptions;
43
+ model: ImageModelV3;
44
+ }) => PromiseLike<ImageModelV3CallOptions>;
45
+
46
+ /**
47
+ * Wraps the generate operation of the image model.
48
+ *
49
+ * @param options - Object containing the generate function, parameters, and model.
50
+ * @param options.doGenerate - The original generate function.
51
+ * @param options.params - The parameters for the generate call. If the
52
+ * `transformParams` middleware is used, this will be the transformed parameters.
53
+ * @param options.model - The image model instance.
54
+ * @returns A promise that resolves to the result of the generate operation.
55
+ */
56
+ wrapGenerate?: (options: {
57
+ doGenerate: () => ReturnType<ImageModelV3['doGenerate']>;
58
+ params: ImageModelV3CallOptions;
59
+ model: ImageModelV3;
60
+ }) => Promise<Awaited<ReturnType<ImageModelV3['doGenerate']>>>;
61
+ };
@@ -0,0 +1 @@
1
+ export * from './image-model-v3-middleware';
package/src/index.ts ADDED
@@ -0,0 +1,15 @@
1
+ export * from './embedding-model/index';
2
+ export * from './errors/index';
3
+ export * from './image-model/index';
4
+ export * from './image-model-middleware/index';
5
+ export * from './json-value/index';
6
+ export * from './language-model-middleware/index';
7
+ export * from './embedding-model-middleware/index';
8
+ export * from './language-model/index';
9
+ export * from './provider/index';
10
+ export * from './reranking-model/index';
11
+ export * from './shared/index';
12
+ export * from './speech-model/index';
13
+ export * from './transcription-model/index';
14
+
15
+ export type { JSONSchema7, JSONSchema7Definition } from 'json-schema';
@@ -0,0 +1,2 @@
1
+ export { isJSONArray, isJSONObject, isJSONValue } from './is-json';
2
+ export type { JSONArray, JSONObject, JSONValue } from './json-value';