UNPKG

@ai-sdk/amazon-bedrock

Version:

The **[Amazon Bedrock provider](https://ai-sdk.dev/providers/ai-sdk-providers/amazon-bedrock)** for the [AI SDK](https://ai-sdk.dev/docs) contains language model support for the Amazon Bedrock [converse API](https://docs.aws.amazon.com/bedrock/latest/APIR

208 lines (199 loc) 11.6 kB
export { AnthropicProviderOptions } from '@ai-sdk/anthropic'; import { z } from 'zod/v4'; import { anthropicTools } from '@ai-sdk/anthropic/internal'; import { ProviderV4, LanguageModelV4, EmbeddingModelV4, ImageModelV4, RerankingModelV4 } from '@ai-sdk/provider'; import { FetchFunction } from '@ai-sdk/provider-utils'; type AmazonBedrockEmbeddingModelId = 'amazon.titan-embed-text-v1' | 'amazon.titan-embed-text-v2:0' | 'cohere.embed-english-v3' | 'cohere.embed-multilingual-v3' | (string & {}); declare const amazonBedrockEmbeddingModelOptionsSchema: z.ZodObject<{ dimensions: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<1024>, z.ZodLiteral<512>, z.ZodLiteral<256>]>>; normalize: z.ZodOptional<z.ZodBoolean>; embeddingDimension: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<256>, z.ZodLiteral<384>, z.ZodLiteral<1024>, z.ZodLiteral<3072>]>>; embeddingPurpose: z.ZodOptional<z.ZodEnum<{ GENERIC_INDEX: "GENERIC_INDEX"; TEXT_RETRIEVAL: "TEXT_RETRIEVAL"; IMAGE_RETRIEVAL: "IMAGE_RETRIEVAL"; VIDEO_RETRIEVAL: "VIDEO_RETRIEVAL"; DOCUMENT_RETRIEVAL: "DOCUMENT_RETRIEVAL"; AUDIO_RETRIEVAL: "AUDIO_RETRIEVAL"; GENERIC_RETRIEVAL: "GENERIC_RETRIEVAL"; CLASSIFICATION: "CLASSIFICATION"; CLUSTERING: "CLUSTERING"; }>>; inputType: z.ZodOptional<z.ZodEnum<{ search_document: "search_document"; search_query: "search_query"; classification: "classification"; clustering: "clustering"; }>>; truncate: z.ZodOptional<z.ZodEnum<{ NONE: "NONE"; START: "START"; END: "END"; }>>; outputDimension: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<256>, z.ZodLiteral<512>, z.ZodLiteral<1024>, z.ZodLiteral<1536>]>>; }, z.core.$strip>; type AmazonBedrockEmbeddingModelOptions = z.infer<typeof amazonBedrockEmbeddingModelOptionsSchema>; type AmazonBedrockChatModelId = 'amazon.titan-tg1-large' | 'amazon.titan-text-express-v1' | 'anthropic.claude-v2' | 'anthropic.claude-v2:1' | 'anthropic.claude-instant-v1' | 'anthropic.claude-sonnet-5' | 'anthropic.claude-fable-5' | 'anthropic.claude-opus-4-8' | 'anthropic.claude-opus-4-7' | 'anthropic.claude-opus-4-6-v1' | 'anthropic.claude-sonnet-4-6-v1' | 'anthropic.claude-opus-4-5-20251101-v1:0' | 'anthropic.claude-haiku-4-5-20251001-v1:0' | 'anthropic.claude-sonnet-4-5-20250929-v1:0' | 'anthropic.claude-sonnet-4-20250514-v1:0' | 'anthropic.claude-opus-4-20250514-v1:0' | 'anthropic.claude-opus-4-1-20250805-v1:0' | 'anthropic.claude-3-7-sonnet-20250219-v1:0' | 'anthropic.claude-3-5-sonnet-20240620-v1:0' | 'anthropic.claude-3-5-sonnet-20241022-v2:0' | 'anthropic.claude-3-5-haiku-20241022-v1:0' | 'anthropic.claude-3-sonnet-20240229-v1:0' | 'anthropic.claude-3-haiku-20240307-v1:0' | 'anthropic.claude-3-opus-20240229-v1:0' | 'cohere.command-text-v14' | 'cohere.command-light-text-v14' | 'cohere.command-r-v1:0' | 'cohere.command-r-plus-v1:0' | 'meta.llama3-70b-instruct-v1:0' | 'meta.llama3-8b-instruct-v1:0' | 'meta.llama3-1-405b-instruct-v1:0' | 'meta.llama3-1-70b-instruct-v1:0' | 'meta.llama3-1-8b-instruct-v1:0' | 'meta.llama3-2-11b-instruct-v1:0' | 'meta.llama3-2-1b-instruct-v1:0' | 'meta.llama3-2-3b-instruct-v1:0' | 'meta.llama3-2-90b-instruct-v1:0' | 'mistral.mistral-7b-instruct-v0:2' | 'mistral.mixtral-8x7b-instruct-v0:1' | 'mistral.mistral-large-2402-v1:0' | 'mistral.mistral-small-2402-v1:0' | 'openai.gpt-oss-120b-1:0' | 'openai.gpt-oss-20b-1:0' | 'amazon.titan-text-express-v1' | 'amazon.titan-text-lite-v1' | 'us.amazon.nova-premier-v1:0' | 'us.amazon.nova-pro-v1:0' | 'us.amazon.nova-micro-v1:0' | 'us.amazon.nova-lite-v1:0' | 'us.anthropic.claude-3-sonnet-20240229-v1:0' | 'us.anthropic.claude-3-opus-20240229-v1:0' | 'us.anthropic.claude-3-haiku-20240307-v1:0' | 'us.anthropic.claude-3-5-sonnet-20240620-v1:0' | 'us.anthropic.claude-3-5-haiku-20241022-v1:0' | 'us.anthropic.claude-3-5-sonnet-20241022-v2:0' | 'us.anthropic.claude-3-7-sonnet-20250219-v1:0' | 'us.anthropic.claude-sonnet-5' | 'us.anthropic.claude-fable-5' | 'us.anthropic.claude-opus-4-8' | 'us.anthropic.claude-opus-4-7' | 'us.anthropic.claude-opus-4-6-v1' | 'us.anthropic.claude-sonnet-4-6-v1' | 'us.anthropic.claude-opus-4-5-20251101-v1:0' | 'us.anthropic.claude-sonnet-4-5-20250929-v1:0' | 'us.anthropic.claude-sonnet-4-20250514-v1:0' | 'us.anthropic.claude-opus-4-20250514-v1:0' | 'us.anthropic.claude-opus-4-1-20250805-v1:0' | 'us.anthropic.claude-haiku-4-5-20251001-v1:0' | 'us.meta.llama3-2-11b-instruct-v1:0' | 'us.meta.llama3-2-3b-instruct-v1:0' | 'us.meta.llama3-2-90b-instruct-v1:0' | 'us.meta.llama3-2-1b-instruct-v1:0' | 'us.meta.llama3-1-8b-instruct-v1:0' | 'us.meta.llama3-1-70b-instruct-v1:0' | 'us.meta.llama3-3-70b-instruct-v1:0' | 'us.deepseek.r1-v1:0' | 'us.mistral.pixtral-large-2502-v1:0' | 'us.meta.llama4-scout-17b-instruct-v1:0' | 'us.meta.llama4-maverick-17b-instruct-v1:0' | (string & {}); declare const amazonBedrockLanguageModelChatOptions: z.ZodObject<{ additionalModelRequestFields: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>; reasoningConfig: z.ZodOptional<z.ZodObject<{ type: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"enabled">, z.ZodLiteral<"disabled">, z.ZodLiteral<"adaptive">]>>; budgetTokens: z.ZodOptional<z.ZodNumber>; maxReasoningEffort: z.ZodOptional<z.ZodEnum<{ low: "low"; medium: "medium"; high: "high"; xhigh: "xhigh"; max: "max"; }>>; display: z.ZodOptional<z.ZodEnum<{ omitted: "omitted"; summarized: "summarized"; }>>; }, z.core.$strip>>; anthropicBeta: z.ZodOptional<z.ZodArray<z.ZodString>>; serviceTier: z.ZodOptional<z.ZodEnum<{ default: "default"; reserved: "reserved"; priority: "priority"; flex: "flex"; }>>; }, z.core.$strip>; type AmazonBedrockLanguageModelChatOptions = z.infer<typeof amazonBedrockLanguageModelChatOptions>; type AmazonBedrockImageModelId = 'amazon.nova-canvas-v1:0' | (string & {}); interface AmazonBedrockCredentials { region: string; accessKeyId: string; secretAccessKey: string; sessionToken?: string; } type AmazonBedrockRerankingModelId = 'amazon.rerank-v1:0' | 'cohere.rerank-v3-5:0' | (string & {}); type AmazonBedrockRerankingModelOptions = { /** * If the total number of results was greater than could fit in a response, a token is returned in the nextToken field. You can enter that token in this field to return the next batch of results. */ nextToken?: string; /** * Additional model request fields to pass to the model. */ additionalModelRequestFields?: Record<string, unknown>; }; interface AmazonBedrockProviderSettings { /** * The AWS region to use for the Bedrock provider. Defaults to the value of the * `AWS_REGION` environment variable. */ region?: string; /** * API key for authenticating requests using Bearer token authentication. * When provided, this will be used instead of AWS SigV4 authentication. * Defaults to the value of the `AWS_BEARER_TOKEN_BEDROCK` environment variable. * * @example * ```typescript * // Using API key directly * const bedrock = createAmazonBedrock({ * apiKey: 'your-api-key-here', * region: 'us-east-1' * }); * * // Using environment variable AWS_BEARER_TOKEN_BEDROCK * const bedrock = createAmazonBedrock({ * region: 'us-east-1' * }); * ``` * * Note: When `apiKey` is provided, it takes precedence over AWS SigV4 authentication. * If neither `apiKey` nor `AWS_BEARER_TOKEN_BEDROCK` environment variable is set, * the provider will fall back to AWS SigV4 authentication using AWS credentials. */ apiKey?: string; /** * The AWS access key ID to use for the Bedrock provider. Defaults to the value of the * `AWS_ACCESS_KEY_ID` environment variable. */ accessKeyId?: string; /** * The AWS secret access key to use for the Bedrock provider. Defaults to the value of the * `AWS_SECRET_ACCESS_KEY` environment variable. */ secretAccessKey?: string; /** * The AWS session token to use for the Bedrock provider. When `accessKeyId` and * `secretAccessKey` are both passed explicitly as options, only this field is used * If either access key field is omitted and resolved from the environment, the * session token also falls back to `AWS_SESSION_TOKEN` when not set here. */ sessionToken?: string; /** * Base URL for the Bedrock API calls. */ baseURL?: string; /** * Custom headers to include in the requests. */ headers?: Record<string, string>; /** * Custom fetch implementation. You can use it as a middleware to intercept requests, * or to provide a custom fetch implementation for e.g. testing. */ fetch?: FetchFunction; /** * The AWS credential provider to use for the Bedrock provider to get dynamic * credentials similar to the AWS SDK. Setting a provider here will cause its * credential values to be used instead of the `accessKeyId`, `secretAccessKey`, * and `sessionToken` settings. */ credentialProvider?: () => PromiseLike<Omit<AmazonBedrockCredentials, 'region'>>; generateId?: () => string; } interface AmazonBedrockProvider extends ProviderV4 { (modelId: AmazonBedrockChatModelId): LanguageModelV4; languageModel(modelId: AmazonBedrockChatModelId): LanguageModelV4; /** * Creates a model for text embeddings. */ embedding(modelId: AmazonBedrockEmbeddingModelId): EmbeddingModelV4; /** * Creates a model for text embeddings. */ embeddingModel(modelId: AmazonBedrockEmbeddingModelId): EmbeddingModelV4; /** * @deprecated Use `embedding` instead. */ textEmbedding(modelId: AmazonBedrockEmbeddingModelId): EmbeddingModelV4; /** * @deprecated Use `embeddingModel` instead. */ textEmbeddingModel(modelId: AmazonBedrockEmbeddingModelId): EmbeddingModelV4; /** * Creates a model for image generation. */ image(modelId: AmazonBedrockImageModelId): ImageModelV4; /** * Creates a model for image generation. */ imageModel(modelId: AmazonBedrockImageModelId): ImageModelV4; /** * Creates a model for reranking documents. */ reranking(modelId: AmazonBedrockRerankingModelId): RerankingModelV4; /** * Creates a model for reranking documents. */ rerankingModel(modelId: AmazonBedrockRerankingModelId): RerankingModelV4; /** * Anthropic-specific tools that can be used with Anthropic models on Bedrock. */ tools: typeof anthropicTools; } /** * Create an Amazon Bedrock provider instance. */ declare function createAmazonBedrock(options?: AmazonBedrockProviderSettings): AmazonBedrockProvider; /** * Default Amazon Bedrock provider instance. */ declare const amazonBedrock: AmazonBedrockProvider; declare const VERSION: string; export { type AmazonBedrockEmbeddingModelOptions, type AmazonBedrockLanguageModelChatOptions, type AmazonBedrockLanguageModelChatOptions as AmazonBedrockLanguageModelOptions, type AmazonBedrockProvider, type AmazonBedrockProviderSettings, type AmazonBedrockRerankingModelOptions, type AmazonBedrockLanguageModelChatOptions as BedrockProviderOptions, type AmazonBedrockRerankingModelOptions as BedrockRerankingOptions, VERSION, amazonBedrock, amazonBedrock as bedrock, createAmazonBedrock };