@ai-sdk/amazon-bedrock 5.0.98 → 5.0.100
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.
- package/CHANGELOG.md +25 -0
- package/dist/anthropic/index.d.ts +1 -1
- package/dist/anthropic/index.js +4 -4
- package/dist/anthropic/index.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/mantle/index.cjs +4 -4
- package/dist/mantle/index.cjs.map +1 -1
- package/dist/mantle/index.js +4 -4
- package/dist/mantle/index.js.map +1 -1
- package/docs/08-amazon-bedrock.mdx +8 -6
- package/package.json +4 -4
- package/src/amazon-bedrock-chat-language-model-options.ts +2 -0
- package/src/amazon-bedrock-provider.ts +1 -1
- package/src/amazon-bedrock-sigv4-fetch.ts +2 -2
- package/src/anthropic/amazon-bedrock-anthropic-options.ts +2 -0
- package/src/anthropic/amazon-bedrock-anthropic-provider.ts +1 -1
- package/src/inject-fetch-headers.ts +1 -1
- package/src/mantle/bedrock-mantle-provider.ts +1 -1
package/dist/mantle/index.cjs
CHANGED
|
@@ -35,7 +35,7 @@ var import_provider_utils = require("@ai-sdk/provider-utils");
|
|
|
35
35
|
var import_aws4fetch = require("aws4fetch");
|
|
36
36
|
|
|
37
37
|
// src/version.ts
|
|
38
|
-
var VERSION = true ? "5.0.
|
|
38
|
+
var VERSION = true ? "5.0.100" : "0.0.0-test";
|
|
39
39
|
|
|
40
40
|
// src/amazon-bedrock-sigv4-fetch.ts
|
|
41
41
|
function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {
|
|
@@ -48,7 +48,7 @@ function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {
|
|
|
48
48
|
);
|
|
49
49
|
const headersWithUserAgent = (0, import_provider_utils.withUserAgentSuffix)(
|
|
50
50
|
originalHeaders,
|
|
51
|
-
`ai-sdk
|
|
51
|
+
`ai-sdk-amazon-bedrock/${VERSION}`,
|
|
52
52
|
(0, import_provider_utils.getRuntimeEnvironmentUserAgent)()
|
|
53
53
|
);
|
|
54
54
|
let effectiveBody = init?.body ?? void 0;
|
|
@@ -106,7 +106,7 @@ function createApiKeyFetchFunction(apiKey, fetch) {
|
|
|
106
106
|
const originalHeaders = (0, import_provider_utils.normalizeHeaders)(init?.headers);
|
|
107
107
|
const headersWithUserAgent = (0, import_provider_utils.withUserAgentSuffix)(
|
|
108
108
|
originalHeaders,
|
|
109
|
-
`ai-sdk
|
|
109
|
+
`ai-sdk-amazon-bedrock/${VERSION}`,
|
|
110
110
|
(0, import_provider_utils.getRuntimeEnvironmentUserAgent)()
|
|
111
111
|
);
|
|
112
112
|
const finalHeaders = (0, import_provider_utils.combineHeaders)(headersWithUserAgent, {
|
|
@@ -202,7 +202,7 @@ Original error: ${errorMessage}`
|
|
|
202
202
|
) ?? "https://bedrock-mantle.us-east-1.api.aws/v1";
|
|
203
203
|
const getHeaders = () => (0, import_provider_utils2.withUserAgentSuffix)(
|
|
204
204
|
options.headers ?? {},
|
|
205
|
-
`ai-sdk
|
|
205
|
+
`ai-sdk-amazon-bedrock/${VERSION}`
|
|
206
206
|
);
|
|
207
207
|
const url = ({ path, modelId }) => `${getBaseURL(modelId)}${path}`;
|
|
208
208
|
const createChatModel = (modelId) => new import_internal.OpenAIChatLanguageModel(modelId, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/mantle/index.ts","../../src/mantle/bedrock-mantle-provider.ts","../../src/amazon-bedrock-sigv4-fetch.ts","../../src/version.ts"],"sourcesContent":["export { bedrockMantle, createBedrockMantle } from './bedrock-mantle-provider';\nexport type {\n BedrockMantleProvider,\n BedrockMantleProviderSettings,\n} from './bedrock-mantle-provider';\nexport type { BedrockMantleModelId } from './bedrock-mantle-options';\n","import {\n OpenAIChatLanguageModel,\n OpenAIResponsesLanguageModel,\n} from '@ai-sdk/openai/internal';\nimport {\n NoSuchModelError,\n type LanguageModelV4,\n type ProviderV4,\n} from '@ai-sdk/provider';\nimport {\n loadOptionalSetting,\n loadSetting,\n withoutTrailingSlash,\n withUserAgentSuffix,\n type FetchFunction,\n} from '@ai-sdk/provider-utils';\nimport {\n createApiKeyFetchFunction,\n createSigV4FetchFunction,\n type AmazonBedrockCredentials,\n} from '../amazon-bedrock-sigv4-fetch';\nimport type {\n BedrockMantleChatModelId,\n BedrockMantleResponsesModelId,\n} from './bedrock-mantle-options';\nimport { VERSION } from '../version';\n\nexport interface BedrockMantleProvider extends ProviderV4 {\n /**\n * Creates a model for text generation using the Chat Completions API.\n * Chat Completions has the broadest model support on Mantle.\n */\n (modelId: BedrockMantleChatModelId): LanguageModelV4;\n\n /**\n * Creates a model for text generation using the Chat Completions API.\n */\n languageModel(modelId: BedrockMantleChatModelId): LanguageModelV4;\n\n /**\n * Creates a model for text generation using the Chat Completions API.\n */\n chat(modelId: BedrockMantleChatModelId): LanguageModelV4;\n\n /**\n * Creates a model for text generation using the Responses API.\n * Not all Mantle models support this API. Notably, gpt-oss-safeguard models\n * are Chat-only.\n */\n responses(modelId: BedrockMantleResponsesModelId): LanguageModelV4;\n\n /**\n * @deprecated Mantle does not support embedding models.\n */\n textEmbeddingModel(modelId: string): never;\n}\n\nexport interface BedrockMantleProviderSettings {\n /**\n * The AWS region to use for the Bedrock Mantle endpoint. Defaults to the value of the\n * `AWS_REGION` environment variable.\n */\n region?: string;\n\n /**\n * API key for authenticating requests using Bearer token authentication.\n * When provided, this will be used instead of AWS SigV4 authentication.\n * Defaults to the value of the `AWS_BEARER_TOKEN_BEDROCK` environment variable.\n */\n apiKey?: string;\n\n /**\n * The AWS access key ID to use for SigV4 authentication. Defaults to the value of the\n * `AWS_ACCESS_KEY_ID` environment variable.\n */\n accessKeyId?: string;\n\n /**\n * The AWS secret access key to use for SigV4 authentication. Defaults to the value of the\n * `AWS_SECRET_ACCESS_KEY` environment variable.\n */\n secretAccessKey?: string;\n\n /**\n * The AWS session token to use for SigV4 authentication. Defaults to the value of the\n * `AWS_SESSION_TOKEN` environment variable.\n */\n sessionToken?: string;\n\n /**\n * Base URL for the Bedrock Mantle API calls.\n */\n baseURL?: string;\n\n /**\n * Custom headers to include in the requests.\n */\n headers?: Record<string, string | undefined>;\n\n /**\n * Custom fetch implementation. You can use it as a middleware to intercept requests,\n * or to provide a custom fetch implementation for e.g. testing.\n */\n fetch?: FetchFunction;\n\n /**\n * The AWS credential provider to use for SigV4 authentication to get dynamic\n * credentials similar to the AWS SDK. Setting a provider here will cause its\n * credential values to be used instead of the `accessKeyId`, `secretAccessKey`,\n * and `sessionToken` settings.\n */\n credentialProvider?: () => PromiseLike<\n Omit<AmazonBedrockCredentials, 'region'>\n >;\n}\n\n/**\n * Create an Amazon Bedrock Mantle provider instance.\n * This provider uses the OpenAI-compatible Mantle API for models that are\n * only available through the Mantle endpoint (e.g. openai.gpt-oss-20b).\n */\nexport function createBedrockMantle(\n options: BedrockMantleProviderSettings = {},\n): BedrockMantleProvider {\n // Check for API key authentication first\n const rawApiKey = loadOptionalSetting({\n settingValue: options.apiKey,\n environmentVariableName: 'AWS_BEARER_TOKEN_BEDROCK',\n });\n\n // Only use API key if it's a non-empty, non-whitespace string\n const apiKey =\n rawApiKey && rawApiKey.trim().length > 0 ? rawApiKey.trim() : undefined;\n\n // Use API key authentication if available, otherwise fall back to SigV4\n const fetchFunction = apiKey\n ? createApiKeyFetchFunction(apiKey, options.fetch)\n : createSigV4FetchFunction(\n async () => {\n const region = loadSetting({\n settingValue: options.region,\n settingName: 'region',\n environmentVariableName: 'AWS_REGION',\n description: 'AWS region',\n });\n\n // If a credential provider is provided, use it to get the credentials.\n if (options.credentialProvider) {\n try {\n return {\n ...(await options.credentialProvider()),\n region,\n };\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : String(error);\n throw new Error(\n `AWS credential provider failed: ${errorMessage}. ` +\n 'Please ensure your credential provider returns valid AWS credentials ' +\n 'with accessKeyId and secretAccessKey properties.',\n );\n }\n }\n\n try {\n return {\n region,\n accessKeyId: loadSetting({\n settingValue: options.accessKeyId,\n settingName: 'accessKeyId',\n environmentVariableName: 'AWS_ACCESS_KEY_ID',\n description: 'AWS access key ID',\n }),\n secretAccessKey: loadSetting({\n settingValue: options.secretAccessKey,\n settingName: 'secretAccessKey',\n environmentVariableName: 'AWS_SECRET_ACCESS_KEY',\n description: 'AWS secret access key',\n }),\n sessionToken: loadOptionalSetting({\n settingValue: options.sessionToken,\n environmentVariableName: 'AWS_SESSION_TOKEN',\n }),\n };\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : String(error);\n if (\n errorMessage.includes('AWS_ACCESS_KEY_ID') ||\n errorMessage.includes('accessKeyId')\n ) {\n throw new Error(\n 'AWS SigV4 authentication requires AWS credentials. Please provide either:\\n' +\n '1. Set AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables\\n' +\n '2. Provide accessKeyId and secretAccessKey in options\\n' +\n '3. Use a credentialProvider function\\n' +\n '4. Use API key authentication with AWS_BEARER_TOKEN_BEDROCK or apiKey option\\n' +\n `Original error: ${errorMessage}`,\n );\n }\n if (\n errorMessage.includes('AWS_SECRET_ACCESS_KEY') ||\n errorMessage.includes('secretAccessKey')\n ) {\n throw new Error(\n 'AWS SigV4 authentication requires both AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY. ' +\n 'Please ensure both credentials are provided.\\n' +\n `Original error: ${errorMessage}`,\n );\n }\n throw error;\n }\n },\n options.fetch,\n 'bedrock-mantle',\n );\n\n const getBaseURL = (modelId: string): string =>\n withoutTrailingSlash(\n options.baseURL ??\n `https://bedrock-mantle.${loadSetting({\n settingValue: options.region,\n settingName: 'region',\n environmentVariableName: 'AWS_REGION',\n description: 'AWS region',\n })}.api.aws/${\n // Mantle serves these models under its separate OpenAI route.\n /^(?:openai\\.gpt-(?!oss-)|google\\.gemma-4|xai\\.)/.test(modelId)\n ? 'openai/v1'\n : 'v1'\n }`,\n ) ?? 'https://bedrock-mantle.us-east-1.api.aws/v1';\n\n const getHeaders = (): Record<string, string | undefined> =>\n withUserAgentSuffix(\n options.headers ?? {},\n `ai-sdk/amazon-bedrock/${VERSION}`,\n );\n\n const url = ({ path, modelId }: { path: string; modelId: string }): string =>\n `${getBaseURL(modelId)}${path}`;\n\n const createChatModel = (modelId: BedrockMantleChatModelId) =>\n new OpenAIChatLanguageModel(modelId, {\n provider: 'bedrock-mantle.chat',\n url,\n headers: getHeaders,\n fetch: fetchFunction,\n });\n\n const createResponsesModel = (modelId: BedrockMantleResponsesModelId) =>\n new OpenAIResponsesLanguageModel(modelId, {\n provider: 'bedrock-mantle.responses',\n url,\n headers: getHeaders,\n fetch: fetchFunction,\n supportsWebSearchSourcesInclude: false,\n });\n\n const provider = function (modelId: BedrockMantleChatModelId) {\n if (new.target) {\n throw new Error(\n 'The Bedrock Mantle model function cannot be called with the new keyword.',\n );\n }\n\n return createChatModel(modelId);\n };\n\n provider.specificationVersion = 'v4' as const;\n provider.languageModel = createChatModel;\n provider.chat = createChatModel;\n provider.responses = createResponsesModel;\n\n provider.embeddingModel = (modelId: string) => {\n throw new NoSuchModelError({ modelId, modelType: 'embeddingModel' });\n };\n provider.textEmbeddingModel = provider.embeddingModel;\n provider.imageModel = (modelId: string) => {\n throw new NoSuchModelError({ modelId, modelType: 'imageModel' });\n };\n\n return provider as BedrockMantleProvider;\n}\n\n/**\n * Default Bedrock Mantle provider instance.\n */\nexport const bedrockMantle = createBedrockMantle();\n","import {\n combineHeaders,\n normalizeHeaders,\n withUserAgentSuffix,\n getRuntimeEnvironmentUserAgent,\n type FetchFunction,\n} from '@ai-sdk/provider-utils';\nimport { AwsV4Signer } from 'aws4fetch';\nimport { VERSION } from './version';\n\nexport interface AmazonBedrockCredentials {\n region: string;\n accessKeyId: string;\n secretAccessKey: string;\n sessionToken?: string;\n}\n\n/**\n * Creates a fetch function that applies AWS Signature Version 4 signing.\n *\n * @param getCredentials - Function that returns the AWS credentials to use when signing.\n * @param fetch - Optional original fetch implementation to wrap. Defaults to global fetch.\n * @param service - The AWS service name to use for SigV4 signing scope. Defaults to 'bedrock'.\n * @returns A FetchFunction that signs requests before passing them to the underlying fetch.\n */\nexport function createSigV4FetchFunction(\n getCredentials: () =>\n | AmazonBedrockCredentials\n | PromiseLike<AmazonBedrockCredentials>,\n fetch?: FetchFunction,\n service: string = 'bedrock',\n): FetchFunction {\n return async (\n input: RequestInfo | URL,\n init?: RequestInit,\n ): Promise<Response> => {\n // avoid caching globalThis.fetch in case it is patched by other libraries\n const effectiveFetch = fetch ?? globalThis.fetch;\n const request = input instanceof Request ? input : undefined;\n const originalHeaders = combineHeaders(\n normalizeHeaders(request?.headers),\n normalizeHeaders(init?.headers),\n );\n const headersWithUserAgent = withUserAgentSuffix(\n originalHeaders,\n `ai-sdk/amazon-bedrock/${VERSION}`,\n getRuntimeEnvironmentUserAgent(),\n );\n\n let effectiveBody: BodyInit | undefined = init?.body ?? undefined;\n if (effectiveBody === undefined && request && request.body !== null) {\n try {\n effectiveBody = await request.clone().text();\n } catch {}\n }\n\n const effectiveMethod = init?.method ?? request?.method;\n\n if (effectiveMethod?.toUpperCase() !== 'POST' || !effectiveBody) {\n return effectiveFetch(input, {\n ...init,\n headers: headersWithUserAgent as HeadersInit,\n });\n }\n\n const url =\n typeof input === 'string'\n ? input\n : input instanceof URL\n ? input.href\n : input.url;\n\n const body = prepareBodyString(effectiveBody);\n const credentials = await getCredentials();\n const signer = new AwsV4Signer({\n url,\n method: 'POST',\n headers: Object.entries(headersWithUserAgent),\n body,\n region: credentials.region,\n accessKeyId: credentials.accessKeyId,\n secretAccessKey: credentials.secretAccessKey,\n sessionToken: credentials.sessionToken,\n service,\n });\n\n const signingResult = await signer.sign();\n const signedHeaders = normalizeHeaders(signingResult.headers);\n\n // Use the combined headers directly as HeadersInit\n const combinedHeaders = combineHeaders(headersWithUserAgent, signedHeaders);\n\n return effectiveFetch(input, {\n ...init,\n body,\n headers: combinedHeaders as HeadersInit,\n });\n };\n}\n\nfunction prepareBodyString(body: BodyInit | undefined): string {\n if (typeof body === 'string') {\n return body;\n } else if (body instanceof Uint8Array) {\n return new TextDecoder().decode(body);\n } else if (body instanceof ArrayBuffer) {\n return new TextDecoder().decode(new Uint8Array(body));\n } else {\n return JSON.stringify(body);\n }\n}\n\n/**\n * Creates a fetch function that applies Bearer token authentication.\n *\n * @param apiKey - The API key to use for Bearer token authentication.\n * @param fetch - Optional original fetch implementation to wrap. Defaults to global fetch.\n * @returns A FetchFunction that adds Authorization header with Bearer token to requests.\n */\nexport function createApiKeyFetchFunction(\n apiKey: string,\n fetch?: FetchFunction,\n): FetchFunction {\n return async (\n input: RequestInfo | URL,\n init?: RequestInit,\n ): Promise<Response> => {\n // avoid caching globalThis.fetch in case it is patched by other libraries\n const effectiveFetch = fetch ?? globalThis.fetch;\n const originalHeaders = normalizeHeaders(init?.headers);\n const headersWithUserAgent = withUserAgentSuffix(\n originalHeaders,\n `ai-sdk/amazon-bedrock/${VERSION}`,\n getRuntimeEnvironmentUserAgent(),\n );\n\n const finalHeaders = combineHeaders(headersWithUserAgent, {\n Authorization: `Bearer ${apiKey}`,\n });\n\n return effectiveFetch(input, {\n ...init,\n headers: finalHeaders as HeadersInit,\n });\n };\n}\n","// Version string of this package injected at build time.\ndeclare const __PACKAGE_VERSION__: string | undefined;\nexport const VERSION: string =\n typeof __PACKAGE_VERSION__ !== 'undefined'\n ? __PACKAGE_VERSION__\n : '0.0.0-test';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,sBAGO;AACP,sBAIO;AACP,IAAAA,yBAMO;;;ACfP,4BAMO;AACP,uBAA4B;;;ACLrB,IAAM,UACX,OACI,WACA;;;ADoBC,SAAS,yBACd,gBAGA,OACA,UAAkB,WACH;AACf,SAAO,OACL,OACA,SACsB;AAEtB,UAAM,iBAAiB,SAAS,WAAW;AAC3C,UAAM,UAAU,iBAAiB,UAAU,QAAQ;AACnD,UAAM,sBAAkB;AAAA,UACtB,wC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MAAM,QAAQ,MAC3B,GAAG,WAAW,OAAO,CAAC,GAAG,IAAI;AAE/B,QAAM,kBAAkB,CAAC,YACvB,IAAI,wCAAwB,SAAS;AAAA,IACnC,UAAU;AAAA,IACV;AAAA,IACA,SAAS;AAAA,IACT,OAAO;AAAA,EACT,CAAC;AAEH,QAAM,uBAAuB,CAAC,YAC5B,IAAI,6CAA6B,SAAS;AAAA,IACxC,UAAU;AAAA,IACV;AAAA,IACA,SAAS;AAAA,IACT,OAAO;AAAA,IACP,iCAAiC;AAAA,EACnC,CAAC;AAEH,QAAM,WAAW,SAAU,SAAmC;AAC5D,QAAI,YAAY;AACd,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAEA,WAAO,gBAAgB,OAAO;AAAA,EAChC;AAEA,WAAS,uBAAuB;AAChC,WAAS,gBAAgB;AACzB,WAAS,OAAO;AAChB,WAAS,YAAY;AAErB,WAAS,iBAAiB,CAAC,YAAoB;AAC7C,UAAM,IAAI,iCAAiB,EAAE,SAAS,WAAW,iBAAiB,CAAC;AAAA,EACrE;AACA,WAAS,qBAAqB,SAAS;AACvC,WAAS,aAAa,CAAC,YAAoB;AACzC,UAAM,IAAI,iCAAiB,EAAE,SAAS,WAAW,aAAa,CAAC;AAAA,EACjE;AAEA,SAAO;AACT;AAKO,IAAM,gBAAgB,oBAAoB;","names":["import_provider_utils"]}
|
|
1
|
+
{"version":3,"sources":["../../src/mantle/index.ts","../../src/mantle/bedrock-mantle-provider.ts","../../src/amazon-bedrock-sigv4-fetch.ts","../../src/version.ts"],"sourcesContent":["export { bedrockMantle, createBedrockMantle } from './bedrock-mantle-provider';\nexport type {\n BedrockMantleProvider,\n BedrockMantleProviderSettings,\n} from './bedrock-mantle-provider';\nexport type { BedrockMantleModelId } from './bedrock-mantle-options';\n","import {\n OpenAIChatLanguageModel,\n OpenAIResponsesLanguageModel,\n} from '@ai-sdk/openai/internal';\nimport {\n NoSuchModelError,\n type LanguageModelV4,\n type ProviderV4,\n} from '@ai-sdk/provider';\nimport {\n loadOptionalSetting,\n loadSetting,\n withoutTrailingSlash,\n withUserAgentSuffix,\n type FetchFunction,\n} from '@ai-sdk/provider-utils';\nimport {\n createApiKeyFetchFunction,\n createSigV4FetchFunction,\n type AmazonBedrockCredentials,\n} from '../amazon-bedrock-sigv4-fetch';\nimport type {\n BedrockMantleChatModelId,\n BedrockMantleResponsesModelId,\n} from './bedrock-mantle-options';\nimport { VERSION } from '../version';\n\nexport interface BedrockMantleProvider extends ProviderV4 {\n /**\n * Creates a model for text generation using the Chat Completions API.\n * Chat Completions has the broadest model support on Mantle.\n */\n (modelId: BedrockMantleChatModelId): LanguageModelV4;\n\n /**\n * Creates a model for text generation using the Chat Completions API.\n */\n languageModel(modelId: BedrockMantleChatModelId): LanguageModelV4;\n\n /**\n * Creates a model for text generation using the Chat Completions API.\n */\n chat(modelId: BedrockMantleChatModelId): LanguageModelV4;\n\n /**\n * Creates a model for text generation using the Responses API.\n * Not all Mantle models support this API. Notably, gpt-oss-safeguard models\n * are Chat-only.\n */\n responses(modelId: BedrockMantleResponsesModelId): LanguageModelV4;\n\n /**\n * @deprecated Mantle does not support embedding models.\n */\n textEmbeddingModel(modelId: string): never;\n}\n\nexport interface BedrockMantleProviderSettings {\n /**\n * The AWS region to use for the Bedrock Mantle endpoint. Defaults to the value of the\n * `AWS_REGION` environment variable.\n */\n region?: string;\n\n /**\n * API key for authenticating requests using Bearer token authentication.\n * When provided, this will be used instead of AWS SigV4 authentication.\n * Defaults to the value of the `AWS_BEARER_TOKEN_BEDROCK` environment variable.\n */\n apiKey?: string;\n\n /**\n * The AWS access key ID to use for SigV4 authentication. Defaults to the value of the\n * `AWS_ACCESS_KEY_ID` environment variable.\n */\n accessKeyId?: string;\n\n /**\n * The AWS secret access key to use for SigV4 authentication. Defaults to the value of the\n * `AWS_SECRET_ACCESS_KEY` environment variable.\n */\n secretAccessKey?: string;\n\n /**\n * The AWS session token to use for SigV4 authentication. Defaults to the value of the\n * `AWS_SESSION_TOKEN` environment variable.\n */\n sessionToken?: string;\n\n /**\n * Base URL for the Bedrock Mantle API calls.\n */\n baseURL?: string;\n\n /**\n * Custom headers to include in the requests.\n */\n headers?: Record<string, string | undefined>;\n\n /**\n * Custom fetch implementation. You can use it as a middleware to intercept requests,\n * or to provide a custom fetch implementation for e.g. testing.\n */\n fetch?: FetchFunction;\n\n /**\n * The AWS credential provider to use for SigV4 authentication to get dynamic\n * credentials similar to the AWS SDK. Setting a provider here will cause its\n * credential values to be used instead of the `accessKeyId`, `secretAccessKey`,\n * and `sessionToken` settings.\n */\n credentialProvider?: () => PromiseLike<\n Omit<AmazonBedrockCredentials, 'region'>\n >;\n}\n\n/**\n * Create an Amazon Bedrock Mantle provider instance.\n * This provider uses the OpenAI-compatible Mantle API for models that are\n * only available through the Mantle endpoint (e.g. openai.gpt-oss-20b).\n */\nexport function createBedrockMantle(\n options: BedrockMantleProviderSettings = {},\n): BedrockMantleProvider {\n // Check for API key authentication first\n const rawApiKey = loadOptionalSetting({\n settingValue: options.apiKey,\n environmentVariableName: 'AWS_BEARER_TOKEN_BEDROCK',\n });\n\n // Only use API key if it's a non-empty, non-whitespace string\n const apiKey =\n rawApiKey && rawApiKey.trim().length > 0 ? rawApiKey.trim() : undefined;\n\n // Use API key authentication if available, otherwise fall back to SigV4\n const fetchFunction = apiKey\n ? createApiKeyFetchFunction(apiKey, options.fetch)\n : createSigV4FetchFunction(\n async () => {\n const region = loadSetting({\n settingValue: options.region,\n settingName: 'region',\n environmentVariableName: 'AWS_REGION',\n description: 'AWS region',\n });\n\n // If a credential provider is provided, use it to get the credentials.\n if (options.credentialProvider) {\n try {\n return {\n ...(await options.credentialProvider()),\n region,\n };\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : String(error);\n throw new Error(\n `AWS credential provider failed: ${errorMessage}. ` +\n 'Please ensure your credential provider returns valid AWS credentials ' +\n 'with accessKeyId and secretAccessKey properties.',\n );\n }\n }\n\n try {\n return {\n region,\n accessKeyId: loadSetting({\n settingValue: options.accessKeyId,\n settingName: 'accessKeyId',\n environmentVariableName: 'AWS_ACCESS_KEY_ID',\n description: 'AWS access key ID',\n }),\n secretAccessKey: loadSetting({\n settingValue: options.secretAccessKey,\n settingName: 'secretAccessKey',\n environmentVariableName: 'AWS_SECRET_ACCESS_KEY',\n description: 'AWS secret access key',\n }),\n sessionToken: loadOptionalSetting({\n settingValue: options.sessionToken,\n environmentVariableName: 'AWS_SESSION_TOKEN',\n }),\n };\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : String(error);\n if (\n errorMessage.includes('AWS_ACCESS_KEY_ID') ||\n errorMessage.includes('accessKeyId')\n ) {\n throw new Error(\n 'AWS SigV4 authentication requires AWS credentials. Please provide either:\\n' +\n '1. Set AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables\\n' +\n '2. Provide accessKeyId and secretAccessKey in options\\n' +\n '3. Use a credentialProvider function\\n' +\n '4. Use API key authentication with AWS_BEARER_TOKEN_BEDROCK or apiKey option\\n' +\n `Original error: ${errorMessage}`,\n );\n }\n if (\n errorMessage.includes('AWS_SECRET_ACCESS_KEY') ||\n errorMessage.includes('secretAccessKey')\n ) {\n throw new Error(\n 'AWS SigV4 authentication requires both AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY. ' +\n 'Please ensure both credentials are provided.\\n' +\n `Original error: ${errorMessage}`,\n );\n }\n throw error;\n }\n },\n options.fetch,\n 'bedrock-mantle',\n );\n\n const getBaseURL = (modelId: string): string =>\n withoutTrailingSlash(\n options.baseURL ??\n `https://bedrock-mantle.${loadSetting({\n settingValue: options.region,\n settingName: 'region',\n environmentVariableName: 'AWS_REGION',\n description: 'AWS region',\n })}.api.aws/${\n // Mantle serves these models under its separate OpenAI route.\n /^(?:openai\\.gpt-(?!oss-)|google\\.gemma-4|xai\\.)/.test(modelId)\n ? 'openai/v1'\n : 'v1'\n }`,\n ) ?? 'https://bedrock-mantle.us-east-1.api.aws/v1';\n\n const getHeaders = (): Record<string, string | undefined> =>\n withUserAgentSuffix(\n options.headers ?? {},\n `ai-sdk-amazon-bedrock/${VERSION}`,\n );\n\n const url = ({ path, modelId }: { path: string; modelId: string }): string =>\n `${getBaseURL(modelId)}${path}`;\n\n const createChatModel = (modelId: BedrockMantleChatModelId) =>\n new OpenAIChatLanguageModel(modelId, {\n provider: 'bedrock-mantle.chat',\n url,\n headers: getHeaders,\n fetch: fetchFunction,\n });\n\n const createResponsesModel = (modelId: BedrockMantleResponsesModelId) =>\n new OpenAIResponsesLanguageModel(modelId, {\n provider: 'bedrock-mantle.responses',\n url,\n headers: getHeaders,\n fetch: fetchFunction,\n supportsWebSearchSourcesInclude: false,\n });\n\n const provider = function (modelId: BedrockMantleChatModelId) {\n if (new.target) {\n throw new Error(\n 'The Bedrock Mantle model function cannot be called with the new keyword.',\n );\n }\n\n return createChatModel(modelId);\n };\n\n provider.specificationVersion = 'v4' as const;\n provider.languageModel = createChatModel;\n provider.chat = createChatModel;\n provider.responses = createResponsesModel;\n\n provider.embeddingModel = (modelId: string) => {\n throw new NoSuchModelError({ modelId, modelType: 'embeddingModel' });\n };\n provider.textEmbeddingModel = provider.embeddingModel;\n provider.imageModel = (modelId: string) => {\n throw new NoSuchModelError({ modelId, modelType: 'imageModel' });\n };\n\n return provider as BedrockMantleProvider;\n}\n\n/**\n * Default Bedrock Mantle provider instance.\n */\nexport const bedrockMantle = createBedrockMantle();\n","import {\n combineHeaders,\n normalizeHeaders,\n withUserAgentSuffix,\n getRuntimeEnvironmentUserAgent,\n type FetchFunction,\n} from '@ai-sdk/provider-utils';\nimport { AwsV4Signer } from 'aws4fetch';\nimport { VERSION } from './version';\n\nexport interface AmazonBedrockCredentials {\n region: string;\n accessKeyId: string;\n secretAccessKey: string;\n sessionToken?: string;\n}\n\n/**\n * Creates a fetch function that applies AWS Signature Version 4 signing.\n *\n * @param getCredentials - Function that returns the AWS credentials to use when signing.\n * @param fetch - Optional original fetch implementation to wrap. Defaults to global fetch.\n * @param service - The AWS service name to use for SigV4 signing scope. Defaults to 'bedrock'.\n * @returns A FetchFunction that signs requests before passing them to the underlying fetch.\n */\nexport function createSigV4FetchFunction(\n getCredentials: () =>\n | AmazonBedrockCredentials\n | PromiseLike<AmazonBedrockCredentials>,\n fetch?: FetchFunction,\n service: string = 'bedrock',\n): FetchFunction {\n return async (\n input: RequestInfo | URL,\n init?: RequestInit,\n ): Promise<Response> => {\n // avoid caching globalThis.fetch in case it is patched by other libraries\n const effectiveFetch = fetch ?? globalThis.fetch;\n const request = input instanceof Request ? input : undefined;\n const originalHeaders = combineHeaders(\n normalizeHeaders(request?.headers),\n normalizeHeaders(init?.headers),\n );\n const headersWithUserAgent = withUserAgentSuffix(\n originalHeaders,\n `ai-sdk-amazon-bedrock/${VERSION}`,\n getRuntimeEnvironmentUserAgent(),\n );\n\n let effectiveBody: BodyInit | undefined = init?.body ?? undefined;\n if (effectiveBody === undefined && request && request.body !== null) {\n try {\n effectiveBody = await request.clone().text();\n } catch {}\n }\n\n const effectiveMethod = init?.method ?? request?.method;\n\n if (effectiveMethod?.toUpperCase() !== 'POST' || !effectiveBody) {\n return effectiveFetch(input, {\n ...init,\n headers: headersWithUserAgent as HeadersInit,\n });\n }\n\n const url =\n typeof input === 'string'\n ? input\n : input instanceof URL\n ? input.href\n : input.url;\n\n const body = prepareBodyString(effectiveBody);\n const credentials = await getCredentials();\n const signer = new AwsV4Signer({\n url,\n method: 'POST',\n headers: Object.entries(headersWithUserAgent),\n body,\n region: credentials.region,\n accessKeyId: credentials.accessKeyId,\n secretAccessKey: credentials.secretAccessKey,\n sessionToken: credentials.sessionToken,\n service,\n });\n\n const signingResult = await signer.sign();\n const signedHeaders = normalizeHeaders(signingResult.headers);\n\n // Use the combined headers directly as HeadersInit\n const combinedHeaders = combineHeaders(headersWithUserAgent, signedHeaders);\n\n return effectiveFetch(input, {\n ...init,\n body,\n headers: combinedHeaders as HeadersInit,\n });\n };\n}\n\nfunction prepareBodyString(body: BodyInit | undefined): string {\n if (typeof body === 'string') {\n return body;\n } else if (body instanceof Uint8Array) {\n return new TextDecoder().decode(body);\n } else if (body instanceof ArrayBuffer) {\n return new TextDecoder().decode(new Uint8Array(body));\n } else {\n return JSON.stringify(body);\n }\n}\n\n/**\n * Creates a fetch function that applies Bearer token authentication.\n *\n * @param apiKey - The API key to use for Bearer token authentication.\n * @param fetch - Optional original fetch implementation to wrap. Defaults to global fetch.\n * @returns A FetchFunction that adds Authorization header with Bearer token to requests.\n */\nexport function createApiKeyFetchFunction(\n apiKey: string,\n fetch?: FetchFunction,\n): FetchFunction {\n return async (\n input: RequestInfo | URL,\n init?: RequestInit,\n ): Promise<Response> => {\n // avoid caching globalThis.fetch in case it is patched by other libraries\n const effectiveFetch = fetch ?? globalThis.fetch;\n const originalHeaders = normalizeHeaders(init?.headers);\n const headersWithUserAgent = withUserAgentSuffix(\n originalHeaders,\n `ai-sdk-amazon-bedrock/${VERSION}`,\n getRuntimeEnvironmentUserAgent(),\n );\n\n const finalHeaders = combineHeaders(headersWithUserAgent, {\n Authorization: `Bearer ${apiKey}`,\n });\n\n return effectiveFetch(input, {\n ...init,\n headers: finalHeaders as HeadersInit,\n });\n };\n}\n","// Version string of this package injected at build time.\ndeclare const __PACKAGE_VERSION__: string | undefined;\nexport const VERSION: string =\n typeof __PACKAGE_VERSION__ !== 'undefined'\n ? __PACKAGE_VERSION__\n : '0.0.0-test';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,sBAGO;AACP,sBAIO;AACP,IAAAA,yBAMO;;;ACfP,4BAMO;AACP,uBAA4B;;;ACLrB,IAAM,UACX,OACI,YACA;;;ADoBC,SAAS,yBACd,gBAGA,OACA,UAAkB,WACH;AACf,SAAO,OACL,OACA,SACsB;AAEtB,UAAM,iBAAiB,SAAS,WAAW;AAC3C,UAAM,UAAU,iBAAiB,UAAU,QAAQ;AACnD,UAAM,sBAAkB;AAAA,UACtB,w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,MAAM,QAAQ,MAC3B,GAAG,WAAW,OAAO,CAAC,GAAG,IAAI;AAE/B,QAAM,kBAAkB,CAAC,YACvB,IAAI,wCAAwB,SAAS;AAAA,IACnC,UAAU;AAAA,IACV;AAAA,IACA,SAAS;AAAA,IACT,OAAO;AAAA,EACT,CAAC;AAEH,QAAM,uBAAuB,CAAC,YAC5B,IAAI,6CAA6B,SAAS;AAAA,IACxC,UAAU;AAAA,IACV;AAAA,IACA,SAAS;AAAA,IACT,OAAO;AAAA,IACP,iCAAiC;AAAA,EACnC,CAAC;AAEH,QAAM,WAAW,SAAU,SAAmC;AAC5D,QAAI,YAAY;AACd,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAEA,WAAO,gBAAgB,OAAO;AAAA,EAChC;AAEA,WAAS,uBAAuB;AAChC,WAAS,gBAAgB;AACzB,WAAS,OAAO;AAChB,WAAS,YAAY;AAErB,WAAS,iBAAiB,CAAC,YAAoB;AAC7C,UAAM,IAAI,iCAAiB,EAAE,SAAS,WAAW,iBAAiB,CAAC;AAAA,EACrE;AACA,WAAS,qBAAqB,SAAS;AACvC,WAAS,aAAa,CAAC,YAAoB;AACzC,UAAM,IAAI,iCAAiB,EAAE,SAAS,WAAW,aAAa,CAAC;AAAA,EACjE;AAEA,SAAO;AACT;AAKO,IAAM,gBAAgB,oBAAoB;","names":["import_provider_utils"]}
|
package/dist/mantle/index.js
CHANGED
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
import { AwsV4Signer } from "aws4fetch";
|
|
24
24
|
|
|
25
25
|
// src/version.ts
|
|
26
|
-
var VERSION = true ? "5.0.
|
|
26
|
+
var VERSION = true ? "5.0.100" : "0.0.0-test";
|
|
27
27
|
|
|
28
28
|
// src/amazon-bedrock-sigv4-fetch.ts
|
|
29
29
|
function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {
|
|
@@ -36,7 +36,7 @@ function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {
|
|
|
36
36
|
);
|
|
37
37
|
const headersWithUserAgent = withUserAgentSuffix(
|
|
38
38
|
originalHeaders,
|
|
39
|
-
`ai-sdk
|
|
39
|
+
`ai-sdk-amazon-bedrock/${VERSION}`,
|
|
40
40
|
getRuntimeEnvironmentUserAgent()
|
|
41
41
|
);
|
|
42
42
|
let effectiveBody = init?.body ?? void 0;
|
|
@@ -94,7 +94,7 @@ function createApiKeyFetchFunction(apiKey, fetch) {
|
|
|
94
94
|
const originalHeaders = normalizeHeaders(init?.headers);
|
|
95
95
|
const headersWithUserAgent = withUserAgentSuffix(
|
|
96
96
|
originalHeaders,
|
|
97
|
-
`ai-sdk
|
|
97
|
+
`ai-sdk-amazon-bedrock/${VERSION}`,
|
|
98
98
|
getRuntimeEnvironmentUserAgent()
|
|
99
99
|
);
|
|
100
100
|
const finalHeaders = combineHeaders(headersWithUserAgent, {
|
|
@@ -190,7 +190,7 @@ Original error: ${errorMessage}`
|
|
|
190
190
|
) ?? "https://bedrock-mantle.us-east-1.api.aws/v1";
|
|
191
191
|
const getHeaders = () => withUserAgentSuffix2(
|
|
192
192
|
options.headers ?? {},
|
|
193
|
-
`ai-sdk
|
|
193
|
+
`ai-sdk-amazon-bedrock/${VERSION}`
|
|
194
194
|
);
|
|
195
195
|
const url = ({ path, modelId }) => `${getBaseURL(modelId)}${path}`;
|
|
196
196
|
const createChatModel = (modelId) => new OpenAIChatLanguageModel(modelId, {
|
package/dist/mantle/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/mantle/bedrock-mantle-provider.ts","../../src/amazon-bedrock-sigv4-fetch.ts","../../src/version.ts"],"sourcesContent":["import {\n OpenAIChatLanguageModel,\n OpenAIResponsesLanguageModel,\n} from '@ai-sdk/openai/internal';\nimport {\n NoSuchModelError,\n type LanguageModelV4,\n type ProviderV4,\n} from '@ai-sdk/provider';\nimport {\n loadOptionalSetting,\n loadSetting,\n withoutTrailingSlash,\n withUserAgentSuffix,\n type FetchFunction,\n} from '@ai-sdk/provider-utils';\nimport {\n createApiKeyFetchFunction,\n createSigV4FetchFunction,\n type AmazonBedrockCredentials,\n} from '../amazon-bedrock-sigv4-fetch';\nimport type {\n BedrockMantleChatModelId,\n BedrockMantleResponsesModelId,\n} from './bedrock-mantle-options';\nimport { VERSION } from '../version';\n\nexport interface BedrockMantleProvider extends ProviderV4 {\n /**\n * Creates a model for text generation using the Chat Completions API.\n * Chat Completions has the broadest model support on Mantle.\n */\n (modelId: BedrockMantleChatModelId): LanguageModelV4;\n\n /**\n * Creates a model for text generation using the Chat Completions API.\n */\n languageModel(modelId: BedrockMantleChatModelId): LanguageModelV4;\n\n /**\n * Creates a model for text generation using the Chat Completions API.\n */\n chat(modelId: BedrockMantleChatModelId): LanguageModelV4;\n\n /**\n * Creates a model for text generation using the Responses API.\n * Not all Mantle models support this API. Notably, gpt-oss-safeguard models\n * are Chat-only.\n */\n responses(modelId: BedrockMantleResponsesModelId): LanguageModelV4;\n\n /**\n * @deprecated Mantle does not support embedding models.\n */\n textEmbeddingModel(modelId: string): never;\n}\n\nexport interface BedrockMantleProviderSettings {\n /**\n * The AWS region to use for the Bedrock Mantle endpoint. Defaults to the value of the\n * `AWS_REGION` environment variable.\n */\n region?: string;\n\n /**\n * API key for authenticating requests using Bearer token authentication.\n * When provided, this will be used instead of AWS SigV4 authentication.\n * Defaults to the value of the `AWS_BEARER_TOKEN_BEDROCK` environment variable.\n */\n apiKey?: string;\n\n /**\n * The AWS access key ID to use for SigV4 authentication. Defaults to the value of the\n * `AWS_ACCESS_KEY_ID` environment variable.\n */\n accessKeyId?: string;\n\n /**\n * The AWS secret access key to use for SigV4 authentication. Defaults to the value of the\n * `AWS_SECRET_ACCESS_KEY` environment variable.\n */\n secretAccessKey?: string;\n\n /**\n * The AWS session token to use for SigV4 authentication. Defaults to the value of the\n * `AWS_SESSION_TOKEN` environment variable.\n */\n sessionToken?: string;\n\n /**\n * Base URL for the Bedrock Mantle API calls.\n */\n baseURL?: string;\n\n /**\n * Custom headers to include in the requests.\n */\n headers?: Record<string, string | undefined>;\n\n /**\n * Custom fetch implementation. You can use it as a middleware to intercept requests,\n * or to provide a custom fetch implementation for e.g. testing.\n */\n fetch?: FetchFunction;\n\n /**\n * The AWS credential provider to use for SigV4 authentication to get dynamic\n * credentials similar to the AWS SDK. Setting a provider here will cause its\n * credential values to be used instead of the `accessKeyId`, `secretAccessKey`,\n * and `sessionToken` settings.\n */\n credentialProvider?: () => PromiseLike<\n Omit<AmazonBedrockCredentials, 'region'>\n >;\n}\n\n/**\n * Create an Amazon Bedrock Mantle provider instance.\n * This provider uses the OpenAI-compatible Mantle API for models that are\n * only available through the Mantle endpoint (e.g. openai.gpt-oss-20b).\n */\nexport function createBedrockMantle(\n options: BedrockMantleProviderSettings = {},\n): BedrockMantleProvider {\n // Check for API key authentication first\n const rawApiKey = loadOptionalSetting({\n settingValue: options.apiKey,\n environmentVariableName: 'AWS_BEARER_TOKEN_BEDROCK',\n });\n\n // Only use API key if it's a non-empty, non-whitespace string\n const apiKey =\n rawApiKey && rawApiKey.trim().length > 0 ? rawApiKey.trim() : undefined;\n\n // Use API key authentication if available, otherwise fall back to SigV4\n const fetchFunction = apiKey\n ? createApiKeyFetchFunction(apiKey, options.fetch)\n : createSigV4FetchFunction(\n async () => {\n const region = loadSetting({\n settingValue: options.region,\n settingName: 'region',\n environmentVariableName: 'AWS_REGION',\n description: 'AWS region',\n });\n\n // If a credential provider is provided, use it to get the credentials.\n if (options.credentialProvider) {\n try {\n return {\n ...(await options.credentialProvider()),\n region,\n };\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : String(error);\n throw new Error(\n `AWS credential provider failed: ${errorMessage}. ` +\n 'Please ensure your credential provider returns valid AWS credentials ' +\n 'with accessKeyId and secretAccessKey properties.',\n );\n }\n }\n\n try {\n return {\n region,\n accessKeyId: loadSetting({\n settingValue: options.accessKeyId,\n settingName: 'accessKeyId',\n environmentVariableName: 'AWS_ACCESS_KEY_ID',\n description: 'AWS access key ID',\n }),\n secretAccessKey: loadSetting({\n settingValue: options.secretAccessKey,\n settingName: 'secretAccessKey',\n environmentVariableName: 'AWS_SECRET_ACCESS_KEY',\n description: 'AWS secret access key',\n }),\n sessionToken: loadOptionalSetting({\n settingValue: options.sessionToken,\n environmentVariableName: 'AWS_SESSION_TOKEN',\n }),\n };\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : String(error);\n if (\n errorMessage.includes('AWS_ACCESS_KEY_ID') ||\n errorMessage.includes('accessKeyId')\n ) {\n throw new Error(\n 'AWS SigV4 authentication requires AWS credentials. Please provide either:\\n' +\n '1. Set AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables\\n' +\n '2. Provide accessKeyId and secretAccessKey in options\\n' +\n '3. Use a credentialProvider function\\n' +\n '4. Use API key authentication with AWS_BEARER_TOKEN_BEDROCK or apiKey option\\n' +\n `Original error: ${errorMessage}`,\n );\n }\n if (\n errorMessage.includes('AWS_SECRET_ACCESS_KEY') ||\n errorMessage.includes('secretAccessKey')\n ) {\n throw new Error(\n 'AWS SigV4 authentication requires both AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY. ' +\n 'Please ensure both credentials are provided.\\n' +\n `Original error: ${errorMessage}`,\n );\n }\n throw error;\n }\n },\n options.fetch,\n 'bedrock-mantle',\n );\n\n const getBaseURL = (modelId: string): string =>\n withoutTrailingSlash(\n options.baseURL ??\n `https://bedrock-mantle.${loadSetting({\n settingValue: options.region,\n settingName: 'region',\n environmentVariableName: 'AWS_REGION',\n description: 'AWS region',\n })}.api.aws/${\n // Mantle serves these models under its separate OpenAI route.\n /^(?:openai\\.gpt-(?!oss-)|google\\.gemma-4|xai\\.)/.test(modelId)\n ? 'openai/v1'\n : 'v1'\n }`,\n ) ?? 'https://bedrock-mantle.us-east-1.api.aws/v1';\n\n const getHeaders = (): Record<string, string | undefined> =>\n withUserAgentSuffix(\n options.headers ?? {},\n `ai-sdk/amazon-bedrock/${VERSION}`,\n );\n\n const url = ({ path, modelId }: { path: string; modelId: string }): string =>\n `${getBaseURL(modelId)}${path}`;\n\n const createChatModel = (modelId: BedrockMantleChatModelId) =>\n new OpenAIChatLanguageModel(modelId, {\n provider: 'bedrock-mantle.chat',\n url,\n headers: getHeaders,\n fetch: fetchFunction,\n });\n\n const createResponsesModel = (modelId: BedrockMantleResponsesModelId) =>\n new OpenAIResponsesLanguageModel(modelId, {\n provider: 'bedrock-mantle.responses',\n url,\n headers: getHeaders,\n fetch: fetchFunction,\n supportsWebSearchSourcesInclude: false,\n });\n\n const provider = function (modelId: BedrockMantleChatModelId) {\n if (new.target) {\n throw new Error(\n 'The Bedrock Mantle model function cannot be called with the new keyword.',\n );\n }\n\n return createChatModel(modelId);\n };\n\n provider.specificationVersion = 'v4' as const;\n provider.languageModel = createChatModel;\n provider.chat = createChatModel;\n provider.responses = createResponsesModel;\n\n provider.embeddingModel = (modelId: string) => {\n throw new NoSuchModelError({ modelId, modelType: 'embeddingModel' });\n };\n provider.textEmbeddingModel = provider.embeddingModel;\n provider.imageModel = (modelId: string) => {\n throw new NoSuchModelError({ modelId, modelType: 'imageModel' });\n };\n\n return provider as BedrockMantleProvider;\n}\n\n/**\n * Default Bedrock Mantle provider instance.\n */\nexport const bedrockMantle = createBedrockMantle();\n","import {\n combineHeaders,\n normalizeHeaders,\n withUserAgentSuffix,\n getRuntimeEnvironmentUserAgent,\n type FetchFunction,\n} from '@ai-sdk/provider-utils';\nimport { AwsV4Signer } from 'aws4fetch';\nimport { VERSION } from './version';\n\nexport interface AmazonBedrockCredentials {\n region: string;\n accessKeyId: string;\n secretAccessKey: string;\n sessionToken?: string;\n}\n\n/**\n * Creates a fetch function that applies AWS Signature Version 4 signing.\n *\n * @param getCredentials - Function that returns the AWS credentials to use when signing.\n * @param fetch - Optional original fetch implementation to wrap. Defaults to global fetch.\n * @param service - The AWS service name to use for SigV4 signing scope. Defaults to 'bedrock'.\n * @returns A FetchFunction that signs requests before passing them to the underlying fetch.\n */\nexport function createSigV4FetchFunction(\n getCredentials: () =>\n | AmazonBedrockCredentials\n | PromiseLike<AmazonBedrockCredentials>,\n fetch?: FetchFunction,\n service: string = 'bedrock',\n): FetchFunction {\n return async (\n input: RequestInfo | URL,\n init?: RequestInit,\n ): Promise<Response> => {\n // avoid caching globalThis.fetch in case it is patched by other libraries\n const effectiveFetch = fetch ?? globalThis.fetch;\n const request = input instanceof Request ? input : undefined;\n const originalHeaders = combineHeaders(\n normalizeHeaders(request?.headers),\n normalizeHeaders(init?.headers),\n );\n const headersWithUserAgent = withUserAgentSuffix(\n originalHeaders,\n `ai-sdk/amazon-bedrock/${VERSION}`,\n getRuntimeEnvironmentUserAgent(),\n );\n\n let effectiveBody: BodyInit | undefined = init?.body ?? undefined;\n if (effectiveBody === undefined && request && request.body !== null) {\n try {\n effectiveBody = await request.clone().text();\n } catch {}\n }\n\n const effectiveMethod = init?.method ?? request?.method;\n\n if (effectiveMethod?.toUpperCase() !== 'POST' || !effectiveBody) {\n return effectiveFetch(input, {\n ...init,\n headers: headersWithUserAgent as HeadersInit,\n });\n }\n\n const url =\n typeof input === 'string'\n ? input\n : input instanceof URL\n ? input.href\n : input.url;\n\n const body = prepareBodyString(effectiveBody);\n const credentials = await getCredentials();\n const signer = new AwsV4Signer({\n url,\n method: 'POST',\n headers: Object.entries(headersWithUserAgent),\n body,\n region: credentials.region,\n accessKeyId: credentials.accessKeyId,\n secretAccessKey: credentials.secretAccessKey,\n sessionToken: credentials.sessionToken,\n service,\n });\n\n const signingResult = await signer.sign();\n const signedHeaders = normalizeHeaders(signingResult.headers);\n\n // Use the combined headers directly as HeadersInit\n const combinedHeaders = combineHeaders(headersWithUserAgent, signedHeaders);\n\n return effectiveFetch(input, {\n ...init,\n body,\n headers: combinedHeaders as HeadersInit,\n });\n };\n}\n\nfunction prepareBodyString(body: BodyInit | undefined): string {\n if (typeof body === 'string') {\n return body;\n } else if (body instanceof Uint8Array) {\n return new TextDecoder().decode(body);\n } else if (body instanceof ArrayBuffer) {\n return new TextDecoder().decode(new Uint8Array(body));\n } else {\n return JSON.stringify(body);\n }\n}\n\n/**\n * Creates a fetch function that applies Bearer token authentication.\n *\n * @param apiKey - The API key to use for Bearer token authentication.\n * @param fetch - Optional original fetch implementation to wrap. Defaults to global fetch.\n * @returns A FetchFunction that adds Authorization header with Bearer token to requests.\n */\nexport function createApiKeyFetchFunction(\n apiKey: string,\n fetch?: FetchFunction,\n): FetchFunction {\n return async (\n input: RequestInfo | URL,\n init?: RequestInit,\n ): Promise<Response> => {\n // avoid caching globalThis.fetch in case it is patched by other libraries\n const effectiveFetch = fetch ?? globalThis.fetch;\n const originalHeaders = normalizeHeaders(init?.headers);\n const headersWithUserAgent = withUserAgentSuffix(\n originalHeaders,\n `ai-sdk/amazon-bedrock/${VERSION}`,\n getRuntimeEnvironmentUserAgent(),\n );\n\n const finalHeaders = combineHeaders(headersWithUserAgent, {\n Authorization: `Bearer ${apiKey}`,\n });\n\n return effectiveFetch(input, {\n ...init,\n headers: finalHeaders as HeadersInit,\n });\n };\n}\n","// Version string of this package injected at build time.\ndeclare const __PACKAGE_VERSION__: string | undefined;\nexport const VERSION: string =\n typeof __PACKAGE_VERSION__ !== 'undefined'\n ? __PACKAGE_VERSION__\n : '0.0.0-test';\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,OAGK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA,uBAAAA;AAAA,OAEK;;;ACfP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,mBAAmB;;;ACLrB,IAAM,UACX,OACI,WACA;;;ADoBC,SAAS,yBACd,gBAGA,OACA,UAAkB,WACH;AACf,SAAO,OACL,OACA,SACsB;AAEtB,UAAM,iBAAiB,SAAS,WAAW;AAC3C,UAAM,UAAU,iBAAiB,UAAU,QAAQ;AACnD,UAAM,kBAAkB;AAAA,MACtB,iBAAiB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B,GAAG,WAAW,OAAO,CAAC,GAAG,IAAI;AAE/B,QAAM,kBAAkB,CAAC,YACvB,IAAI,wBAAwB,SAAS;AAAA,IACnC,UAAU;AAAA,IACV;AAAA,IACA,SAAS;AAAA,IACT,OAAO;AAAA,EACT,CAAC;AAEH,QAAM,uBAAuB,CAAC,YAC5B,IAAI,6BAA6B,SAAS;AAAA,IACxC,UAAU;AAAA,IACV;AAAA,IACA,SAAS;AAAA,IACT,OAAO;AAAA,IACP,iCAAiC;AAAA,EACnC,CAAC;AAEH,QAAM,WAAW,SAAU,SAAmC;AAC5D,QAAI,YAAY;AACd,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAEA,WAAO,gBAAgB,OAAO;AAAA,EAChC;AAEA,WAAS,uBAAuB;AAChC,WAAS,gBAAgB;AACzB,WAAS,OAAO;AAChB,WAAS,YAAY;AAErB,WAAS,iBAAiB,CAAC,YAAoB;AAC7C,UAAM,IAAI,iBAAiB,EAAE,SAAS,WAAW,iBAAiB,CAAC;AAAA,EACrE;AACA,WAAS,qBAAqB,SAAS;AACvC,WAAS,aAAa,CAAC,YAAoB;AACzC,UAAM,IAAI,iBAAiB,EAAE,SAAS,WAAW,aAAa,CAAC;AAAA,EACjE;AAEA,SAAO;AACT;AAKO,IAAM,gBAAgB,oBAAoB;","names":["withUserAgentSuffix","withUserAgentSuffix"]}
|
|
1
|
+
{"version":3,"sources":["../../src/mantle/bedrock-mantle-provider.ts","../../src/amazon-bedrock-sigv4-fetch.ts","../../src/version.ts"],"sourcesContent":["import {\n OpenAIChatLanguageModel,\n OpenAIResponsesLanguageModel,\n} from '@ai-sdk/openai/internal';\nimport {\n NoSuchModelError,\n type LanguageModelV4,\n type ProviderV4,\n} from '@ai-sdk/provider';\nimport {\n loadOptionalSetting,\n loadSetting,\n withoutTrailingSlash,\n withUserAgentSuffix,\n type FetchFunction,\n} from '@ai-sdk/provider-utils';\nimport {\n createApiKeyFetchFunction,\n createSigV4FetchFunction,\n type AmazonBedrockCredentials,\n} from '../amazon-bedrock-sigv4-fetch';\nimport type {\n BedrockMantleChatModelId,\n BedrockMantleResponsesModelId,\n} from './bedrock-mantle-options';\nimport { VERSION } from '../version';\n\nexport interface BedrockMantleProvider extends ProviderV4 {\n /**\n * Creates a model for text generation using the Chat Completions API.\n * Chat Completions has the broadest model support on Mantle.\n */\n (modelId: BedrockMantleChatModelId): LanguageModelV4;\n\n /**\n * Creates a model for text generation using the Chat Completions API.\n */\n languageModel(modelId: BedrockMantleChatModelId): LanguageModelV4;\n\n /**\n * Creates a model for text generation using the Chat Completions API.\n */\n chat(modelId: BedrockMantleChatModelId): LanguageModelV4;\n\n /**\n * Creates a model for text generation using the Responses API.\n * Not all Mantle models support this API. Notably, gpt-oss-safeguard models\n * are Chat-only.\n */\n responses(modelId: BedrockMantleResponsesModelId): LanguageModelV4;\n\n /**\n * @deprecated Mantle does not support embedding models.\n */\n textEmbeddingModel(modelId: string): never;\n}\n\nexport interface BedrockMantleProviderSettings {\n /**\n * The AWS region to use for the Bedrock Mantle endpoint. Defaults to the value of the\n * `AWS_REGION` environment variable.\n */\n region?: string;\n\n /**\n * API key for authenticating requests using Bearer token authentication.\n * When provided, this will be used instead of AWS SigV4 authentication.\n * Defaults to the value of the `AWS_BEARER_TOKEN_BEDROCK` environment variable.\n */\n apiKey?: string;\n\n /**\n * The AWS access key ID to use for SigV4 authentication. Defaults to the value of the\n * `AWS_ACCESS_KEY_ID` environment variable.\n */\n accessKeyId?: string;\n\n /**\n * The AWS secret access key to use for SigV4 authentication. Defaults to the value of the\n * `AWS_SECRET_ACCESS_KEY` environment variable.\n */\n secretAccessKey?: string;\n\n /**\n * The AWS session token to use for SigV4 authentication. Defaults to the value of the\n * `AWS_SESSION_TOKEN` environment variable.\n */\n sessionToken?: string;\n\n /**\n * Base URL for the Bedrock Mantle API calls.\n */\n baseURL?: string;\n\n /**\n * Custom headers to include in the requests.\n */\n headers?: Record<string, string | undefined>;\n\n /**\n * Custom fetch implementation. You can use it as a middleware to intercept requests,\n * or to provide a custom fetch implementation for e.g. testing.\n */\n fetch?: FetchFunction;\n\n /**\n * The AWS credential provider to use for SigV4 authentication to get dynamic\n * credentials similar to the AWS SDK. Setting a provider here will cause its\n * credential values to be used instead of the `accessKeyId`, `secretAccessKey`,\n * and `sessionToken` settings.\n */\n credentialProvider?: () => PromiseLike<\n Omit<AmazonBedrockCredentials, 'region'>\n >;\n}\n\n/**\n * Create an Amazon Bedrock Mantle provider instance.\n * This provider uses the OpenAI-compatible Mantle API for models that are\n * only available through the Mantle endpoint (e.g. openai.gpt-oss-20b).\n */\nexport function createBedrockMantle(\n options: BedrockMantleProviderSettings = {},\n): BedrockMantleProvider {\n // Check for API key authentication first\n const rawApiKey = loadOptionalSetting({\n settingValue: options.apiKey,\n environmentVariableName: 'AWS_BEARER_TOKEN_BEDROCK',\n });\n\n // Only use API key if it's a non-empty, non-whitespace string\n const apiKey =\n rawApiKey && rawApiKey.trim().length > 0 ? rawApiKey.trim() : undefined;\n\n // Use API key authentication if available, otherwise fall back to SigV4\n const fetchFunction = apiKey\n ? createApiKeyFetchFunction(apiKey, options.fetch)\n : createSigV4FetchFunction(\n async () => {\n const region = loadSetting({\n settingValue: options.region,\n settingName: 'region',\n environmentVariableName: 'AWS_REGION',\n description: 'AWS region',\n });\n\n // If a credential provider is provided, use it to get the credentials.\n if (options.credentialProvider) {\n try {\n return {\n ...(await options.credentialProvider()),\n region,\n };\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : String(error);\n throw new Error(\n `AWS credential provider failed: ${errorMessage}. ` +\n 'Please ensure your credential provider returns valid AWS credentials ' +\n 'with accessKeyId and secretAccessKey properties.',\n );\n }\n }\n\n try {\n return {\n region,\n accessKeyId: loadSetting({\n settingValue: options.accessKeyId,\n settingName: 'accessKeyId',\n environmentVariableName: 'AWS_ACCESS_KEY_ID',\n description: 'AWS access key ID',\n }),\n secretAccessKey: loadSetting({\n settingValue: options.secretAccessKey,\n settingName: 'secretAccessKey',\n environmentVariableName: 'AWS_SECRET_ACCESS_KEY',\n description: 'AWS secret access key',\n }),\n sessionToken: loadOptionalSetting({\n settingValue: options.sessionToken,\n environmentVariableName: 'AWS_SESSION_TOKEN',\n }),\n };\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : String(error);\n if (\n errorMessage.includes('AWS_ACCESS_KEY_ID') ||\n errorMessage.includes('accessKeyId')\n ) {\n throw new Error(\n 'AWS SigV4 authentication requires AWS credentials. Please provide either:\\n' +\n '1. Set AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables\\n' +\n '2. Provide accessKeyId and secretAccessKey in options\\n' +\n '3. Use a credentialProvider function\\n' +\n '4. Use API key authentication with AWS_BEARER_TOKEN_BEDROCK or apiKey option\\n' +\n `Original error: ${errorMessage}`,\n );\n }\n if (\n errorMessage.includes('AWS_SECRET_ACCESS_KEY') ||\n errorMessage.includes('secretAccessKey')\n ) {\n throw new Error(\n 'AWS SigV4 authentication requires both AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY. ' +\n 'Please ensure both credentials are provided.\\n' +\n `Original error: ${errorMessage}`,\n );\n }\n throw error;\n }\n },\n options.fetch,\n 'bedrock-mantle',\n );\n\n const getBaseURL = (modelId: string): string =>\n withoutTrailingSlash(\n options.baseURL ??\n `https://bedrock-mantle.${loadSetting({\n settingValue: options.region,\n settingName: 'region',\n environmentVariableName: 'AWS_REGION',\n description: 'AWS region',\n })}.api.aws/${\n // Mantle serves these models under its separate OpenAI route.\n /^(?:openai\\.gpt-(?!oss-)|google\\.gemma-4|xai\\.)/.test(modelId)\n ? 'openai/v1'\n : 'v1'\n }`,\n ) ?? 'https://bedrock-mantle.us-east-1.api.aws/v1';\n\n const getHeaders = (): Record<string, string | undefined> =>\n withUserAgentSuffix(\n options.headers ?? {},\n `ai-sdk-amazon-bedrock/${VERSION}`,\n );\n\n const url = ({ path, modelId }: { path: string; modelId: string }): string =>\n `${getBaseURL(modelId)}${path}`;\n\n const createChatModel = (modelId: BedrockMantleChatModelId) =>\n new OpenAIChatLanguageModel(modelId, {\n provider: 'bedrock-mantle.chat',\n url,\n headers: getHeaders,\n fetch: fetchFunction,\n });\n\n const createResponsesModel = (modelId: BedrockMantleResponsesModelId) =>\n new OpenAIResponsesLanguageModel(modelId, {\n provider: 'bedrock-mantle.responses',\n url,\n headers: getHeaders,\n fetch: fetchFunction,\n supportsWebSearchSourcesInclude: false,\n });\n\n const provider = function (modelId: BedrockMantleChatModelId) {\n if (new.target) {\n throw new Error(\n 'The Bedrock Mantle model function cannot be called with the new keyword.',\n );\n }\n\n return createChatModel(modelId);\n };\n\n provider.specificationVersion = 'v4' as const;\n provider.languageModel = createChatModel;\n provider.chat = createChatModel;\n provider.responses = createResponsesModel;\n\n provider.embeddingModel = (modelId: string) => {\n throw new NoSuchModelError({ modelId, modelType: 'embeddingModel' });\n };\n provider.textEmbeddingModel = provider.embeddingModel;\n provider.imageModel = (modelId: string) => {\n throw new NoSuchModelError({ modelId, modelType: 'imageModel' });\n };\n\n return provider as BedrockMantleProvider;\n}\n\n/**\n * Default Bedrock Mantle provider instance.\n */\nexport const bedrockMantle = createBedrockMantle();\n","import {\n combineHeaders,\n normalizeHeaders,\n withUserAgentSuffix,\n getRuntimeEnvironmentUserAgent,\n type FetchFunction,\n} from '@ai-sdk/provider-utils';\nimport { AwsV4Signer } from 'aws4fetch';\nimport { VERSION } from './version';\n\nexport interface AmazonBedrockCredentials {\n region: string;\n accessKeyId: string;\n secretAccessKey: string;\n sessionToken?: string;\n}\n\n/**\n * Creates a fetch function that applies AWS Signature Version 4 signing.\n *\n * @param getCredentials - Function that returns the AWS credentials to use when signing.\n * @param fetch - Optional original fetch implementation to wrap. Defaults to global fetch.\n * @param service - The AWS service name to use for SigV4 signing scope. Defaults to 'bedrock'.\n * @returns A FetchFunction that signs requests before passing them to the underlying fetch.\n */\nexport function createSigV4FetchFunction(\n getCredentials: () =>\n | AmazonBedrockCredentials\n | PromiseLike<AmazonBedrockCredentials>,\n fetch?: FetchFunction,\n service: string = 'bedrock',\n): FetchFunction {\n return async (\n input: RequestInfo | URL,\n init?: RequestInit,\n ): Promise<Response> => {\n // avoid caching globalThis.fetch in case it is patched by other libraries\n const effectiveFetch = fetch ?? globalThis.fetch;\n const request = input instanceof Request ? input : undefined;\n const originalHeaders = combineHeaders(\n normalizeHeaders(request?.headers),\n normalizeHeaders(init?.headers),\n );\n const headersWithUserAgent = withUserAgentSuffix(\n originalHeaders,\n `ai-sdk-amazon-bedrock/${VERSION}`,\n getRuntimeEnvironmentUserAgent(),\n );\n\n let effectiveBody: BodyInit | undefined = init?.body ?? undefined;\n if (effectiveBody === undefined && request && request.body !== null) {\n try {\n effectiveBody = await request.clone().text();\n } catch {}\n }\n\n const effectiveMethod = init?.method ?? request?.method;\n\n if (effectiveMethod?.toUpperCase() !== 'POST' || !effectiveBody) {\n return effectiveFetch(input, {\n ...init,\n headers: headersWithUserAgent as HeadersInit,\n });\n }\n\n const url =\n typeof input === 'string'\n ? input\n : input instanceof URL\n ? input.href\n : input.url;\n\n const body = prepareBodyString(effectiveBody);\n const credentials = await getCredentials();\n const signer = new AwsV4Signer({\n url,\n method: 'POST',\n headers: Object.entries(headersWithUserAgent),\n body,\n region: credentials.region,\n accessKeyId: credentials.accessKeyId,\n secretAccessKey: credentials.secretAccessKey,\n sessionToken: credentials.sessionToken,\n service,\n });\n\n const signingResult = await signer.sign();\n const signedHeaders = normalizeHeaders(signingResult.headers);\n\n // Use the combined headers directly as HeadersInit\n const combinedHeaders = combineHeaders(headersWithUserAgent, signedHeaders);\n\n return effectiveFetch(input, {\n ...init,\n body,\n headers: combinedHeaders as HeadersInit,\n });\n };\n}\n\nfunction prepareBodyString(body: BodyInit | undefined): string {\n if (typeof body === 'string') {\n return body;\n } else if (body instanceof Uint8Array) {\n return new TextDecoder().decode(body);\n } else if (body instanceof ArrayBuffer) {\n return new TextDecoder().decode(new Uint8Array(body));\n } else {\n return JSON.stringify(body);\n }\n}\n\n/**\n * Creates a fetch function that applies Bearer token authentication.\n *\n * @param apiKey - The API key to use for Bearer token authentication.\n * @param fetch - Optional original fetch implementation to wrap. Defaults to global fetch.\n * @returns A FetchFunction that adds Authorization header with Bearer token to requests.\n */\nexport function createApiKeyFetchFunction(\n apiKey: string,\n fetch?: FetchFunction,\n): FetchFunction {\n return async (\n input: RequestInfo | URL,\n init?: RequestInit,\n ): Promise<Response> => {\n // avoid caching globalThis.fetch in case it is patched by other libraries\n const effectiveFetch = fetch ?? globalThis.fetch;\n const originalHeaders = normalizeHeaders(init?.headers);\n const headersWithUserAgent = withUserAgentSuffix(\n originalHeaders,\n `ai-sdk-amazon-bedrock/${VERSION}`,\n getRuntimeEnvironmentUserAgent(),\n );\n\n const finalHeaders = combineHeaders(headersWithUserAgent, {\n Authorization: `Bearer ${apiKey}`,\n });\n\n return effectiveFetch(input, {\n ...init,\n headers: finalHeaders as HeadersInit,\n });\n };\n}\n","// Version string of this package injected at build time.\ndeclare const __PACKAGE_VERSION__: string | undefined;\nexport const VERSION: string =\n typeof __PACKAGE_VERSION__ !== 'undefined'\n ? __PACKAGE_VERSION__\n : '0.0.0-test';\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,OAGK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA,uBAAAA;AAAA,OAEK;;;ACfP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,mBAAmB;;;ACLrB,IAAM,UACX,OACI,YACA;;;ADoBC,SAAS,yBACd,gBAGA,OACA,UAAkB,WACH;AACf,SAAO,OACL,OACA,SACsB;AAEtB,UAAM,iBAAiB,SAAS,WAAW;AAC3C,UAAM,UAAU,iBAAiB,UAAU,QAAQ;AACnD,UAAM,kBAAkB;AAAA,MACtB,iBAAiB,SAAS,OAAO;AAAA,MACjC,iBAAiB,MAAM,OAAO;AAAA,IAChC;AACA,UAAM,u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B,IAAI,wBAAwB,SAAS;AAAA,IACnC,UAAU;AAAA,IACV;AAAA,IACA,SAAS;AAAA,IACT,OAAO;AAAA,EACT,CAAC;AAEH,QAAM,uBAAuB,CAAC,YAC5B,IAAI,6BAA6B,SAAS;AAAA,IACxC,UAAU;AAAA,IACV;AAAA,IACA,SAAS;AAAA,IACT,OAAO;AAAA,IACP,iCAAiC;AAAA,EACnC,CAAC;AAEH,QAAM,WAAW,SAAU,SAAmC;AAC5D,QAAI,YAAY;AACd,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAEA,WAAO,gBAAgB,OAAO;AAAA,EAChC;AAEA,WAAS,uBAAuB;AAChC,WAAS,gBAAgB;AACzB,WAAS,OAAO;AAChB,WAAS,YAAY;AAErB,WAAS,iBAAiB,CAAC,YAAoB;AAC7C,UAAM,IAAI,iBAAiB,EAAE,SAAS,WAAW,iBAAiB,CAAC;AAAA,EACrE;AACA,WAAS,qBAAqB,SAAS;AACvC,WAAS,aAAa,CAAC,YAAoB;AACzC,UAAM,IAAI,iBAAiB,EAAE,SAAS,WAAW,aAAa,CAAC;AAAA,EACjE;AAEA,SAAO;AACT;AAKO,IAAM,gBAAgB,oBAAoB;","names":["withUserAgentSuffix","withUserAgentSuffix"]}
|
|
@@ -544,7 +544,7 @@ const cyberpunkAnalysis =
|
|
|
544
544
|
'... literary analysis of cyberpunk themes and concepts ...';
|
|
545
545
|
|
|
546
546
|
const result = await generateText({
|
|
547
|
-
model: amazonBedrock('us.anthropic.claude-sonnet-5'),
|
|
547
|
+
model: amazonBedrock('us.anthropic.claude-sonnet-5-5'),
|
|
548
548
|
messages: [
|
|
549
549
|
{
|
|
550
550
|
role: 'system',
|
|
@@ -580,7 +580,7 @@ const cyberpunkAnalysis =
|
|
|
580
580
|
'... literary analysis of cyberpunk themes and concepts ...';
|
|
581
581
|
|
|
582
582
|
const result = streamText({
|
|
583
|
-
model: amazonBedrock('us.anthropic.claude-sonnet-5'),
|
|
583
|
+
model: amazonBedrock('us.anthropic.claude-sonnet-5-5'),
|
|
584
584
|
messages: [
|
|
585
585
|
{
|
|
586
586
|
role: 'assistant',
|
|
@@ -1590,10 +1590,10 @@ You can use the following optional settings to customize the Bedrock Anthropic p
|
|
|
1590
1590
|
### Language Models
|
|
1591
1591
|
|
|
1592
1592
|
You can create models that call the [Anthropic Messages API](https://docs.anthropic.com/claude/reference/messages_post) using the provider instance.
|
|
1593
|
-
The first argument is the model id, e.g. `us.anthropic.claude-sonnet-5`.
|
|
1593
|
+
The first argument is the model id, e.g. `us.anthropic.claude-sonnet-5-5`.
|
|
1594
1594
|
|
|
1595
1595
|
```ts
|
|
1596
|
-
const model = bedrockAnthropic('us.anthropic.claude-sonnet-5');
|
|
1596
|
+
const model = bedrockAnthropic('us.anthropic.claude-sonnet-5-5');
|
|
1597
1597
|
```
|
|
1598
1598
|
|
|
1599
1599
|
You can use Bedrock Anthropic language models to generate text with the `generateText` function:
|
|
@@ -1603,7 +1603,7 @@ import { bedrockAnthropic } from '@ai-sdk/amazon-bedrock/anthropic';
|
|
|
1603
1603
|
import { generateText } from 'ai';
|
|
1604
1604
|
|
|
1605
1605
|
const { text } = await generateText({
|
|
1606
|
-
model: bedrockAnthropic('us.anthropic.claude-sonnet-5'),
|
|
1606
|
+
model: bedrockAnthropic('us.anthropic.claude-sonnet-5-5'),
|
|
1607
1607
|
prompt: 'Write a vegetarian lasagna recipe for 4 people.',
|
|
1608
1608
|
});
|
|
1609
1609
|
```
|
|
@@ -1627,7 +1627,7 @@ import { bedrockAnthropic } from '@ai-sdk/amazon-bedrock/anthropic';
|
|
|
1627
1627
|
import { generateText } from 'ai';
|
|
1628
1628
|
|
|
1629
1629
|
const result = await generateText({
|
|
1630
|
-
model: bedrockAnthropic('us.anthropic.claude-sonnet-5'),
|
|
1630
|
+
model: bedrockAnthropic('us.anthropic.claude-sonnet-5-5'),
|
|
1631
1631
|
messages: [
|
|
1632
1632
|
{
|
|
1633
1633
|
role: 'system',
|
|
@@ -1756,6 +1756,7 @@ const result = await generateText({
|
|
|
1756
1756
|
Anthropic has reasoning support for Claude 3.7 and Claude 4 models on Bedrock, including:
|
|
1757
1757
|
|
|
1758
1758
|
- `us.anthropic.claude-fable-5-1`
|
|
1759
|
+
- `us.anthropic.claude-sonnet-5-5`
|
|
1759
1760
|
- `us.anthropic.claude-sonnet-5`
|
|
1760
1761
|
- `us.anthropic.claude-fable-5`
|
|
1761
1762
|
- `us.anthropic.claude-opus-4-8`
|
|
@@ -1802,6 +1803,7 @@ on how to integrate reasoning into your chatbot.
|
|
|
1802
1803
|
| Model | Image Input | Object Generation | Tool Usage | Computer Use | Reasoning |
|
|
1803
1804
|
| ---------------------------------------------- | ----------- | ----------------- | ---------- | ------------ | --------- |
|
|
1804
1805
|
| `us.anthropic.claude-fable-5-1` | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> |
|
|
1806
|
+
| `us.anthropic.claude-sonnet-5-5` | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> |
|
|
1805
1807
|
| `us.anthropic.claude-sonnet-5` | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> |
|
|
1806
1808
|
| `us.anthropic.claude-fable-5` | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> |
|
|
1807
1809
|
| `us.anthropic.claude-opus-4-8` | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/amazon-bedrock",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.100",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -41,10 +41,10 @@
|
|
|
41
41
|
}
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@ai-sdk/anthropic": "4.0.
|
|
45
|
-
"@ai-sdk/openai": "4.0.
|
|
44
|
+
"@ai-sdk/anthropic": "4.0.68",
|
|
45
|
+
"@ai-sdk/openai": "4.0.80",
|
|
46
46
|
"@ai-sdk/provider": "4.0.19",
|
|
47
|
-
"@ai-sdk/provider-utils": "5.0.
|
|
47
|
+
"@ai-sdk/provider-utils": "5.0.51",
|
|
48
48
|
"@smithy/eventstream-codec": "^4.3.3",
|
|
49
49
|
"@smithy/util-utf8": "^4.3.3",
|
|
50
50
|
"aws4fetch": "^1.0.20"
|
|
@@ -8,6 +8,7 @@ export type AmazonBedrockChatModelId =
|
|
|
8
8
|
| 'anthropic.claude-v2:1'
|
|
9
9
|
| 'anthropic.claude-instant-v1'
|
|
10
10
|
| 'anthropic.claude-sonnet-5'
|
|
11
|
+
| 'anthropic.claude-sonnet-5-5'
|
|
11
12
|
| 'anthropic.claude-fable-5'
|
|
12
13
|
| 'anthropic.claude-fable-5-1'
|
|
13
14
|
| 'anthropic.claude-opus-5'
|
|
@@ -62,6 +63,7 @@ export type AmazonBedrockChatModelId =
|
|
|
62
63
|
| 'us.anthropic.claude-3-5-sonnet-20241022-v2:0'
|
|
63
64
|
| 'us.anthropic.claude-3-7-sonnet-20250219-v1:0'
|
|
64
65
|
| 'us.anthropic.claude-sonnet-5'
|
|
66
|
+
| 'us.anthropic.claude-sonnet-5-5'
|
|
65
67
|
| 'us.anthropic.claude-fable-5'
|
|
66
68
|
| 'us.anthropic.claude-fable-5-1'
|
|
67
69
|
| 'us.anthropic.claude-opus-5'
|
|
@@ -291,7 +291,7 @@ export function createAmazonBedrock(
|
|
|
291
291
|
|
|
292
292
|
const getHeaders = () => {
|
|
293
293
|
const baseHeaders = options.headers ?? {};
|
|
294
|
-
return withUserAgentSuffix(baseHeaders, `ai-sdk
|
|
294
|
+
return withUserAgentSuffix(baseHeaders, `ai-sdk-amazon-bedrock/${VERSION}`);
|
|
295
295
|
};
|
|
296
296
|
|
|
297
297
|
const getAmazonBedrockRuntimeBaseUrl = (): string =>
|
|
@@ -43,7 +43,7 @@ export function createSigV4FetchFunction(
|
|
|
43
43
|
);
|
|
44
44
|
const headersWithUserAgent = withUserAgentSuffix(
|
|
45
45
|
originalHeaders,
|
|
46
|
-
`ai-sdk
|
|
46
|
+
`ai-sdk-amazon-bedrock/${VERSION}`,
|
|
47
47
|
getRuntimeEnvironmentUserAgent(),
|
|
48
48
|
);
|
|
49
49
|
|
|
@@ -130,7 +130,7 @@ export function createApiKeyFetchFunction(
|
|
|
130
130
|
const originalHeaders = normalizeHeaders(init?.headers);
|
|
131
131
|
const headersWithUserAgent = withUserAgentSuffix(
|
|
132
132
|
originalHeaders,
|
|
133
|
-
`ai-sdk
|
|
133
|
+
`ai-sdk-amazon-bedrock/${VERSION}`,
|
|
134
134
|
getRuntimeEnvironmentUserAgent(),
|
|
135
135
|
);
|
|
136
136
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export type AmazonBedrockAnthropicModelId =
|
|
2
2
|
| 'anthropic.claude-sonnet-5'
|
|
3
|
+
| 'anthropic.claude-sonnet-5-5'
|
|
3
4
|
| 'anthropic.claude-fable-5'
|
|
4
5
|
| 'anthropic.claude-fable-5-1'
|
|
5
6
|
| 'anthropic.claude-opus-5'
|
|
@@ -22,6 +23,7 @@ export type AmazonBedrockAnthropicModelId =
|
|
|
22
23
|
| 'anthropic.claude-3-sonnet-20240229-v1:0'
|
|
23
24
|
| 'anthropic.claude-3-haiku-20240307-v1:0'
|
|
24
25
|
| 'us.anthropic.claude-sonnet-5'
|
|
26
|
+
| 'us.anthropic.claude-sonnet-5-5'
|
|
25
27
|
| 'us.anthropic.claude-fable-5'
|
|
26
28
|
| 'us.anthropic.claude-fable-5-1'
|
|
27
29
|
| 'us.anthropic.claude-opus-5'
|
|
@@ -255,7 +255,7 @@ export function createAmazonBedrockAnthropic(
|
|
|
255
255
|
|
|
256
256
|
const getHeaders = async () => {
|
|
257
257
|
const baseHeaders = (await resolve(options.headers)) ?? {};
|
|
258
|
-
return withUserAgentSuffix(baseHeaders, `ai-sdk
|
|
258
|
+
return withUserAgentSuffix(baseHeaders, `ai-sdk-amazon-bedrock/${VERSION}`);
|
|
259
259
|
};
|
|
260
260
|
|
|
261
261
|
const createChatModel = (modelId: AmazonBedrockAnthropicModelId) =>
|
|
@@ -234,7 +234,7 @@ export function createBedrockMantle(
|
|
|
234
234
|
const getHeaders = (): Record<string, string | undefined> =>
|
|
235
235
|
withUserAgentSuffix(
|
|
236
236
|
options.headers ?? {},
|
|
237
|
-
`ai-sdk
|
|
237
|
+
`ai-sdk-amazon-bedrock/${VERSION}`,
|
|
238
238
|
);
|
|
239
239
|
|
|
240
240
|
const url = ({ path, modelId }: { path: string; modelId: string }): string =>
|