@ai-sdk/amazon-bedrock 4.0.111 → 4.0.112

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.
@@ -0,0 +1,240 @@
1
+ // src/mantle/bedrock-mantle-provider.ts
2
+ import {
3
+ OpenAIChatLanguageModel,
4
+ OpenAIResponsesLanguageModel
5
+ } from "@ai-sdk/openai/internal";
6
+ import {
7
+ NoSuchModelError
8
+ } from "@ai-sdk/provider";
9
+ import {
10
+ loadOptionalSetting,
11
+ loadSetting,
12
+ withoutTrailingSlash,
13
+ withUserAgentSuffix as withUserAgentSuffix2
14
+ } from "@ai-sdk/provider-utils";
15
+
16
+ // src/bedrock-sigv4-fetch.ts
17
+ import {
18
+ combineHeaders,
19
+ normalizeHeaders,
20
+ withUserAgentSuffix,
21
+ getRuntimeEnvironmentUserAgent
22
+ } from "@ai-sdk/provider-utils";
23
+ import { AwsV4Signer } from "aws4fetch";
24
+
25
+ // src/version.ts
26
+ var VERSION = true ? "4.0.112" : "0.0.0-test";
27
+
28
+ // src/bedrock-sigv4-fetch.ts
29
+ function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {
30
+ return async (input, init) => {
31
+ var _a, _b;
32
+ const effectiveFetch = fetch != null ? fetch : globalThis.fetch;
33
+ const request = input instanceof Request ? input : void 0;
34
+ const originalHeaders = combineHeaders(
35
+ normalizeHeaders(request == null ? void 0 : request.headers),
36
+ normalizeHeaders(init == null ? void 0 : init.headers)
37
+ );
38
+ const headersWithUserAgent = withUserAgentSuffix(
39
+ originalHeaders,
40
+ `ai-sdk/amazon-bedrock/${VERSION}`,
41
+ getRuntimeEnvironmentUserAgent()
42
+ );
43
+ let effectiveBody = (_a = init == null ? void 0 : init.body) != null ? _a : void 0;
44
+ if (effectiveBody === void 0 && request && request.body !== null) {
45
+ try {
46
+ effectiveBody = await request.clone().text();
47
+ } catch (e) {
48
+ }
49
+ }
50
+ const effectiveMethod = (_b = init == null ? void 0 : init.method) != null ? _b : request == null ? void 0 : request.method;
51
+ if ((effectiveMethod == null ? void 0 : effectiveMethod.toUpperCase()) !== "POST" || !effectiveBody) {
52
+ return effectiveFetch(input, {
53
+ ...init,
54
+ headers: headersWithUserAgent
55
+ });
56
+ }
57
+ const url = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
58
+ const body = prepareBodyString(effectiveBody);
59
+ const credentials = await getCredentials();
60
+ const signer = new AwsV4Signer({
61
+ url,
62
+ method: "POST",
63
+ headers: Object.entries(headersWithUserAgent),
64
+ body,
65
+ region: credentials.region,
66
+ accessKeyId: credentials.accessKeyId,
67
+ secretAccessKey: credentials.secretAccessKey,
68
+ sessionToken: credentials.sessionToken,
69
+ service
70
+ });
71
+ const signingResult = await signer.sign();
72
+ const signedHeaders = normalizeHeaders(signingResult.headers);
73
+ const combinedHeaders = combineHeaders(headersWithUserAgent, signedHeaders);
74
+ return effectiveFetch(input, {
75
+ ...init,
76
+ body,
77
+ headers: combinedHeaders
78
+ });
79
+ };
80
+ }
81
+ function prepareBodyString(body) {
82
+ if (typeof body === "string") {
83
+ return body;
84
+ } else if (body instanceof Uint8Array) {
85
+ return new TextDecoder().decode(body);
86
+ } else if (body instanceof ArrayBuffer) {
87
+ return new TextDecoder().decode(new Uint8Array(body));
88
+ } else {
89
+ return JSON.stringify(body);
90
+ }
91
+ }
92
+ function createApiKeyFetchFunction(apiKey, fetch) {
93
+ return async (input, init) => {
94
+ const effectiveFetch = fetch != null ? fetch : globalThis.fetch;
95
+ const originalHeaders = normalizeHeaders(init == null ? void 0 : init.headers);
96
+ const headersWithUserAgent = withUserAgentSuffix(
97
+ originalHeaders,
98
+ `ai-sdk/amazon-bedrock/${VERSION}`,
99
+ getRuntimeEnvironmentUserAgent()
100
+ );
101
+ const finalHeaders = combineHeaders(headersWithUserAgent, {
102
+ Authorization: `Bearer ${apiKey}`
103
+ });
104
+ return effectiveFetch(input, {
105
+ ...init,
106
+ headers: finalHeaders
107
+ });
108
+ };
109
+ }
110
+
111
+ // src/mantle/bedrock-mantle-provider.ts
112
+ function createBedrockMantle(options = {}) {
113
+ const rawApiKey = loadOptionalSetting({
114
+ settingValue: options.apiKey,
115
+ environmentVariableName: "AWS_BEARER_TOKEN_BEDROCK"
116
+ });
117
+ const apiKey = rawApiKey && rawApiKey.trim().length > 0 ? rawApiKey.trim() : void 0;
118
+ const fetchFunction = apiKey ? createApiKeyFetchFunction(apiKey, options.fetch) : createSigV4FetchFunction(
119
+ async () => {
120
+ const region = loadSetting({
121
+ settingValue: options.region,
122
+ settingName: "region",
123
+ environmentVariableName: "AWS_REGION",
124
+ description: "AWS region"
125
+ });
126
+ if (options.credentialProvider) {
127
+ try {
128
+ return {
129
+ ...await options.credentialProvider(),
130
+ region
131
+ };
132
+ } catch (error) {
133
+ const errorMessage = error instanceof Error ? error.message : String(error);
134
+ throw new Error(
135
+ `AWS credential provider failed: ${errorMessage}. Please ensure your credential provider returns valid AWS credentials with accessKeyId and secretAccessKey properties.`
136
+ );
137
+ }
138
+ }
139
+ try {
140
+ return {
141
+ region,
142
+ accessKeyId: loadSetting({
143
+ settingValue: options.accessKeyId,
144
+ settingName: "accessKeyId",
145
+ environmentVariableName: "AWS_ACCESS_KEY_ID",
146
+ description: "AWS access key ID"
147
+ }),
148
+ secretAccessKey: loadSetting({
149
+ settingValue: options.secretAccessKey,
150
+ settingName: "secretAccessKey",
151
+ environmentVariableName: "AWS_SECRET_ACCESS_KEY",
152
+ description: "AWS secret access key"
153
+ }),
154
+ sessionToken: loadOptionalSetting({
155
+ settingValue: options.sessionToken,
156
+ environmentVariableName: "AWS_SESSION_TOKEN"
157
+ })
158
+ };
159
+ } catch (error) {
160
+ const errorMessage = error instanceof Error ? error.message : String(error);
161
+ if (errorMessage.includes("AWS_ACCESS_KEY_ID") || errorMessage.includes("accessKeyId")) {
162
+ throw new Error(
163
+ `AWS SigV4 authentication requires AWS credentials. Please provide either:
164
+ 1. Set AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables
165
+ 2. Provide accessKeyId and secretAccessKey in options
166
+ 3. Use a credentialProvider function
167
+ 4. Use API key authentication with AWS_BEARER_TOKEN_BEDROCK or apiKey option
168
+ Original error: ${errorMessage}`
169
+ );
170
+ }
171
+ if (errorMessage.includes("AWS_SECRET_ACCESS_KEY") || errorMessage.includes("secretAccessKey")) {
172
+ throw new Error(
173
+ `AWS SigV4 authentication requires both AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY. Please ensure both credentials are provided.
174
+ Original error: ${errorMessage}`
175
+ );
176
+ }
177
+ throw error;
178
+ }
179
+ },
180
+ options.fetch,
181
+ "bedrock-mantle"
182
+ );
183
+ const getBaseURL = () => {
184
+ var _a, _b;
185
+ return (_b = withoutTrailingSlash(
186
+ (_a = options.baseURL) != null ? _a : `https://bedrock-mantle.${loadSetting({
187
+ settingValue: options.region,
188
+ settingName: "region",
189
+ environmentVariableName: "AWS_REGION",
190
+ description: "AWS region"
191
+ })}.api.aws/v1`
192
+ )) != null ? _b : "https://bedrock-mantle.us-east-1.api.aws/v1";
193
+ };
194
+ const getHeaders = () => {
195
+ var _a;
196
+ return withUserAgentSuffix2(
197
+ (_a = options.headers) != null ? _a : {},
198
+ `ai-sdk/amazon-bedrock/${VERSION}`
199
+ );
200
+ };
201
+ const url = ({ path }) => `${getBaseURL()}${path}`;
202
+ const createChatModel = (modelId) => new OpenAIChatLanguageModel(modelId, {
203
+ provider: "bedrock-mantle.chat",
204
+ url,
205
+ headers: getHeaders,
206
+ fetch: fetchFunction
207
+ });
208
+ const createResponsesModel = (modelId) => new OpenAIResponsesLanguageModel(modelId, {
209
+ provider: "bedrock-mantle.responses",
210
+ url,
211
+ headers: getHeaders,
212
+ fetch: fetchFunction
213
+ });
214
+ const provider = function(modelId) {
215
+ if (new.target) {
216
+ throw new Error(
217
+ "The Bedrock Mantle model function cannot be called with the new keyword."
218
+ );
219
+ }
220
+ return createChatModel(modelId);
221
+ };
222
+ provider.specificationVersion = "v3";
223
+ provider.languageModel = createChatModel;
224
+ provider.chat = createChatModel;
225
+ provider.responses = createResponsesModel;
226
+ provider.embeddingModel = (modelId) => {
227
+ throw new NoSuchModelError({ modelId, modelType: "embeddingModel" });
228
+ };
229
+ provider.textEmbeddingModel = provider.embeddingModel;
230
+ provider.imageModel = (modelId) => {
231
+ throw new NoSuchModelError({ modelId, modelType: "imageModel" });
232
+ };
233
+ return provider;
234
+ }
235
+ var bedrockMantle = createBedrockMantle();
236
+ export {
237
+ bedrockMantle,
238
+ createBedrockMantle
239
+ };
240
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/mantle/bedrock-mantle-provider.ts","../../src/bedrock-sigv4-fetch.ts","../../src/version.ts"],"sourcesContent":["import {\n OpenAIChatLanguageModel,\n OpenAIResponsesLanguageModel,\n} from '@ai-sdk/openai/internal';\nimport {\n NoSuchModelError,\n type LanguageModelV3,\n type ProviderV3,\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 BedrockCredentials,\n} from '../bedrock-sigv4-fetch';\nimport type {\n BedrockMantleChatModelId,\n BedrockMantleResponsesModelId,\n} from './bedrock-mantle-options';\nimport { VERSION } from '../version';\n\nexport interface BedrockMantleProvider extends ProviderV3 {\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): LanguageModelV3;\n\n /**\n * Creates a model for text generation using the Chat Completions API.\n */\n languageModel(modelId: BedrockMantleChatModelId): LanguageModelV3;\n\n /**\n * Creates a model for text generation using the Chat Completions API.\n */\n chat(modelId: BedrockMantleChatModelId): LanguageModelV3;\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): LanguageModelV3;\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<Omit<BedrockCredentials, 'region'>>;\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 = (): 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/v1`,\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 }: { path: string; modelId: string }): string =>\n `${getBaseURL()}${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 });\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 = 'v3' 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 BedrockCredentials {\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: () => BedrockCredentials | PromiseLike<BedrockCredentials>,\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__ !== 'undef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,aAAa,CAAC;AAAA,EACjE;AAEA,SAAO;AACT;AAKO,IAAM,gBAAgB,oBAAoB;","names":["withUserAgentSuffix","withUserAgentSuffix"]}
@@ -1641,6 +1641,163 @@ on how to integrate reasoning into your chatbot.
1641
1641
  Connector which are not supported on Bedrock.
1642
1642
  </Note>
1643
1643
 
1644
+ ## Bedrock Mantle Provider Usage
1645
+
1646
+ The Bedrock Mantle provider offers access to OpenAI-compatible models through Amazon Bedrock's Mantle API at `https://bedrock-mantle.{region}.api.aws/v1`. This endpoint supports the Chat Completions API and the Responses API, and provides access to models that may only be available through the Mantle endpoint (such as `openai.gpt-oss-120b`).
1647
+
1648
+ ### Provider Instance
1649
+
1650
+ You can import the default provider instance `bedrockMantle` from `@ai-sdk/amazon-bedrock/mantle`:
1651
+
1652
+ ```typescript
1653
+ import { bedrockMantle } from '@ai-sdk/amazon-bedrock/mantle';
1654
+ ```
1655
+
1656
+ If you need a customized setup, you can import `createBedrockMantle` from `@ai-sdk/amazon-bedrock/mantle` and create a provider instance with your settings:
1657
+
1658
+ ```typescript
1659
+ import { createBedrockMantle } from '@ai-sdk/amazon-bedrock/mantle';
1660
+
1661
+ const bedrockMantle = createBedrockMantle({
1662
+ region: 'us-east-1', // optional
1663
+ accessKeyId: 'xxxxxxxxx', // optional
1664
+ secretAccessKey: 'xxxxxxxxx', // optional
1665
+ sessionToken: 'xxxxxxxxx', // optional
1666
+ });
1667
+ ```
1668
+
1669
+ #### Provider Settings
1670
+
1671
+ You can use the following optional settings to customize the Bedrock Mantle provider instance:
1672
+
1673
+ - **region** _string_
1674
+
1675
+ The AWS region that you want to use for the API calls.
1676
+ It uses the `AWS_REGION` environment variable by default.
1677
+
1678
+ - **accessKeyId** _string_
1679
+
1680
+ The AWS access key ID that you want to use for the API calls.
1681
+ It uses the `AWS_ACCESS_KEY_ID` environment variable by default.
1682
+
1683
+ - **secretAccessKey** _string_
1684
+
1685
+ The AWS secret access key that you want to use for the API calls.
1686
+ It uses the `AWS_SECRET_ACCESS_KEY` environment variable by default.
1687
+
1688
+ - **sessionToken** _string_
1689
+
1690
+ Optional. The AWS session token that you want to use for the API calls.
1691
+ It uses the `AWS_SESSION_TOKEN` environment variable by default.
1692
+
1693
+ - **apiKey** _string_
1694
+
1695
+ API key for authenticating requests using Bearer token authentication.
1696
+ When provided, this will be used instead of AWS SigV4 authentication.
1697
+ It uses the `AWS_BEARER_TOKEN_BEDROCK` environment variable by default.
1698
+
1699
+ - **baseURL** _string_
1700
+
1701
+ Base URL for the Bedrock Mantle API calls.
1702
+ Defaults to `https://bedrock-mantle.{region}.api.aws/v1`.
1703
+
1704
+ - **headers** _Record&lt;string, string | undefined&gt;_
1705
+
1706
+ Headers to include in the requests.
1707
+
1708
+ - **fetch** _(input: RequestInfo, init?: RequestInit) => Promise&lt;Response&gt;_
1709
+
1710
+ Custom [fetch](https://developer.mozilla.org/en-US/docs/Web/API/fetch) implementation.
1711
+ You can use it as a middleware to intercept requests,
1712
+ or to provide a custom fetch implementation for e.g. testing.
1713
+
1714
+ - **credentialProvider** _() => PromiseLike&lt;BedrockCredentials&gt;_
1715
+
1716
+ The AWS credential provider to use for the Bedrock provider to get dynamic
1717
+ credentials similar to the AWS SDK. Setting a provider here will cause its
1718
+ credential values to be used instead of the `accessKeyId`, `secretAccessKey`,
1719
+ and `sessionToken` settings.
1720
+
1721
+ ### Language Models
1722
+
1723
+ You can create models using the Mantle provider instance. By default, the provider creates models using the Chat Completions API, which has the broadest model support on Mantle:
1724
+
1725
+ ```ts
1726
+ const model = bedrockMantle('openai.gpt-oss-120b');
1727
+ ```
1728
+
1729
+ You can also explicitly select the Chat Completions API or the Responses API:
1730
+
1731
+ ```ts
1732
+ const chatModel = bedrockMantle.chat('openai.gpt-oss-120b');
1733
+ const responsesModel = bedrockMantle.responses('openai.gpt-oss-120b');
1734
+ ```
1735
+
1736
+ Note that not all Mantle models support the Responses API. See the model capabilities table below.
1737
+
1738
+ You can use Bedrock Mantle language models to generate text with the `generateText` function:
1739
+
1740
+ ```ts
1741
+ import { bedrockMantle } from '@ai-sdk/amazon-bedrock/mantle';
1742
+ import { generateText } from 'ai';
1743
+
1744
+ const { text } = await generateText({
1745
+ model: bedrockMantle('openai.gpt-oss-120b'),
1746
+ prompt: 'Invent a new holiday and describe its traditions.',
1747
+ });
1748
+ ```
1749
+
1750
+ Or stream text with the `streamText` function:
1751
+
1752
+ ```ts
1753
+ import { bedrockMantle } from '@ai-sdk/amazon-bedrock/mantle';
1754
+ import { streamText } from 'ai';
1755
+
1756
+ const result = streamText({
1757
+ model: bedrockMantle('openai.gpt-oss-120b'),
1758
+ prompt: 'Invent a new holiday and describe its traditions.',
1759
+ });
1760
+
1761
+ for await (const textPart of result.textStream) {
1762
+ process.stdout.write(textPart);
1763
+ }
1764
+ ```
1765
+
1766
+ ### Provider Options
1767
+
1768
+ Since the Mantle API is OpenAI-compatible, provider options are passed under the `openai` namespace:
1769
+
1770
+ ```ts
1771
+ import { bedrockMantle } from '@ai-sdk/amazon-bedrock/mantle';
1772
+ import { generateText } from 'ai';
1773
+
1774
+ const { text } = await generateText({
1775
+ model: bedrockMantle('openai.gpt-oss-120b'),
1776
+ prompt: 'Hello!',
1777
+ providerOptions: {
1778
+ openai: {
1779
+ // OpenAI-compatible provider options
1780
+ },
1781
+ },
1782
+ });
1783
+ ```
1784
+
1785
+ ### Model Capabilities
1786
+
1787
+ | Model | Chat Completions | Responses API |
1788
+ | ------------------------------- | ------------------- | ------------------- |
1789
+ | `openai.gpt-oss-20b` | <Check size={18} /> | <Check size={18} /> |
1790
+ | `openai.gpt-oss-120b` | <Check size={18} /> | <Check size={18} /> |
1791
+ | `openai.gpt-oss-safeguard-20b` | <Check size={18} /> | <Cross size={18} /> |
1792
+ | `openai.gpt-oss-safeguard-120b` | <Check size={18} /> | <Cross size={18} /> |
1793
+
1794
+ <Note>
1795
+ The Bedrock Mantle provider uses the OpenAI-compatible API format. Models
1796
+ available through the Mantle endpoint may differ from those available through
1797
+ the Bedrock Converse API. Use the Mantle endpoint's model listing API to
1798
+ discover all available models.
1799
+ </Note>
1800
+
1644
1801
  ## Migrating to `@ai-sdk/amazon-bedrock` 2.x
1645
1802
 
1646
1803
  The Amazon Bedrock provider was rewritten in version 2.x to remove the
@@ -0,0 +1 @@
1
+ export * from '../dist/mantle';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/amazon-bedrock",
3
- "version": "4.0.111",
3
+ "version": "4.0.112",
4
4
  "license": "Apache-2.0",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.js",
@@ -16,7 +16,8 @@
16
16
  "!src/**/__fixtures__",
17
17
  "CHANGELOG.md",
18
18
  "README.md",
19
- "anthropic/index.d.ts"
19
+ "anthropic/index.d.ts",
20
+ "mantle/index.d.ts"
20
21
  ],
21
22
  "directories": {
22
23
  "doc": "./docs"
@@ -32,6 +33,11 @@
32
33
  "types": "./dist/anthropic/index.d.ts",
33
34
  "import": "./dist/anthropic/index.mjs",
34
35
  "require": "./dist/anthropic/index.js"
36
+ },
37
+ "./mantle": {
38
+ "types": "./dist/mantle/index.d.ts",
39
+ "import": "./dist/mantle/index.mjs",
40
+ "require": "./dist/mantle/index.js"
35
41
  }
36
42
  },
