@ai-sdk/amazon-bedrock 5.0.0-beta.4 → 5.0.0-beta.41

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 CHANGED
@@ -1,5 +1,322 @@
1
1
  # @ai-sdk/amazon-bedrock
2
2
 
3
+ ## 5.0.0-beta.41
4
+
5
+ ### Patch Changes
6
+
7
+ - ed60b47: fix(provider/amazon-bedrock): fix Anthropic reasoning behavior related to Opus 4.7
8
+ - Updated dependencies [2e98477]
9
+ - @ai-sdk/provider-utils@5.0.0-beta.26
10
+ - @ai-sdk/anthropic@4.0.0-beta.37
11
+
12
+ ## 5.0.0-beta.40
13
+
14
+ ### Patch Changes
15
+
16
+ - Updated dependencies [eea8d98]
17
+ - @ai-sdk/provider-utils@5.0.0-beta.25
18
+ - @ai-sdk/anthropic@4.0.0-beta.36
19
+
20
+ ## 5.0.0-beta.39
21
+
22
+ ### Patch Changes
23
+
24
+ - Updated dependencies [f807e45]
25
+ - @ai-sdk/provider-utils@5.0.0-beta.24
26
+ - @ai-sdk/anthropic@4.0.0-beta.35
27
+
28
+ ## 5.0.0-beta.38
29
+
30
+ ### Patch Changes
31
+
32
+ - Updated dependencies [350ea38]
33
+ - @ai-sdk/provider-utils@5.0.0-beta.23
34
+ - @ai-sdk/anthropic@4.0.0-beta.34
35
+
36
+ ## 5.0.0-beta.37
37
+
38
+ ### Patch Changes
39
+
40
+ - Updated dependencies [832f86f]
41
+ - @ai-sdk/anthropic@4.0.0-beta.33
42
+
43
+ ## 5.0.0-beta.36
44
+
45
+ ### Patch Changes
46
+
47
+ - Updated dependencies [ad0b376]
48
+ - @ai-sdk/anthropic@4.0.0-beta.32
49
+
50
+ ## 5.0.0-beta.35
51
+
52
+ ### Patch Changes
53
+
54
+ - Updated dependencies [083947b]
55
+ - @ai-sdk/provider-utils@5.0.0-beta.22
56
+ - @ai-sdk/anthropic@4.0.0-beta.31
57
+
58
+ ## 5.0.0-beta.34
59
+
60
+ ### Patch Changes
61
+
62
+ - 0d8f107: feat(provider/anthropic): add support for Opus 4.7 and relevant API enhancements
63
+ - Updated dependencies [0d8f107]
64
+ - @ai-sdk/anthropic@4.0.0-beta.30
65
+
66
+ ## 5.0.0-beta.33
67
+
68
+ ### Patch Changes
69
+
70
+ - Updated dependencies [add1126]
71
+ - @ai-sdk/provider-utils@5.0.0-beta.21
72
+ - @ai-sdk/anthropic@4.0.0-beta.29
73
+
74
+ ## 5.0.0-beta.32
75
+
76
+ ### Patch Changes
77
+
78
+ - b3976a2: Add workflow serialization support to all provider models.
79
+
80
+ **`@ai-sdk/provider-utils`:** New `serializeModel()` helper that extracts only serializable properties from a model instance, filtering out functions and objects containing functions. Third-party provider authors can use this to add workflow support to their own models.
81
+
82
+ **All providers:** `headers` is now optional in provider config types. This is non-breaking — existing code that passes `headers` continues to work. Custom provider implementations that construct model configs manually can now omit `headers`, which is useful when models are deserialized from a workflow step boundary where auth is provided separately.
83
+
84
+ All provider model classes now include `WORKFLOW_SERIALIZE` and `WORKFLOW_DESERIALIZE` static methods, enabling them to cross workflow step boundaries without serialization errors.
85
+
86
+ - ff5eba1: feat: roll `image-*` tool output types into their equivalent `file-*` types
87
+ - Updated dependencies [b3976a2]
88
+ - Updated dependencies [ff5eba1]
89
+ - @ai-sdk/provider-utils@5.0.0-beta.20
90
+ - @ai-sdk/anthropic@4.0.0-beta.28
91
+ - @ai-sdk/provider@4.0.0-beta.12
92
+
93
+ ## 5.0.0-beta.31
94
+
95
+ ### Major Changes
96
+
97
+ - ef992f8: Remove CommonJS exports from all packages. All packages are now ESM-only (`"type": "module"`). Consumers using `require()` must switch to ESM `import` syntax.
98
+
99
+ ### Patch Changes
100
+
101
+ - Updated dependencies [ef992f8]
102
+ - @ai-sdk/anthropic@4.0.0-beta.27
103
+ - @ai-sdk/provider@4.0.0-beta.11
104
+ - @ai-sdk/provider-utils@5.0.0-beta.19
105
+
106
+ ## 5.0.0-beta.30
107
+
108
+ ### Patch Changes
109
+
110
+ - 90e2d8a: chore: fix unused vars not being flagged by our lint tooling
111
+ - Updated dependencies [90e2d8a]
112
+ - @ai-sdk/provider-utils@5.0.0-beta.18
113
+ - @ai-sdk/anthropic@4.0.0-beta.26
114
+
115
+ ## 5.0.0-beta.29
116
+
117
+ ### Patch Changes
118
+
119
+ - Updated dependencies [09bd27b]
120
+ - @ai-sdk/anthropic@4.0.0-beta.25
121
+
122
+ ## 5.0.0-beta.28
123
+
124
+ ### Patch Changes
125
+
126
+ - Updated dependencies [3ae1786]
127
+ - @ai-sdk/provider-utils@5.0.0-beta.17
128
+ - @ai-sdk/anthropic@4.0.0-beta.24
129
+
130
+ ## 5.0.0-beta.27
131
+
132
+ ### Patch Changes
133
+
134
+ - Updated dependencies [176466a]
135
+ - @ai-sdk/provider@4.0.0-beta.10
136
+ - @ai-sdk/anthropic@4.0.0-beta.23
137
+ - @ai-sdk/provider-utils@5.0.0-beta.16
138
+
139
+ ## 5.0.0-beta.26
140
+
141
+ ### Patch Changes
142
+
143
+ - Updated dependencies [e311194]
144
+ - @ai-sdk/provider@4.0.0-beta.9
145
+ - @ai-sdk/anthropic@4.0.0-beta.22
146
+ - @ai-sdk/provider-utils@5.0.0-beta.15
147
+
148
+ ## 5.0.0-beta.25
149
+
150
+ ### Patch Changes
151
+
152
+ - 24ac76f: fix(amazon-bedrock): preserve empty text blocks when reasoning content is present
153
+ - cdc15f3: feat(bedrock): support native structured output for anthropic models without reasoning
154
+ - Updated dependencies [34bd95d]
155
+ - Updated dependencies [008271d]
156
+ - @ai-sdk/anthropic@4.0.0-beta.21
157
+ - @ai-sdk/provider@4.0.0-beta.8
158
+ - @ai-sdk/provider-utils@5.0.0-beta.14
159
+
160
+ ## 5.0.0-beta.24
161
+
162
+ ### Patch Changes
163
+
164
+ - Updated dependencies [b0c2869]
165
+ - Updated dependencies [7e26e81]
166
+ - @ai-sdk/provider-utils@5.0.0-beta.13
167
+ - @ai-sdk/anthropic@4.0.0-beta.20
168
+
169
+ ## 5.0.0-beta.23
170
+
171
+ ### Patch Changes
172
+
173
+ - Updated dependencies [46d1149]
174
+ - @ai-sdk/provider-utils@5.0.0-beta.12
175
+ - @ai-sdk/anthropic@4.0.0-beta.19
176
+
177
+ ## 5.0.0-beta.22
178
+
179
+ ### Patch Changes
180
+
181
+ - Updated dependencies [6fd51c0]
182
+ - @ai-sdk/provider-utils@5.0.0-beta.11
183
+ - @ai-sdk/provider@4.0.0-beta.7
184
+ - @ai-sdk/anthropic@4.0.0-beta.18
185
+
186
+ ## 5.0.0-beta.21
187
+
188
+ ### Patch Changes
189
+
190
+ - c29a26f: feat(provider): add support for provider references and uploading files as supported per provider
191
+ - Updated dependencies [c29a26f]
192
+ - @ai-sdk/provider-utils@5.0.0-beta.10
193
+ - @ai-sdk/anthropic@4.0.0-beta.17
194
+ - @ai-sdk/provider@4.0.0-beta.6
195
+
196
+ ## 5.0.0-beta.20
197
+
198
+ ### Patch Changes
199
+
200
+ - 38fc777: Add AI Gateway hint to provider READMEs
201
+ - Updated dependencies [38fc777]
202
+ - @ai-sdk/anthropic@4.0.0-beta.16
203
+
204
+ ## 5.0.0-beta.19
205
+
206
+ ### Patch Changes
207
+
208
+ - Updated dependencies [f57c702]
209
+ - @ai-sdk/anthropic@4.0.0-beta.15
210
+
211
+ ## 5.0.0-beta.18
212
+
213
+ ### Patch Changes
214
+
215
+ - Updated dependencies [2e17091]
216
+ - @ai-sdk/provider-utils@5.0.0-beta.9
217
+ - @ai-sdk/anthropic@4.0.0-beta.14
218
+
219
+ ## 5.0.0-beta.17
220
+
221
+ ### Patch Changes
222
+
223
+ - Updated dependencies [986c6fd]
224
+ - Updated dependencies [493295c]
225
+ - @ai-sdk/provider-utils@5.0.0-beta.8
226
+ - @ai-sdk/anthropic@4.0.0-beta.13
227
+
228
+ ## 5.0.0-beta.16
229
+
230
+ ### Patch Changes
231
+
232
+ - 6d8716c: feat(bedrock): add support for service tier for model inference
233
+
234
+ ## 5.0.0-beta.15
235
+
236
+ ### Patch Changes
237
+
238
+ - 4b20a5d: fix(provider/amazon-bedrock): transform bedrock/anthropic error responses to anthropic format
239
+
240
+ ## 5.0.0-beta.14
241
+
242
+ ### Patch Changes
243
+
244
+ - b0c59e8: fix(amazon-bedrock): preserve reasoning text when signature is present
245
+
246
+ ## 5.0.0-beta.13
247
+
248
+ ### Patch Changes
249
+
250
+ - 1921625: fix(provider/amazon-bedrock): add tool search beta for Anthropic
251
+
252
+ ## 5.0.0-beta.12
253
+
254
+ ### Patch Changes
255
+
256
+ - Updated dependencies [1f509d4]
257
+ - @ai-sdk/provider-utils@5.0.0-beta.7
258
+ - @ai-sdk/provider@4.0.0-beta.5
259
+ - @ai-sdk/anthropic@4.0.0-beta.12
260
+
261
+ ## 5.0.0-beta.11
262
+
263
+ ### Patch Changes
264
+
265
+ - Updated dependencies [0ee8aec]
266
+ - @ai-sdk/anthropic@4.0.0-beta.11
267
+
268
+ ## 5.0.0-beta.10
269
+
270
+ ### Patch Changes
271
+
272
+ - 3887c70: feat(provider): add new top-level reasoning parameter to spec and support it in `generateText` and `streamText`
273
+ - Updated dependencies [3887c70]
274
+ - @ai-sdk/provider-utils@5.0.0-beta.6
275
+ - @ai-sdk/anthropic@4.0.0-beta.10
276
+ - @ai-sdk/provider@4.0.0-beta.4
277
+
278
+ ## 5.0.0-beta.9
279
+
280
+ ### Patch Changes
281
+
282
+ - Updated dependencies [776b617]
283
+ - @ai-sdk/provider-utils@5.0.0-beta.5
284
+ - @ai-sdk/provider@4.0.0-beta.3
285
+ - @ai-sdk/anthropic@4.0.0-beta.9
286
+
287
+ ## 5.0.0-beta.8
288
+
289
+ ### Patch Changes
290
+
291
+ - Updated dependencies [61753c3]
292
+ - @ai-sdk/provider-utils@5.0.0-beta.4
293
+ - @ai-sdk/anthropic@4.0.0-beta.8
294
+
295
+ ## 5.0.0-beta.7
296
+
297
+ ### Patch Changes
298
+
299
+ - Updated dependencies [f7d4f01]
300
+ - @ai-sdk/provider-utils@5.0.0-beta.3
301
+ - @ai-sdk/provider@4.0.0-beta.2
302
+ - @ai-sdk/anthropic@4.0.0-beta.7
303
+
304
+ ## 5.0.0-beta.6
305
+
306
+ ### Patch Changes
307
+
308
+ - Updated dependencies [21d1ee3]
309
+ - @ai-sdk/anthropic@4.0.0-beta.6
310
+
311
+ ## 5.0.0-beta.5
312
+
313
+ ### Patch Changes
314
+
315
+ - Updated dependencies [5c2a5a2]
316
+ - @ai-sdk/provider@4.0.0-beta.1
317
+ - @ai-sdk/anthropic@4.0.0-beta.5
318
+ - @ai-sdk/provider-utils@5.0.0-beta.2
319
+
3
320
  ## 5.0.0-beta.4
