eve
Version:
Filesystem-first framework for durable backend AI agents that run anywhere.
1,616 lines (1,558 loc) • 228 kB
TypeScript
import { JSONSchema7 } from './_json-schema.js';
export { JSONSchema7, JSONSchema7Definition } from './_json-schema.js';
/**
* A mapping of provider names to provider-specific file identifiers.
*
* Provider references allow files to be identified across different
* providers without re-uploading, by storing each provider's own
* identifier for the same logical file.
*
* ```ts
* {
* "openai": "file-abc123",
* "anthropic": "file-xyz789"
* }
* ```
*
* The `type?: never` constraint excludes any object that has a `type`
* property, so a `SharedV4ProviderReference` cannot be confused with a
* tagged file-data shape (e.g. `{ type: 'data', data }` or
* `{ type: 'reference', reference }`) when both appear in the same union.
*/
type SharedV4ProviderReference = Record<string, string> & {
type?: never;
};
/**
* File data variant containing raw bytes (`Uint8Array`) or a base64-encoded
* string.
*/
interface SharedV4FileDataData {
type: 'data';
data: Uint8Array | string;
}
/**
* File data variant containing a URL that points to the file.
*/
interface SharedV4FileDataUrl {
type: 'url';
url: URL;
}
/**
* File data variant containing a provider reference (`{ [provider]: id }`).
*/
interface SharedV4FileDataReference {
type: 'reference';
reference: SharedV4ProviderReference;
}
/**
* File data variant containing inline text content (e.g. an inline text
* document).
*/
interface SharedV4FileDataText {
type: 'text';
text: string;
}
/**
* File data as a tagged discriminated union:
*
* - `{ type: 'data', data }`: raw bytes (`Uint8Array`) or base64-encoded string.
* - `{ type: 'url', url }`: a URL that points to the file.
* - `{ type: 'reference', reference }`: a provider reference (`{ [provider]: id }`).
* - `{ type: 'text', text }`: inline text content (e.g. an inline text document).
*/
type SharedV4FileData = SharedV4FileDataData | SharedV4FileDataUrl | SharedV4FileDataReference | SharedV4FileDataText;
type SharedV4Headers = Record<string, string>;
/**
* A JSON value can be a string, number, boolean, object, array, or null.
* JSON values can be serialized and deserialized by the JSON.stringify and JSON.parse methods.
*/
type JSONValue = null | string | number | boolean | JSONObject | JSONArray;
type JSONObject = {
[key: string]: JSONValue | undefined;
};
type JSONArray = JSONValue[];
/**
* Additional provider-specific metadata.
* Metadata are additional outputs from the provider.
* They are passed through to the provider from the AI SDK
* and enable provider-specific functionality
* that can be fully encapsulated in the provider.
*
* This enables us to quickly ship provider-specific functionality
* without affecting the core AI SDK.
*
* The outer record is keyed by the provider name, and the inner
* record is keyed by the provider-specific metadata key.
*
* ```ts
* {
* "anthropic": {
* "cacheControl": { "type": "ephemeral" }
* }
* }
* ```
*/
type SharedV4ProviderMetadata = Record<string, JSONObject>;
/**
* Additional provider-specific options.
* Options are additional input to the provider.
* They are passed through to the provider from the AI SDK
* and enable provider-specific functionality
* that can be fully encapsulated in the provider.
*
* This enables us to quickly ship provider-specific functionality
* without affecting the core AI SDK.
*
* The outer record is keyed by the provider name, and the inner
* record is keyed by the provider-specific metadata key.
*
* ```ts
* {
* "anthropic": {
* "cacheControl": { "type": "ephemeral" }
* }
* }
* ```
*/
type SharedV4ProviderOptions = Record<string, JSONObject>;
/**
* Warning from the model.
*
* For example, that certain features are unsupported or compatibility
* functionality is used (which might lead to suboptimal results).
*/
type SharedV4Warning = {
/**
* A feature is not supported by the model.
*/
type: 'unsupported';
/**
* The feature that is not supported.
*/
feature: string;
/**
* Additional details about the warning.
*/
details?: string;
} | {
/**
* A compatibility feature is used that might lead to suboptimal results.
*/
type: 'compatibility';
/**
* The feature that is used in a compatibility mode.
*/
feature: string;
/**
* Additional details about the warning.
*/
details?: string;
} | {
/**
* A deprecated feature or option is being used.
*/
type: 'deprecated';
/**
* The deprecated setting or feature name.
*/
setting: string;
/**
* A human-readable message explaining what to use instead.
*/
message: string;
} | {
/**
* Other warning.
*/
type: 'other';
/**
* The message of the warning.
*/
message: string;
};
type SharedV3Headers = Record<string, string>;
/**
* Additional provider-specific metadata.
* Metadata are additional outputs from the provider.
* They are passed through to the provider from the AI SDK
* and enable provider-specific functionality
* that can be fully encapsulated in the provider.
*
* This enables us to quickly ship provider-specific functionality
* without affecting the core AI SDK.
*
* The outer record is keyed by the provider name, and the inner
* record is keyed by the provider-specific metadata key.
*
* ```ts
* {
* "anthropic": {
* "cacheControl": { "type": "ephemeral" }
* }
* }
* ```
*/
type SharedV3ProviderMetadata = Record<string, JSONObject>;
/**
* Additional provider-specific options.
* Options are additional input to the provider.
* They are passed through to the provider from the AI SDK
* and enable provider-specific functionality
* that can be fully encapsulated in the provider.
*
* This enables us to quickly ship provider-specific functionality
* without affecting the core AI SDK.
*
* The outer record is keyed by the provider name, and the inner
* record is keyed by the provider-specific metadata key.
*
* ```ts
* {
* "anthropic": {
* "cacheControl": { "type": "ephemeral" }
* }
* }
* ```
*/
type SharedV3ProviderOptions = Record<string, JSONObject>;
/**
* Warning from the model.
*
* For example, that certain features are unsupported or compatibility
* functionality is used (which might lead to suboptimal results).
*/
type SharedV3Warning = {
/**
* A feature is not supported by the model.
*/
type: 'unsupported';
/**
* The feature that is not supported.
*/
feature: string;
/**
* Additional details about the warning.
*/
details?: string;
} | {
/**
* A compatibility feature is used that might lead to suboptimal results.
*/
type: 'compatibility';
/**
* The feature that is used in a compatibility mode.
*/
feature: string;
/**
* Additional details about the warning.
*/
details?: string;
} | {
/**
* Other warning.
*/
type: 'other';
/**
* The message of the warning.
*/
message: string;
};
type SharedV2Headers = Record<string, string>;
/**
* Additional provider-specific metadata.
* Metadata are additional outputs from the provider.
* They are passed through to the provider from the AI SDK
* and enable provider-specific functionality
* that can be fully encapsulated in the provider.
*
* This enables us to quickly ship provider-specific functionality
* without affecting the core AI SDK.
*
* The outer record is keyed by the provider name, and the inner
* record is keyed by the provider-specific metadata key.
*
* ```ts
* {
* "anthropic": {
* "cacheControl": { "type": "ephemeral" }
* }
* }
* ```
*/
type SharedV2ProviderMetadata = Record<string, Record<string, JSONValue>>;
/**
* Additional provider-specific options.
* Options are additional input to the provider.
* They are passed through to the provider from the AI SDK
* and enable provider-specific functionality
* that can be fully encapsulated in the provider.
*
* This enables us to quickly ship provider-specific functionality
* without affecting the core AI SDK.
*
* The outer record is keyed by the provider name, and the inner
* record is keyed by the provider-specific metadata key.
*
* ```ts
* {
* "anthropic": {
* "cacheControl": { "type": "ephemeral" }
* }
* }
* ```
*/
type SharedV2ProviderOptions = Record<string, Record<string, JSONValue>>;
type EmbeddingModelV4CallOptions = {
/**
* List of text values to generate embeddings for.
*/
values: Array<string>;
/**
* Abort signal for cancelling the operation.
*/
abortSignal?: AbortSignal;
/**
* Additional provider-specific options. They are passed through
* to the provider from the AI SDK and enable provider-specific
* functionality that can be fully encapsulated in the provider.
*/
providerOptions?: SharedV4ProviderOptions;
/**
* Additional HTTP headers to be sent with the request.
* Only applicable for HTTP-based providers.
*/
headers?: SharedV4Headers;
};
/**
* An embedding is a vector, i.e. an array of numbers.
* It is e.g. used to represent a text as a vector of word embeddings.
*/
type EmbeddingModelV4Embedding = Array<number>;
/**
* The result of a embedding model doEmbed call.
*/
type EmbeddingModelV4Result = {
/**
* Generated embeddings. They are in the same order as the input values.
*/
embeddings: Array<EmbeddingModelV4Embedding>;
/**
* Token usage. We only have input tokens for embeddings.
*/
usage?: {
tokens: number;
};
/**
* Additional provider-specific metadata. They are passed through
* from the provider to the AI SDK and enable provider-specific
* results that can be fully encapsulated in the provider.
*/
providerMetadata?: SharedV4ProviderMetadata;
/**
* Optional response information for debugging purposes.
*/
response?: {
/**
* Response headers.
*/
headers?: SharedV4Headers;
/**
* The response body.
*/
body?: unknown;
};
/**
* Warnings for the call, e.g. unsupported settings.
*/
warnings: Array<SharedV4Warning>;
};
/**
* Specification for an embedding model that implements the embedding model
* interface version 3.
*
* It is specific to text embeddings.
*/
type EmbeddingModelV4 = {
/**
* The embedding model must specify which embedding model interface
* version it implements. This will allow us to evolve the embedding
* model interface and retain backwards compatibility. The different
* implementation versions can be handled as a discriminated union
* on our side.
*/
readonly specificationVersion: 'v4';
/**
* Name of the provider for logging purposes.
*/
readonly provider: string;
/**
* Provider-specific model ID for logging purposes.
*/
readonly modelId: string;
/**
* Limit of how many embeddings can be generated in a single API call.
*
* Use Infinity for models that do not have a limit.
*/
readonly maxEmbeddingsPerCall: PromiseLike<number | undefined> | number | undefined;
/**
* True if the model can handle multiple embedding calls in parallel.
*/
readonly supportsParallelCalls: PromiseLike<boolean> | boolean;
/**
* Generates a list of embeddings for the given input text.
*
* Naming: "do" prefix to prevent accidental direct usage of the method
* by the user.
*/
doEmbed(options: EmbeddingModelV4CallOptions): PromiseLike<EmbeddingModelV4Result>;
};
type EmbeddingModelV3CallOptions = {
/**
* List of text values to generate embeddings for.
*/
values: Array<string>;
/**
* Abort signal for cancelling the operation.
*/
abortSignal?: AbortSignal;
/**
* Additional provider-specific options. They are passed through
* to the provider from the AI SDK and enable provider-specific
* functionality that can be fully encapsulated in the provider.
*/
providerOptions?: SharedV3ProviderOptions;
/**
* Additional HTTP headers to be sent with the request.
* Only applicable for HTTP-based providers.
*/
headers?: SharedV3Headers;
};
/**
* An embedding is a vector, i.e. an array of numbers.
* It is e.g. used to represent a text as a vector of word embeddings.
*/
type EmbeddingModelV3Embedding = Array<number>;
/**
* The result of a embedding model doEmbed call.
*/
type EmbeddingModelV3Result = {
/**
* Generated embeddings. They are in the same order as the input values.
*/
embeddings: Array<EmbeddingModelV3Embedding>;
/**
* Token usage. We only have input tokens for embeddings.
*/
usage?: {
tokens: number;
};
/**
* Additional provider-specific metadata. They are passed through
* from the provider to the AI SDK and enable provider-specific
* results that can be fully encapsulated in the provider.
*/
providerMetadata?: SharedV3ProviderMetadata;
/**
* Optional response information for debugging purposes.
*/
response?: {
/**
* Response headers.
*/
headers?: SharedV3Headers;
/**
* The response body.
*/
body?: unknown;
};
/**
* Warnings for the call, e.g. unsupported settings.
*/
warnings: Array<SharedV3Warning>;
};
/**
* Specification for an embedding model that implements the embedding model
* interface version 3.
*
* It is specific to text embeddings.
*/
type EmbeddingModelV3 = {
/**
* The embedding model must specify which embedding model interface
* version it implements. This will allow us to evolve the embedding
* model interface and retain backwards compatibility. The different
* implementation versions can be handled as a discriminated union
* on our side.
*/
readonly specificationVersion: 'v3';
/**
* Name of the provider for logging purposes.
*/
readonly provider: string;
/**
* Provider-specific model ID for logging purposes.
*/
readonly modelId: string;
/**
* Limit of how many embeddings can be generated in a single API call.
*
* Use Infinity for models that do not have a limit.
*/
readonly maxEmbeddingsPerCall: PromiseLike<number | undefined> | number | undefined;
/**
* True if the model can handle multiple embedding calls in parallel.
*/
readonly supportsParallelCalls: PromiseLike<boolean> | boolean;
/**
* Generates a list of embeddings for the given input text.
*
* Naming: "do" prefix to prevent accidental direct usage of the method
* by the user.
*/
doEmbed(options: EmbeddingModelV3CallOptions): PromiseLike<EmbeddingModelV3Result>;
};
/**
* An embedding is a vector, i.e. an array of numbers.
* It is e.g. used to represent a text as a vector of word embeddings.
*/
type EmbeddingModelV2Embedding = Array<number>;
/**
* Specification for an embedding model that implements the embedding model
* interface version 2.
*
* VALUE is the type of the values that the model can embed.
* This will allow us to go beyond text embeddings in the future,
* e.g. to support image embeddings
*/
type EmbeddingModelV2<VALUE> = {
/**
* The embedding model must specify which embedding model interface
* version it implements. This will allow us to evolve the embedding
* model interface and retain backwards compatibility. The different
* implementation versions can be handled as a discriminated union
* on our side.
*/
readonly specificationVersion: 'v2';
/**
* Name of the provider for logging purposes.
*/
readonly provider: string;
/**
* Provider-specific model ID for logging purposes.
*/
readonly modelId: string;
/**
* Limit of how many embeddings can be generated in a single API call.
*
* Use Infinity for models that do not have a limit.
*/
readonly maxEmbeddingsPerCall: PromiseLike<number | undefined> | number | undefined;
/**
* True if the model can handle multiple embedding calls in parallel.
*/
readonly supportsParallelCalls: PromiseLike<boolean> | boolean;
/**
* Generates a list of embeddings for the given input text.
*
* Naming: "do" prefix to prevent accidental direct usage of the method
* by the user.
*/
doEmbed(options: {
/**
* List of values to embed.
*/
values: Array<VALUE>;
/**
* Abort signal for cancelling the operation.
*/
abortSignal?: AbortSignal;
/**
* Additional provider-specific options. They are passed through
* to the provider from the AI SDK and enable provider-specific
* functionality that can be fully encapsulated in the provider.
*/
providerOptions?: SharedV2ProviderOptions;
/**
* Additional HTTP headers to be sent with the request.
* Only applicable for HTTP-based providers.
*/
headers?: Record<string, string | undefined>;
}): PromiseLike<{
/**
* Generated embeddings. They are in the same order as the input values.
*/
embeddings: Array<EmbeddingModelV2Embedding>;
/**
* Token usage. We only have input tokens for embeddings.
*/
usage?: {
tokens: number;
};
/**
* Additional provider-specific metadata. They are passed through
* from the provider to the AI SDK and enable provider-specific
* results that can be fully encapsulated in the provider.
*/
providerMetadata?: SharedV2ProviderMetadata;
/**
* Optional response information for debugging purposes.
*/
response?: {
/**
* Response headers.
*/
headers?: SharedV2Headers;
/**
* The response body.
*/
body?: unknown;
};
}>;
};
declare const symbol$e: unique symbol;
/**
* Custom error class for AI SDK related errors.
* @extends Error
*/
declare class AISDKError extends Error {
private readonly [symbol$e];
/**
* The underlying cause of the error, if any.
*/
readonly cause?: unknown;
/**
* Creates an AI SDK Error.
*
* @param {Object} params - The parameters for creating the error.
* @param {string} params.name - The name of the error.
* @param {string} params.message - The error message.
* @param {unknown} [params.cause] - The underlying cause of the error.
*/
constructor({ name, message, cause, }: {
name: string;
message: string;
cause?: unknown;
});
/**
* Checks if the given error is an AI SDK Error.
* @param {unknown} error - The error to check.
* @returns {boolean} True if the error is an AI SDK Error, false otherwise.
*/
static isInstance(error: unknown): error is AISDKError;
protected static hasMarker(error: unknown, marker: string): boolean;
}
declare const symbol$d: unique symbol;
declare class APICallError extends AISDKError {
private readonly [symbol$d];
readonly url: string;
readonly requestBodyValues: unknown;
readonly statusCode?: number;
readonly responseHeaders?: Record<string, string>;
readonly responseBody?: string;
readonly isRetryable: boolean;
readonly data?: unknown;
constructor({ message, url, requestBodyValues, statusCode, responseHeaders, responseBody, cause, isRetryable, // server error
data, }: {
message: string;
url: string;
requestBodyValues: unknown;
statusCode?: number;
responseHeaders?: Record<string, string>;
responseBody?: string;
cause?: unknown;
isRetryable?: boolean;
data?: unknown;
});
static isInstance(error: unknown): error is APICallError;
}
declare const symbol$c: unique symbol;
declare class EmptyResponseBodyError extends AISDKError {
private readonly [symbol$c];
constructor({ message }?: {
message?: string;
});
static isInstance(error: unknown): error is EmptyResponseBodyError;
}
declare function getErrorMessage(error: unknown | undefined): string;
declare const symbol$b: unique symbol;
/**
* A function argument is invalid.
*/
declare class InvalidArgumentError extends AISDKError {
private readonly [symbol$b];
readonly argument: string;
constructor({ message, cause, argument, }: {
argument: string;
message: string;
cause?: unknown;
});
static isInstance(error: unknown): error is InvalidArgumentError;
}
declare const symbol$a: unique symbol;
/**
* A prompt is invalid. This error should be thrown by providers when they cannot
* process a prompt.
*/
declare class InvalidPromptError extends AISDKError {
private readonly [symbol$a];
readonly prompt: unknown;
constructor({ prompt, message, cause, }: {
prompt: unknown;
message: string;
cause?: unknown;
});
static isInstance(error: unknown): error is InvalidPromptError;
}
declare const symbol$9: unique symbol;
/**
* Server returned a response with invalid data content.
* This should be thrown by providers when they cannot parse the response from the API.
*/
declare class InvalidResponseDataError extends AISDKError {
private readonly [symbol$9];
readonly data: unknown;
constructor({ data, message, }: {
data: unknown;
message?: string;
});
static isInstance(error: unknown): error is InvalidResponseDataError;
}
declare const symbol$8: unique symbol;
declare class JSONParseError extends AISDKError {
private readonly [symbol$8];
readonly text: string;
constructor({ text, cause }: {
text: string;
cause: unknown;
});
static isInstance(error: unknown): error is JSONParseError;
}
declare const symbol$7: unique symbol;
declare class LoadAPIKeyError extends AISDKError {
private readonly [symbol$7];
constructor({ message }: {
message: string;
});
static isInstance(error: unknown): error is LoadAPIKeyError;
}
declare const symbol$6: unique symbol;
declare class LoadSettingError extends AISDKError {
private readonly [symbol$6];
constructor({ message }: {
message: string;
});
static isInstance(error: unknown): error is LoadSettingError;
}
declare const symbol$5: unique symbol;
/**
* Thrown when the AI provider fails to generate any content.
*/
declare class NoContentGeneratedError extends AISDKError {
private readonly [symbol$5];
constructor({ message, }?: {
message?: string;
});
static isInstance(error: unknown): error is NoContentGeneratedError;
}
declare const symbol$4: unique symbol;
declare class NoSuchModelError extends AISDKError {
private readonly [symbol$4];
readonly modelId: string;
readonly modelType: 'languageModel' | 'embeddingModel' | 'imageModel' | 'transcriptionModel' | 'speechModel' | 'rerankingModel' | 'videoModel';
constructor({ errorName, modelId, modelType, message, }: {
errorName?: string;
modelId: string;
modelType: 'languageModel' | 'embeddingModel' | 'imageModel' | 'transcriptionModel' | 'speechModel' | 'rerankingModel' | 'videoModel';
message?: string;
});
static isInstance(error: unknown): error is NoSuchModelError;
}
declare const symbol$3: unique symbol;
/**
* Thrown when a provider reference cannot be resolved because the specified
* provider is not found in the provider reference mapping.
*/
declare class NoSuchProviderReferenceError extends AISDKError {
private readonly [symbol$3];
readonly provider: string;
readonly reference: SharedV4ProviderReference;
constructor({ provider, reference, message, }: {
provider: string;
reference: SharedV4ProviderReference;
message?: string;
});
static isInstance(error: unknown): error is NoSuchProviderReferenceError;
}
declare const symbol$2: unique symbol;
declare class TooManyEmbeddingValuesForCallError extends AISDKError {
private readonly [symbol$2];
readonly provider: string;
readonly modelId: string;
readonly maxEmbeddingsPerCall: number;
readonly values: Array<unknown>;
constructor(options: {
provider: string;
modelId: string;
maxEmbeddingsPerCall: number;
values: Array<unknown>;
});
static isInstance(error: unknown): error is TooManyEmbeddingValuesForCallError;
}
declare const symbol$1: unique symbol;
interface TypeValidationContext {
/**
* Field path in dot notation (e.g., "message.metadata", "message.parts[3].data")
*/
field?: string;
/**
* Entity name (e.g., tool name, data type name)
*/
entityName?: string;
/**
* Entity identifier (e.g., message ID, tool call ID)
*/
entityId?: string;
}
declare class TypeValidationError extends AISDKError {
private readonly [symbol$1];
readonly value: unknown;
readonly context?: TypeValidationContext;
constructor({ value, cause, context, }: {
value: unknown;
cause: unknown;
context?: TypeValidationContext;
});
static isInstance(error: unknown): error is TypeValidationError;
/**
* Wraps an error into a TypeValidationError.
* If the cause is already a TypeValidationError with the same value and context, it returns the cause.
* Otherwise, it creates a new TypeValidationError.
*
* @param {Object} params - The parameters for wrapping the error.
* @param {unknown} params.value - The value that failed validation.
* @param {unknown} params.cause - The original error or cause of the validation failure.
* @param {TypeValidationContext} params.context - Optional context about what is being validated.
* @returns {TypeValidationError} A TypeValidationError instance.
*/
static wrap({ value, cause, context, }: {
value: unknown;
cause: unknown;
context?: TypeValidationContext;
}): TypeValidationError;
}
declare const symbol: unique symbol;
declare class UnsupportedFunctionalityError extends AISDKError {
private readonly [symbol];
readonly functionality: string;
constructor({ functionality, message, }: {
functionality: string;
message?: string;
});
static isInstance(error: unknown): error is UnsupportedFunctionalityError;
}
/**
* Options for uploading a file via the files interface.
*/
type FilesV4UploadFileCallOptions = {
/**
* The file data.
*
* - `{ type: 'data', data }`: raw bytes (`Uint8Array`) or a base64-encoded string.
* - `{ type: 'text', text }`: inline text (UTF-8).
*/
data: SharedV4FileDataData | SharedV4FileDataText;
/**
* The IANA media type of the file (e.g. `'application/pdf'`).
*/
mediaType: string;
/**
* The filename of the file.
*/
filename?: string;
/**
* Additional provider-specific options. They are passed through
* to the provider from the AI SDK and enable provider-specific
* functionality that can be fully encapsulated in the provider.
*/
providerOptions?: SharedV4ProviderOptions;
};
/**
* Result of uploading a file via the files interface.
*/
type FilesV4UploadFileResult = {
/**
* A provider reference mapping provider names to provider-specific file identifiers.
*/
providerReference: SharedV4ProviderReference;
/**
* The IANA media type of the uploaded file, if available from the provider.
*/
mediaType?: string;
/**
* The filename of the uploaded file, if available from the provider.
*/
filename?: string;
/**
* Additional provider-specific metadata. They are passed through
* to the provider from the AI SDK and enable provider-specific
* functionality that can be fully encapsulated in the provider.
*/
providerMetadata?: SharedV4ProviderMetadata;
/**
* Warnings from the provider.
*/
warnings: Array<SharedV4Warning>;
};
/**
* Specification for a file management interface that implements the files interface version 4.
*/
type FilesV4 = {
/**
* The files interface must specify which files interface version it implements.
*/
readonly specificationVersion: 'v4';
/**
* Provider ID.
*/
readonly provider: string;
/**
* Uploads a file to the provider and returns a provider reference
* that can be used in subsequent API calls.
*/
uploadFile(options: FilesV4UploadFileCallOptions): PromiseLike<FilesV4UploadFileResult>;
};
/**
* An image file that can be used for image editing or variation generation.
*/
type ImageModelV4File = {
type: 'file';
/**
* The IANA media type of the file, e.g. `image/png`. Any string is supported.
*
* @see https://www.iana.org/assignments/media-types/media-types.xhtml
*/
mediaType: string;
/**
* Generated file data as base64 encoded strings or binary data.
*
* The file data should be returned without any unnecessary conversion.
* If the API returns base64 encoded strings, the file data should be returned
* as base64 encoded strings. If the API returns binary data, the file data should
* be returned as binary data.
*/
data: string | Uint8Array;
/**
* Optional provider-specific metadata for the file part.
*/
providerOptions?: SharedV4ProviderMetadata;
} | {
type: 'url';
/**
* The URL of the image file.
*/
url: string;
/**
* Optional provider-specific metadata for the file part.
*/
providerOptions?: SharedV4ProviderMetadata;
};
type ImageModelV4CallOptions = {
/**
* Prompt for the image generation. Some operations, like upscaling, may not require a prompt.
*/
prompt: string | undefined;
/**
* Number of images to generate.
*/
n: number;
/**
* Size of the images to generate.
* Must have the format `{width}x{height}`.
* `undefined` will use the provider's default size.
*/
size: `${number}x${number}` | undefined;
/**
* Aspect ratio of the images to generate.
* Must have the format `{width}:{height}`.
* `undefined` will use the provider's default aspect ratio.
*/
aspectRatio: `${number}:${number}` | undefined;
/**
* Seed for the image generation.
* `undefined` will use the provider's default seed.
*/
seed: number | undefined;
/**
* Array of images for image editing or variation generation.
* The images should be provided as base64 encoded strings or binary data.
*/
files: ImageModelV4File[] | undefined;
/**
* Mask image for inpainting operations.
* The mask should be provided as base64 encoded strings or binary data.
*/
mask: ImageModelV4File | undefined;
/**
* Additional provider-specific options that are passed through to the provider
* as body parameters.
*
* The outer record is keyed by the provider name, and the inner
* record is keyed by the provider-specific metadata key.
*
* ```ts
* {
* "openai": {
* "style": "vivid"
* }
* }
* ```
*/
providerOptions: SharedV4ProviderOptions;
/**
* Abort signal for cancelling the operation.
*/
abortSignal?: AbortSignal;
/**
* Additional HTTP headers to be sent with the request.
* Only applicable for HTTP-based providers.
*/
headers?: Record<string, string | undefined>;
};
declare function isJSONValue(value: unknown): value is JSONValue;
declare function isJSONArray(value: unknown): value is JSONArray;
declare function isJSONObject(value: unknown): value is JSONObject;
/**
* Usage information for an image model call.
*/
type ImageModelV4Usage = {
/**
* The number of input (prompt) tokens used.
*/
inputTokens: number | undefined;
/**
* The number of output tokens used, if reported by the provider.
*/
outputTokens: number | undefined;
/**
* The total number of tokens as reported by the provider.
*/
totalTokens: number | undefined;
};
type ImageModelV4ProviderMetadata = Record<string, {
images: JSONArray;
} & JSONValue>;
/**
* The result of an image model doGenerate call.
*/
type ImageModelV4Result = {
/**
* Generated images as base64 encoded strings or binary data.
* The images should be returned without any unnecessary conversion.
* If the API returns base64 encoded strings, the images should be returned
* as base64 encoded strings. If the API returns binary data, the images should
* be returned as binary data.
*/
images: Array<string> | Array<Uint8Array>;
/**
* Warnings for the call, e.g. unsupported features.
*/
warnings: Array<SharedV4Warning>;
/**
* Additional provider-specific metadata. They are passed through
* from the provider to the AI SDK and enable provider-specific
* results that can be fully encapsulated in the provider.
*
* The outer record is keyed by the provider name, and the inner
* record is provider-specific metadata. It always includes an
* `images` key with image-specific metadata
*
* ```ts
* {
* "openai": {
* "images": ["revisedPrompt": "Revised prompt here."]
* }
* }
* ```
*/
providerMetadata?: ImageModelV4ProviderMetadata;
/**
* Response information for telemetry and debugging purposes.
*/
response: {
/**
* Timestamp for the start of the generated response.
*/
timestamp: Date;
/**
* The ID of the response model that was used to generate the response.
*/
modelId: string;
/**
* Response headers.
*/
headers: Record<string, string> | undefined;
};
/**
* Optional token usage for the image generation call (if the provider reports it).
*/
usage?: ImageModelV4Usage;
};
type GetMaxImagesPerCallFunction$2 = (options: {
modelId: string;
}) => PromiseLike<number | undefined> | number | undefined;
/**
* Image generation model specification version 3.
*/
type ImageModelV4 = {
/**
* The image model must specify which image model interface
* version it implements. This will allow us to evolve the image
* model interface and retain backwards compatibility. The different
* implementation versions can be handled as a discriminated union
* on our side.
*/
readonly specificationVersion: 'v4';
/**
* Name of the provider for logging purposes.
*/
readonly provider: string;
/**
* Provider-specific model ID for logging purposes.
*/
readonly modelId: string;
/**
* Limit of how many images can be generated in a single API call.
* Can be set to a number for a fixed limit, to undefined to use
* the global limit, or a function that returns a number or undefined,
* optionally as a promise.
*/
readonly maxImagesPerCall: number | undefined | GetMaxImagesPerCallFunction$2;
/**
* Generates an array of images.
*/
doGenerate(options: ImageModelV4CallOptions): PromiseLike<ImageModelV4Result>;
};
/**
* Usage information for an image model call.
*/
type ImageModelV3Usage = {
/**
* The number of input (prompt) tokens used.
*/
inputTokens: number | undefined;
/**
* The number of output tokens used, if reported by the provider.
*/
outputTokens: number | undefined;
/**
* The total number of tokens as reported by the provider.
*/
totalTokens: number | undefined;
};
/**
* An image file that can be used for image editing or variation generation.
*/
type ImageModelV3File = {
type: 'file';
/**
* The IANA media type of the file, e.g. `image/png`. Any string is supported.
*
* @see https://www.iana.org/assignments/media-types/media-types.xhtml
*/
mediaType: string;
/**
* Generated file data as base64 encoded strings or binary data.
*
* The file data should be returned without any unnecessary conversion.
* If the API returns base64 encoded strings, the file data should be returned
* as base64 encoded strings. If the API returns binary data, the file data should
* be returned as binary data.
*/
data: string | Uint8Array;
/**
* Optional provider-specific metadata for the file part.
*/
providerOptions?: SharedV3ProviderMetadata;
} | {
type: 'url';
/**
* The URL of the image file.
*/
url: string;
/**
* Optional provider-specific metadata for the file part.
*/
providerOptions?: SharedV3ProviderMetadata;
};
type ImageModelV3CallOptions = {
/**
* Prompt for the image generation. Some operations, like upscaling, may not require a prompt.
*/
prompt: string | undefined;
/**
* Number of images to generate.
*/
n: number;
/**
* Size of the images to generate.
* Must have the format `{width}x{height}`.
* `undefined` will use the provider's default size.
*/
size: `${number}x${number}` | undefined;
/**
* Aspect ratio of the images to generate.
* Must have the format `{width}:{height}`.
* `undefined` will use the provider's default aspect ratio.
*/
aspectRatio: `${number}:${number}` | undefined;
/**
* Seed for the image generation.
* `undefined` will use the provider's default seed.
*/
seed: number | undefined;
/**
* Array of images for image editing or variation generation.
* The images should be provided as base64 encoded strings or binary data.
*/
files: ImageModelV3File[] | undefined;
/**
* Mask image for inpainting operations.
* The mask should be provided as base64 encoded strings or binary data.
*/
mask: ImageModelV3File | undefined;
/**
* Additional provider-specific options that are passed through to the provider
* as body parameters.
*
* The outer record is keyed by the provider name, and the inner
* record is keyed by the provider-specific metadata key.
*
* ```ts
* {
* "openai": {
* "style": "vivid"
* }
* }
* ```
*/
providerOptions: SharedV3ProviderOptions;
/**
* Abort signal for cancelling the operation.
*/
abortSignal?: AbortSignal;
/**
* Additional HTTP headers to be sent with the request.
* Only applicable for HTTP-based providers.
*/
headers?: Record<string, string | undefined>;
};
type ImageModelV3ProviderMetadata = Record<string, {
images: JSONArray;
} & JSONValue>;
type GetMaxImagesPerCallFunction$1 = (options: {
modelId: string;
}) => PromiseLike<number | undefined> | number | undefined;
/**
* Image generation model specification version 3.
*/
type ImageModelV3 = {
/**
* The image model must specify which image model interface
* version it implements. This will allow us to evolve the image
* model interface and retain backwards compatibility. The different
* implementation versions can be handled as a discriminated union
* on our side.
*/
readonly specificationVersion: 'v3';
/**
* Name of the provider for logging purposes.
*/
readonly provider: string;
/**
* Provider-specific model ID for logging purposes.
*/
readonly modelId: string;
/**
* Limit of how many images can be generated in a single API call.
* Can be set to a number for a fixed limit, to undefined to use
* the global limit, or a function that returns a number or undefined,
* optionally as a promise.
*/
readonly maxImagesPerCall: number | undefined | GetMaxImagesPerCallFunction$1;
/**
* Generates an array of images.
*/
doGenerate(options: ImageModelV3CallOptions): PromiseLike<{
/**
* Generated images as base64 encoded strings or binary data.
* The images should be returned without any unnecessary conversion.
* If the API returns base64 encoded strings, the images should be returned
* as base64 encoded strings. If the API returns binary data, the images should
* be returned as binary data.
*/
images: Array<string> | Array<Uint8Array>;
/**
* Warnings for the call, e.g. unsupported features.
*/
warnings: Array<SharedV3Warning>;
/**
* Additional provider-specific metadata. They are passed through
* from the provider to the AI SDK and enable provider-specific
* results that can be fully encapsulated in the provider.
*
* The outer record is keyed by the provider name, and the inner
* record is provider-specific metadata. It always includes an
* `images` key with image-specific metadata
*
* ```ts
* {
* "openai": {
* "images": ["revisedPrompt": "Revised prompt here."]
* }
* }
* ```
*/
providerMetadata?: ImageModelV3ProviderMetadata;
/**
* Response information for telemetry and debugging purposes.
*/
response: {
/**
* Timestamp for the start of the generated response.
*/
timestamp: Date;
/**
* The ID of the response model that was used to generate the response.
*/
modelId: string;
/**
* Response headers.
*/
headers: Record<string, string> | undefined;
};
/**
* Optional token usage for the image generation call (if the provider reports it).
*/
usage?: ImageModelV3Usage;
}>;
};
type ImageModelV2CallOptions = {
/**
* Prompt for the image generation.
*/
prompt: string;
/**
* Number of images to generate.
*/
n: number;
/**
* Size of the images to generate.
* Must have the format `{width}x{height}`.
* `undefined` will use the provider's default size.
*/
size: `${number}x${number}` | undefined;
/**
* Aspect ratio of the images to generate.
* Must have the format `{width}:{height}`.
* `undefined` will use the provider's default aspect ratio.
*/
aspectRatio: `${number}:${number}` | undefined;
/**
* Seed for the image generation.
* `undefined` will use the provider's default seed.
*/
seed: number | undefined;
/**
* Additional provider-specific options that are passed through to the provider
* as body parameters.
*
* The outer record is keyed by the provider name, and the inner
* record is keyed by the provider-specific metadata key.
* ```ts
* {
* "openai": {
* "style": "vivid"
* }
* }
* ```
*/
providerOptions: SharedV2ProviderOptions;
/**
* Abort signal for cancelling the operation.
*/
abortSignal?: AbortSignal;
/**
* Additional HTTP headers to be sent with the request.
* Only applicable for HTTP-based providers.
*/
headers?: Record<string, string | undefined>;
};
/**
* Warning from the model provider for this call. The call will proceed, but e.g.
* some settings might not be supported, which can lead to suboptimal results.
*/
type ImageModelV2CallWarning = {
type: 'unsupported-setting';
setting: keyof ImageModelV2CallOptions;
details?: string;
} | {
type: 'other';
message: string;
};
type ImageModelV2ProviderMetadata = Record<string, {
images: JSONArray;
} & JSONValue>;
type GetMaxImagesPerCallFunction = (options: {
modelId: string;
}) => PromiseLike<number | undefined> | number | undefined;
/**
* Image generation model specification version 2.
*/
type ImageModelV2 = {
/**
* The image model must specify which image model interface
* version it implements. This will allow us to evolve the image
* model interface and retain backwards compatibility. The different
* implementation versions can be handled as a discriminated union
* on our side.
*/
readonly specificationVersion: 'v2';
/**
* Name of the provider for logging purposes.
*/
readonly provider: string;
/**
* Provider-specific model ID for logging purposes.
*/
readonly modelId: string;
/**
* Limit of how many images can be generated in a single API call.
* Can be set to a number for a fixed limit, to undefined to use
* the global limit, or a function that returns a number or undefined,
* optionally as a promise.
*/
readonly maxImagesPerCall: number | undefined | GetMaxImagesPerCallFunction;
/**
* Generates an array of images.
*/
doGenerate(options: ImageModelV2CallOptions): PromiseLike<{
/**
* Generated images as base64 encoded strings or binary data.
* The images should be returned without any unnecessary conversion.
* If the API returns base64 encoded strings, the images should be returned
* as base64 encoded strings. If the API returns binary data, the images should
* be returned as binary data.
*/
images: Array<string> | Array<Uint8Array>;
/**
* Warnings for the call, e.g. unsupported settings.
*/
warnings: Array<ImageModelV2CallWarning>;
/**
* Additional provider-specific metadata. They are passed through
* from the provider to the AI SDK and enable provider-specific
* results that can be fully encapsulated in the provider.
*
* The outer record is keyed by the provider name, and the inner
* record is provider-specific metadata. It always includes an
* `images` key with image-specific metadata
*
* ```ts
* {
* "openai": {
* "images": ["revisedPrompt": "Revised prompt here."]
* }
* }
* ```
*/
providerMetadata?: ImageModelV2ProviderMetadata;
/**
* Response information for telemetry and debugging purposes.
*/
response: {
/**
* Timestamp for the start of the generated response.
*/
timestamp: Date;
/**
* The ID of the response model that was used to generate the response.
*/
modelId: string;
/**
* Response headers.
*/
headers: Record<string, string> | undefined;
};
}>;
};
/**
* Middleware for ImageModelV4.
* This type defines the structure for middleware that can be used to modify
* the behavior of ImageModelV4 operations.
*/
type ImageModelV4Middleware = {
/**
* Middleware specification version. Use `v4` for the current version.
*/
readonly specificationVersion: 'v4';
/**
* Override the provider name if desired.
* @param options.model - The image model instance.
*/
overrideProvider?: (options: {
model: ImageModelV4;
}) => string;
/**
* Override the model ID if desired.
* @param options.model - The image model instance.
*/
overrideModelId?: (options: {
model: ImageModelV4;
}) => string;
/**
* Override the limit of how many images can be generated in a single API call if desired.
* @param options.model - The image model instance.
*/
overrideMaxImagesPerCall?: (options: {
model: ImageModelV4;
}) => ImageModelV4['maxImagesPerCall'];
/**
* Transforms the parameters before they are passed to the image model.
* @param options - Object containing the parameters.
* @param options.params - The original parameters for the image model call.
* @returns A promise that resolves to the transformed parameters.
*/
transformParams?: (options: {
params: ImageModelV4CallOptions;
model: ImageModelV4;
}) => PromiseLike<ImageModelV4CallOptions>;
/**
* Wraps the generate operation of the image model.
*
* @param options - Object containing the generate function, parameters, and model.
* @param options.doGenerate - The original generate function.
* @param options.params - The parameters for the generate call. If the
* `transformParams` middleware is used, this will be the transformed parameters.
* @param options.model - The image model instance.
* @returns A promise that resolves to the result of the generate operation.
*/
wrapGenerate?: (options: {
doGenerate: () => ReturnType<ImageModelV4['doGenerate']>;
params: ImageModelV4CallOptions;
model: ImageModelV4;
}) => Promise<Awaited<ReturnType<ImageModelV4['doGenerate']>>>;
};
/**
* Middleware for ImageModelV3.
* This type defines the structure for middleware that can be used to modify
* the behavior of ImageModelV3 operations.
*/
type ImageModelV3Middleware = {
/**
* Middleware specification version. Use `v3` for the current version.
*/
readonly specificationVersion: 'v3';
/**
* Override the provider name if desired.
* @param options.model - The image model instance