37
43
  "dependencies": {
@@ -40,7 +46,8 @@
40
46
  "aws4fetch": "^1.0.20",
41
47
  "@ai-sdk/anthropic": "3.0.81",
42
48
  "@ai-sdk/provider": "3.0.10",
43
- "@ai-sdk/provider-utils": "4.0.27"
49
+ "@ai-sdk/provider-utils": "4.0.27",
50
+ "@ai-sdk/openai": "3.0.67"
44
51
  },
45
52
  "devDependencies": {
46
53
  "@types/node": "20.17.24",
@@ -20,11 +20,13 @@ export interface BedrockCredentials {
20
20
  *
21
21
  * @param getCredentials - Function that returns the AWS credentials to use when signing.
22
22
  * @param fetch - Optional original fetch implementation to wrap. Defaults to global fetch.
23
+ * @param service - The AWS service name to use for SigV4 signing scope. Defaults to 'bedrock'.
23
24
  * @returns A FetchFunction that signs requests before passing them to the underlying fetch.
24
25
  */
25
26
  export function createSigV4FetchFunction(
26
27
  getCredentials: () => BedrockCredentials | PromiseLike<BedrockCredentials>,
27
28
  fetch?: FetchFunction,
29
+ service: string = 'bedrock',
28
30
  ): FetchFunction {
29
31
  return async (
30
32
  input: RequestInfo | URL,
@@ -77,7 +79,7 @@ export function createSigV4FetchFunction(
77
79
  accessKeyId: credentials.accessKeyId,
78
80
  secretAccessKey: credentials.secretAccessKey,
79
81
  sessionToken: credentials.sessionToken,
80
- service: 'bedrock',
82
+ service,
81
83
  });
82
84
 
83
85
  const signingResult = await signer.sign();
@@ -0,0 +1,15 @@
1
+ export type BedrockMantleChatModelId =
2
+ | 'openai.gpt-oss-20b'
3
+ | 'openai.gpt-oss-120b'
4
+ | 'openai.gpt-oss-safeguard-20b'
5
+ | 'openai.gpt-oss-safeguard-120b'
6
+ | (string & {});
7
+
8
+ export type BedrockMantleResponsesModelId =
9
+ | 'openai.gpt-oss-20b'
10
+ | 'openai.gpt-oss-120b'
11
+ | (string & {});
12
+
13
+ export type BedrockMantleModelId =
14
+ | BedrockMantleChatModelId
15
+ | BedrockMantleResponsesModelId;