4
321
 
5
322
  ### Patch Changes
@@ -635,13 +952,13 @@
635
952
  Before
636
953
 
637
954
  ```ts
638
- model.textEmbeddingModel('my-model-id');
955
+ model.textEmbeddingModel("my-model-id");
639
956
  ```
640
957
 
641
958
  After
642
959
 
643
960
  ```ts
644
- model.embeddingModel('my-model-id');
961
+ model.embeddingModel("my-model-id");
645
962
  ```
646
963
 
647
964
  - 2625a04: feat(openai); update spec for mcp approval
@@ -1033,13 +1350,13 @@
1033
1350
  Before
1034
1351
 
1035
1352
  ```ts
1036
- model.textEmbeddingModel('my-model-id');
1353
+ model.textEmbeddingModel("my-model-id");
1037
1354
  ```
1038
1355
 
1039
1356
  After
1040
1357
 
1041
1358
  ```ts
1042
- model.embeddingModel('my-model-id');
1359
+ model.embeddingModel("my-model-id");
1043
1360
  ```
1044
1361
 
1045
1362
  - Updated dependencies [8d9e8ad]
package/README.md CHANGED
@@ -3,6 +3,8 @@
3
3
  The **[Amazon Bedrock provider](https://ai-sdk.dev/providers/ai-sdk-providers/amazon-bedrock)** for the [AI SDK](https://ai-sdk.dev/docs)
4
4
  contains language model support for the Amazon Bedrock [converse API](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_Converse.html).
5
5
 
6
+ > **Deploying to Vercel?** With Vercel's AI Gateway you can access Amazon Bedrock (and hundreds of models from other providers) — no additional packages, API keys, or extra cost. [Get started with AI Gateway](https://vercel.com/ai-gateway).
7
+
6
8
  ## Setup
7
9
 
8
10
  The Amazon Bedrock provider is available in the `@ai-sdk/amazon-bedrock` module. You can install it with
@@ -9,7 +9,7 @@ interface BedrockCredentials {
9
9
  sessionToken?: string;
10
10
  }
11
11
 
12
- type BedrockAnthropicModelId = 'anthropic.claude-opus-4-6-v1' | 'anthropic.claude-sonnet-4-6-v1' | 'anthropic.claude-opus-4-5-20251101-v1:0' | 'anthropic.claude-sonnet-4-5-20250929-v1:0' | 'anthropic.claude-opus-4-20250514-v1:0' | 'anthropic.claude-sonnet-4-20250514-v1:0' | 'anthropic.claude-opus-4-1-20250805-v1:0' | 'anthropic.claude-haiku-4-5-20251001-v1:0' | 'anthropic.claude-3-7-sonnet-20250219-v1:0' | 'anthropic.claude-3-5-sonnet-20241022-v2:0' | 'anthropic.claude-3-5-sonnet-20240620-v1:0' | 'anthropic.claude-3-5-haiku-20241022-v1:0' | 'anthropic.claude-3-opus-20240229-v1:0' | 'anthropic.claude-3-sonnet-20240229-v1:0' | 'anthropic.claude-3-haiku-20240307-v1:0' | 'us.anthropic.claude-opus-4-6-v1' | 'us.anthropic.claude-sonnet-4-6-v1' | 'us.anthropic.claude-opus-4-5-20251101-v1:0' | 'us.anthropic.claude-sonnet-4-5-20250929-v1:0' | 'us.anthropic.claude-opus-4-20250514-v1:0' | 'us.anthropic.claude-sonnet-4-20250514-v1:0' | 'us.anthropic.claude-opus-4-1-20250805-v1:0' | 'us.anthropic.claude-haiku-4-5-20251001-v1:0' | 'us.anthropic.claude-3-7-sonnet-20250219-v1:0' | 'us.anthropic.claude-3-5-sonnet-20241022-v2:0' | 'us.anthropic.claude-3-5-sonnet-20240620-v1:0' | 'us.anthropic.claude-3-5-haiku-20241022-v1:0' | 'us.anthropic.claude-3-opus-20240229-v1:0' | 'us.anthropic.claude-3-sonnet-20240229-v1:0' | 'us.anthropic.claude-3-haiku-20240307-v1:0' | (string & {});
12
+ type BedrockAnthropicModelId = 'anthropic.claude-opus-4-7' | 'anthropic.claude-opus-4-6-v1' | 'anthropic.claude-sonnet-4-6-v1' | 'anthropic.claude-opus-4-5-20251101-v1:0' | 'anthropic.claude-sonnet-4-5-20250929-v1:0' | 'anthropic.claude-opus-4-20250514-v1:0' | 'anthropic.claude-sonnet-4-20250514-v1:0' | 'anthropic.claude-opus-4-1-20250805-v1:0' | 'anthropic.claude-haiku-4-5-20251001-v1:0' | 'anthropic.claude-3-7-sonnet-20250219-v1:0' | 'anthropic.claude-3-5-sonnet-20241022-v2:0' | 'anthropic.claude-3-5-sonnet-20240620-v1:0' | 'anthropic.claude-3-5-haiku-20241022-v1:0' | 'anthropic.claude-3-opus-20240229-v1:0' | 'anthropic.claude-3-sonnet-20240229-v1:0' | 'anthropic.claude-3-haiku-20240307-v1:0' | 'us.anthropic.claude-opus-4-7' | 'us.anthropic.claude-opus-4-6-v1' | 'us.anthropic.claude-sonnet-4-6-v1' | 'us.anthropic.claude-opus-4-5-20251101-v1:0' | 'us.anthropic.claude-sonnet-4-5-20250929-v1:0' | 'us.anthropic.claude-opus-4-20250514-v1:0' | 'us.anthropic.claude-sonnet-4-20250514-v1:0' | 'us.anthropic.claude-opus-4-1-20250805-v1:0' | 'us.anthropic.claude-haiku-4-5-20251001-v1:0' | 'us.anthropic.claude-3-7-sonnet-20250219-v1:0' | 'us.anthropic.claude-3-5-sonnet-20241022-v2:0' | 'us.anthropic.claude-3-5-sonnet-20240620-v1:0' | 'us.anthropic.claude-3-5-haiku-20241022-v1:0' | 'us.anthropic.claude-3-opus-20240229-v1:0' | 'us.anthropic.claude-3-sonnet-20240229-v1:0' | 'us.anthropic.claude-3-haiku-20240307-v1:0' | (string & {});
13
13
 
14
14
  interface BedrockAnthropicProvider extends ProviderV4 {
15
15
  /**
@@ -1,55 +1,44 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/anthropic/index.ts
21
- var index_exports = {};
22
- __export(index_exports, {
23
- bedrockAnthropic: () => bedrockAnthropic,
24
- createBedrockAnthropic: () => createBedrockAnthropic
25
- });
26
- module.exports = __toCommonJS(index_exports);
27
-
28
1
  // src/anthropic/bedrock-anthropic-provider.ts
29
- var import_provider = require("@ai-sdk/provider");
30
- var import_provider_utils3 = require("@ai-sdk/provider-utils");
31
- var import_internal = require("@ai-sdk/anthropic/internal");
2
+ import {
3
+ NoSuchModelError
4
+ } from "@ai-sdk/provider";
5
+ import {
6
+ loadOptionalSetting,
7
+ loadSetting,
8
+ resolve,
9
+ withoutTrailingSlash,
10
+ withUserAgentSuffix as withUserAgentSuffix2
11
+ } from "@ai-sdk/provider-utils";
12
+ import {
13
+ anthropicTools,
14
+ AnthropicMessagesLanguageModel
15
+ } from "@ai-sdk/anthropic/internal";
32
16
 
33
17
  // src/bedrock-sigv4-fetch.ts
34
- var import_provider_utils = require("@ai-sdk/provider-utils");
35
- var import_aws4fetch = require("aws4fetch");
18
+ import {
19
+ combineHeaders,
20
+ normalizeHeaders,
21
+ withUserAgentSuffix,
22
+ getRuntimeEnvironmentUserAgent
23
+ } from "@ai-sdk/provider-utils";
24
+ import { AwsV4Signer } from "aws4fetch";
36
25
 
37
26
  // src/version.ts
38
- var VERSION = true ? "5.0.0-beta.4" : "0.0.0-test";
27
+ var VERSION = true ? "5.0.0-beta.41" : "0.0.0-test";
39
28
 
40
29
  // src/bedrock-sigv4-fetch.ts
41
30
  function createSigV4FetchFunction(getCredentials, fetch = globalThis.fetch) {
42
31
  return async (input, init) => {
43
32
  var _a, _b;
44
33
  const request = input instanceof Request ? input : void 0;
45
- const originalHeaders = (0, import_provider_utils.combineHeaders)(
46
- (0, import_provider_utils.normalizeHeaders)(request == null ? void 0 : request.headers),
47
- (0, import_provider_utils.normalizeHeaders)(init == null ? void 0 : init.headers)
34
+ const originalHeaders = combineHeaders(
35
+ normalizeHeaders(request == null ? void 0 : request.headers),
36
+ normalizeHeaders(init == null ? void 0 : init.headers)
48
37
  );
49
- const headersWithUserAgent = (0, import_provider_utils.withUserAgentSuffix)(
38
+ const headersWithUserAgent = withUserAgentSuffix(
50
39
  originalHeaders,
51
40
  `ai-sdk/amazon-bedrock/${VERSION}`,
52
- (0, import_provider_utils.getRuntimeEnvironmentUserAgent)()
41
+ getRuntimeEnvironmentUserAgent()
53
42
  );
54
43
  let effectiveBody = (_a = init == null ? void 0 : init.body) != null ? _a : void 0;
55
44
  if (effectiveBody === void 0 && request && request.body !== null) {
@@ -68,7 +57,7 @@ function createSigV4FetchFunction(getCredentials, fetch = globalThis.fetch) {
68
57
  const url = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
69
58
  const body = prepareBodyString(effectiveBody);
70
59
  const credentials = await getCredentials();
71
- const signer = new import_aws4fetch.AwsV4Signer({
60
+ const signer = new AwsV4Signer({
72
61
  url,
73
62
  method: "POST",
74
63
  headers: Object.entries(headersWithUserAgent),
@@ -80,8 +69,8 @@ function createSigV4FetchFunction(getCredentials, fetch = globalThis.fetch) {
80
69
  service: "bedrock"
81
70
  });
82
71
  const signingResult = await signer.sign();
83
- const signedHeaders = (0, import_provider_utils.normalizeHeaders)(signingResult.headers);
84
- const combinedHeaders = (0, import_provider_utils.combineHeaders)(headersWithUserAgent, signedHeaders);
72
+ const signedHeaders = normalizeHeaders(signingResult.headers);
73
+ const combinedHeaders = combineHeaders(headersWithUserAgent, signedHeaders);
85
74
  return fetch(input, {
86
75
  ...init,
87
76
  body,
@@ -102,13 +91,13 @@ function prepareBodyString(body) {
102
91
  }
103
92
  function createApiKeyFetchFunction(apiKey, fetch = globalThis.fetch) {
104
93
  return async (input, init) => {
105
- const originalHeaders = (0, import_provider_utils.normalizeHeaders)(init == null ? void 0 : init.headers);
106
- const headersWithUserAgent = (0, import_provider_utils.withUserAgentSuffix)(
94
+ const originalHeaders = normalizeHeaders(init == null ? void 0 : init.headers);
95
+ const headersWithUserAgent = withUserAgentSuffix(
107
96
  originalHeaders,
108
97
  `ai-sdk/amazon-bedrock/${VERSION}`,
109
- (0, import_provider_utils.getRuntimeEnvironmentUserAgent)()
98
+ getRuntimeEnvironmentUserAgent()
110
99
  );
111
- const finalHeaders = (0, import_provider_utils.combineHeaders)(headersWithUserAgent, {
100
+ const finalHeaders = combineHeaders(headersWithUserAgent, {
112
101
  Authorization: `Bearer ${apiKey}`
113
102
  });
114
103
  return fetch(input, {
@@ -119,13 +108,17 @@ function createApiKeyFetchFunction(apiKey, fetch = globalThis.fetch) {
119
108
  }
120
109
 
121
110
  // src/anthropic/bedrock-anthropic-fetch.ts
122
- var import_provider_utils2 = require("@ai-sdk/provider-utils");
111
+ import {
112
+ convertBase64ToUint8Array,
113
+ safeParseJSON
114
+ } from "@ai-sdk/provider-utils";
115
+ import { z } from "zod/v4";
123
116
 
124
117
  // src/bedrock-event-stream-decoder.ts
125
- var import_eventstream_codec = require("@smithy/eventstream-codec");
126
- var import_util_utf8 = require("@smithy/util-utf8");
118
+ import { EventStreamCodec } from "@smithy/eventstream-codec";
119
+ import { toUtf8, fromUtf8 } from "@smithy/util-utf8";
127
120
  function createBedrockEventStreamDecoder(body, processEvent) {
128
- const codec = new import_eventstream_codec.EventStreamCodec(import_util_utf8.toUtf8, import_util_utf8.fromUtf8);
121
+ const codec = new EventStreamCodec(toUtf8, fromUtf8);
129
122
  let buffer = new Uint8Array(0);
130
123
  const textDecoder = new TextDecoder();
131
124
  return body.pipeThrough(
@@ -163,9 +156,26 @@ function createBedrockEventStreamDecoder(body, processEvent) {
163
156
  }
164
157
 
165
158
  // src/anthropic/bedrock-anthropic-fetch.ts
159
+ var bedrockErrorSchema = z.looseObject({
160
+ message: z.string().optional()
161
+ });
166
162
  function createBedrockAnthropicFetch(baseFetch) {
167
163
  return async (url, options) => {
168
164
  const response = await baseFetch(url, options);
165
+ if (!response.ok) {
166
+ const text = await response.text();
167
+ const parsed = await safeParseJSON({ text, schema: bedrockErrorSchema });
168
+ const message = parsed.success && parsed.value.message ? parsed.value.message : text;
169
+ const anthropicError = JSON.stringify({
170
+ type: "error",
171
+ error: { type: "error", message }
172
+ });
173
+ return new Response(anthropicError, {
174
+ status: response.status,
175
+ statusText: response.statusText,
176
+ headers: response.headers
177
+ });
178
+ }
169
179
  const contentType = response.headers.get("content-type");
170
180
  if ((contentType == null ? void 0 : contentType.includes("application/vnd.amazon.eventstream")) && response.body != null) {
171
181
  const transformedBody = transformBedrockEventStreamToSSE(response.body);
@@ -186,7 +196,7 @@ function transformBedrockEventStreamToSSE(body) {
186
196
  return createBedrockEventStreamDecoder(body, async (event, controller) => {
187
197
  if (event.messageType === "event") {
188
198
  if (event.eventType === "chunk") {
189
- const parsed = await (0, import_provider_utils2.safeParseJSON)({ text: event.data });
199
+ const parsed = await safeParseJSON({ text: event.data });
190
200
  if (!parsed.success) {
191
201
  controller.enqueue(textEncoder.encode(`data: ${event.data}
192
202
 
@@ -196,7 +206,7 @@ function transformBedrockEventStreamToSSE(body) {
196
206
  const bytes = parsed.value.bytes;
197
207
  if (bytes) {
198
208
  const anthropicEvent = new TextDecoder().decode(
199
- (0, import_provider_utils2.convertBase64ToUint8Array)(bytes)
209
+ convertBase64ToUint8Array(bytes)
200
210
  );
201
211
  controller.enqueue(textEncoder.encode(`data: ${anthropicEvent}
202
212
 
@@ -238,16 +248,20 @@ var BEDROCK_TOOL_BETA_MAP = {
238
248
  text_editor_20250429: "computer-use-2025-01-24",
239
249
  text_editor_20250728: "computer-use-2025-01-24",
240
250
  computer_20250124: "computer-use-2025-01-24",
241
- computer_20241022: "computer-use-2024-10-22"
251
+ computer_20241022: "computer-use-2024-10-22",
252
+ tool_search_tool_regex_20251119: "tool-search-tool-2025-10-19",
253
+ // BM25 is not currently supported on Bedrock, but including the beta flag
254
+ // so that Bedrock returns a more useful error message if it's used.
255
+ tool_search_tool_bm25_20251119: "tool-search-tool-2025-10-19"
242
256
  };
243
257
  function createBedrockAnthropic(options = {}) {
244
- const rawApiKey = (0, import_provider_utils3.loadOptionalSetting)({
258
+ const rawApiKey = loadOptionalSetting({
245
259
  settingValue: options.apiKey,
246
260
  environmentVariableName: "AWS_BEARER_TOKEN_BEDROCK"
247
261
  });
248
262
  const apiKey = rawApiKey && rawApiKey.trim().length > 0 ? rawApiKey.trim() : void 0;
249
263
  const baseFetchFunction = apiKey ? createApiKeyFetchFunction(apiKey, options.fetch) : createSigV4FetchFunction(async () => {
250
- const region = (0, import_provider_utils3.loadSetting)({
264
+ const region = loadSetting({
251
265
  settingValue: options.region,
252
266
  settingName: "region",
253
267
  environmentVariableName: "AWS_REGION",
@@ -269,19 +283,19 @@ function createBedrockAnthropic(options = {}) {
269
283
  try {
270
284
  return {
271
285
  region,
272
- accessKeyId: (0, import_provider_utils3.loadSetting)({
286
+ accessKeyId: loadSetting({
273
287
  settingValue: options.accessKeyId,
274
288
  settingName: "accessKeyId",
275
289
  environmentVariableName: "AWS_ACCESS_KEY_ID",
276
290
  description: "AWS access key ID"
277
291
  }),
278
- secretAccessKey: (0, import_provider_utils3.loadSetting)({
292
+ secretAccessKey: loadSetting({
279
293
  settingValue: options.secretAccessKey,
280
294
  settingName: "secretAccessKey",
281
295
  environmentVariableName: "AWS_SECRET_ACCESS_KEY",
282
296
  description: "AWS secret access key"
283
297
  }),
284
- sessionToken: (0, import_provider_utils3.loadOptionalSetting)({
298
+ sessionToken: loadOptionalSetting({
285
299
  settingValue: options.sessionToken,
286
300
  environmentVariableName: "AWS_SESSION_TOKEN"
287
301
  })
@@ -310,8 +324,8 @@ Original error: ${errorMessage}`
310
324
  const fetchFunction = createBedrockAnthropicFetch(baseFetchFunction);
311
325
  const getBaseURL = () => {
312
326
  var _a, _b;
313
- return (_b = (0, import_provider_utils3.withoutTrailingSlash)(
314
- (_a = options.baseURL) != null ? _a : `https://bedrock-runtime.${(0, import_provider_utils3.loadSetting)({
327
+ return (_b = withoutTrailingSlash(
328
+ (_a = options.baseURL) != null ? _a : `https://bedrock-runtime.${loadSetting({
315
329
  settingValue: options.region,
316
330
  settingName: "region",
317
331
  environmentVariableName: "AWS_REGION",
@@ -321,17 +335,23 @@ Original error: ${errorMessage}`
321
335
  };
322
336
  const getHeaders = async () => {
323
337
  var _a;
324
- const baseHeaders = (_a = await (0, import_provider_utils3.resolve)(options.headers)) != null ? _a : {};
325
- return (0, import_provider_utils3.withUserAgentSuffix)(baseHeaders, `ai-sdk/amazon-bedrock/${VERSION}`);
338
+ const baseHeaders = (_a = await resolve(options.headers)) != null ? _a : {};
339
+ return withUserAgentSuffix2(baseHeaders, `ai-sdk/amazon-bedrock/${VERSION}`);
326
340
  };
327
- const createChatModel = (modelId) => new import_internal.AnthropicMessagesLanguageModel(modelId, {
341
+ const createChatModel = (modelId) => new AnthropicMessagesLanguageModel(modelId, {
328
342
  provider: "bedrock.anthropic.messages",
329
343
  baseURL: getBaseURL(),
330
344
  headers: getHeaders,
331
345
  fetch: fetchFunction,
332
346
  buildRequestUrl: (baseURL, isStreaming) => `${baseURL}/model/${encodeURIComponent(modelId)}/${isStreaming ? "invoke-with-response-stream" : "invoke"}`,
333
347
  transformRequestBody: (args, betas) => {
334
- const { model, stream, tool_choice, tools, ...rest } = args;
348
+ const {
349
+ model: _model,
350
+ stream: _stream,
351
+ tool_choice,
352
+ tools,
353
+ ...rest
354
+ } = args;
335
355
  const transformedToolChoice = tool_choice != null ? {
336
356
  type: tool_choice.type,
337
357
  ...tool_choice.name != null ? { name: tool_choice.name } : {}
@@ -388,19 +408,18 @@ Original error: ${errorMessage}`
388
408
  provider.chat = createChatModel;
389
409
  provider.messages = createChatModel;
390
410
  provider.embeddingModel = (modelId) => {
391
- throw new import_provider.NoSuchModelError({ modelId, modelType: "embeddingModel" });
411
+ throw new NoSuchModelError({ modelId, modelType: "embeddingModel" });
392
412
  };
393
413
  provider.textEmbeddingModel = provider.embeddingModel;
394
414
  provider.imageModel = (modelId) => {
395
- throw new import_provider.NoSuchModelError({ modelId, modelType: "imageModel" });
415
+ throw new NoSuchModelError({ modelId, modelType: "imageModel" });
396
416
  };
397
- provider.tools = import_internal.anthropicTools;
417
+ provider.tools = anthropicTools;
398
418
  return provider;
399
419
  }
400
420
  var bedrockAnthropic = createBedrockAnthropic();
401
- // Annotate the CommonJS export names for ESM import in node:
402
- 0 && (module.exports = {
421
+ export {
403
422
  bedrockAnthropic,
404
423
  createBedrockAnthropic
405
- });
424
+ };
406
425
  //# sourceMappingURL=index.js.map