@ai-sdk/amazon-bedrock 4.0.165 → 4.0.167

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.
@@ -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 ? "4.0.165" : "0.0.0-test";
38
+ var VERSION = true ? "4.0.167" : "0.0.0-test";
39
39
 
40
40
  // src/bedrock-sigv4-fetch.ts
41
41
  function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {
@@ -23,7 +23,7 @@ import {
23
23
  import { AwsV4Signer } from "aws4fetch";
24
24
 
25
25
  // src/version.ts
26
- var VERSION = true ? "4.0.165" : "0.0.0-test";
26
+ var VERSION = true ? "4.0.167" : "0.0.0-test";
27
27
 
28
28
  // src/bedrock-sigv4-fetch.ts
29
29
  function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {
@@ -942,6 +942,30 @@ The following provider options are available for Cohere embedding models:
942
942
 
943
943
  Truncation behavior when input exceeds the model's context length. Accepts: `NONE`, `START`, `END`.
944
944
 
945
+ ### Application Inference Profiles
946
+
947
+ Application inference profile ARNs do not identify their underlying model. Pass
948
+ the model family when creating an embedding model so the provider can select
949
+ the correct request format and batch size:
950
+
951
+ ```ts
952
+ import {
953
+ bedrock,
954
+ type AmazonBedrockEmbeddingModelSettings,
955
+ } from '@ai-sdk/amazon-bedrock';
956
+ import { embedMany } from 'ai';
957
+
958
+ const profileArn =
959
+ 'arn:aws:bedrock:us-east-1:123456789012:application-inference-profile/qibm5eutlkcy';
960
+
961
+ const { embeddings } = await embedMany({
962
+ model: bedrock.embedding(profileArn, {
963
+ modelFamily: 'cohere',
964
+ } satisfies AmazonBedrockEmbeddingModelSettings),
965
+ values: ['hello', 'world'],
966
+ });
967
+ ```
968
+
945
969
  ### Model Capabilities
946
970
 
947
971
  | Model | Default Dimensions | Custom Dimensions |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/amazon-bedrock",
3
- "version": "4.0.165",
3
+ "version": "4.0.167",
4
4
  "license": "Apache-2.0",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.js",
@@ -44,10 +44,10 @@
44
44
  "@smithy/eventstream-codec": "^4.0.1",
45
45
  "@smithy/util-utf8": "^4.0.0",
46
46
  "aws4fetch": "^1.0.20",
47
- "@ai-sdk/anthropic": "3.0.114",
48
- "@ai-sdk/openai": "3.0.104",
47
+ "@ai-sdk/anthropic": "3.0.115",
48
+ "@ai-sdk/openai": "3.0.106",
49
49
  "@ai-sdk/provider": "3.0.15",
50
- "@ai-sdk/provider-utils": "4.0.49"
50
+ "@ai-sdk/provider-utils": "4.0.50"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@types/node": "20.17.24",
@@ -160,7 +160,12 @@ export class BedrockChatLanguageModel implements LanguageModelV3 {
160
160
  });
161
161
  }
162
162
 
163
- const isAnthropicModel = this.modelId.includes('anthropic');
163
+ // Application inference profile ARNs do not expose their underlying model.
164
+ // The Anthropic-only reasoning budget provides the model-family signal.
165
+ const isAnthropicModel =
166
+ this.modelId.includes('anthropic') ||
167
+ (this.modelId.includes(':application-inference-profile/') &&
168
+ bedrockOptions.reasoningConfig?.budgetTokens != null);
164
169
  const openAIModelId = /^(?:[^.]+\.)?(openai\..+)$/.exec(this.modelId)?.[1];
165
170
  const isOpenAIModel = openAIModelId != null;
166
171
  const isOpenAIGptOssModel =
@@ -1278,6 +1283,9 @@ const BedrockStreamSchema = z.object({
1278
1283
  delta: z
1279
1284
  .union([
1280
1285
  z.object({ text: z.string() }),
1286
+ z.object({
1287
+ citation: z.record(z.string(), z.unknown()),
1288
+ }),
1281
1289
  z.object({ toolUse: z.object({ input: z.string() }) }),
1282
1290
  z.object({
1283
1291
  reasoningContent: z.object({ text: z.string() }),
@@ -15,6 +15,7 @@ import {
15
15
  import {
16
16
  amazonBedrockEmbeddingModelOptionsSchema,
17
17
  type BedrockEmbeddingModelId,
18
+ type AmazonBedrockEmbeddingModelSettings,
18
19
  } from './bedrock-embedding-options';
19
20
  import { BedrockErrorSchema } from './bedrock-error';
20
21
  import { z } from 'zod/v4';
@@ -23,6 +24,7 @@ type BedrockEmbeddingConfig = {
23
24
  baseUrl: () => string;
24
25
  headers: Resolvable<Record<string, string | undefined>>;
25
26
  fetch?: FetchFunction;
27
+ modelFamily?: AmazonBedrockEmbeddingModelSettings['modelFamily'];
26
28
  };
27
29
 
28
30
  type DoEmbedResponse = Awaited<ReturnType<EmbeddingModelV3['doEmbed']>>;
@@ -33,7 +35,11 @@ export class BedrockEmbeddingModel implements EmbeddingModelV3 {
33
35
  readonly supportsParallelCalls = true;
34
36
 
35
37
  get maxEmbeddingsPerCall() {
36
- return isCohereEmbeddingModel(this.modelId) ? 96 : 1;
38
+ return this.modelFamily === 'cohere' ? 96 : 1;
39
+ }
40
+
41
+ private get modelFamily() {
42
+ return this.config.modelFamily ?? detectEmbeddingModelFamily(this.modelId);
37
43
  }
38
44
 
39
45
  constructor(
@@ -74,36 +80,36 @@ export class BedrockEmbeddingModel implements EmbeddingModelV3 {
74
80
  // Note: Different embedding model families expect different request/response
75
81
  // payloads (e.g. Titan vs Cohere vs Nova). We keep the public interface stable and
76
82
  // adapt here based on the modelId.
77
- const isNovaModel = isNovaEmbeddingModel(this.modelId);
78
- const isCohereModel = isCohereEmbeddingModel(this.modelId);
79
-
80
- const args = isNovaModel
81
- ? {
82
- taskType: 'SINGLE_EMBEDDING',
83
- singleEmbeddingParams: {
84
- embeddingPurpose:
85
- bedrockOptions.embeddingPurpose ?? 'GENERIC_INDEX',
86
- embeddingDimension: bedrockOptions.embeddingDimension ?? 1024,
87
- text: {
88
- truncationMode: bedrockOptions.truncate ?? 'END',
89
- value: values[0],
90
- },
91
- },
92
- }
93
- : isCohereModel
83
+ const modelFamily = this.modelFamily;
84
+
85
+ const args =
86
+ modelFamily === 'nova'
94
87
  ? {
95
- // Cohere embedding models on Bedrock require `input_type`.
96
- // Without it, the service attempts other schema branches and rejects the request.
97
- input_type: bedrockOptions.inputType ?? 'search_query',
98
- texts: values,
99
- truncate: bedrockOptions.truncate,
100
- output_dimension: bedrockOptions.outputDimension,
88
+ taskType: 'SINGLE_EMBEDDING',
89
+ singleEmbeddingParams: {
90
+ embeddingPurpose:
91
+ bedrockOptions.embeddingPurpose ?? 'GENERIC_INDEX',
92
+ embeddingDimension: bedrockOptions.embeddingDimension ?? 1024,
93
+ text: {
94
+ truncationMode: bedrockOptions.truncate ?? 'END',
95
+ value: values[0],
96
+ },
97
+ },
101
98
  }
102
- : {
103
- inputText: values[0],
104
- dimensions: bedrockOptions.dimensions,
105
- normalize: bedrockOptions.normalize,
106
- };
99
+ : modelFamily === 'cohere'
100
+ ? {
101
+ // Cohere embedding models on Bedrock require `input_type`.
102
+ // Without it, the service attempts other schema branches and rejects the request.
103
+ input_type: bedrockOptions.inputType ?? 'search_query',
104
+ texts: values,
105
+ truncate: bedrockOptions.truncate,
106
+ output_dimension: bedrockOptions.outputDimension,
107
+ }
108
+ : {
109
+ inputText: values[0],
110
+ dimensions: bedrockOptions.dimensions,
111
+ normalize: bedrockOptions.normalize,
112
+ };
107
113
 
108
114
  const url = this.getUrl(this.modelId);
109
115
  const { value: response, responseHeaders } = await postJsonToApi({
@@ -172,7 +178,17 @@ function isCohereEmbeddingModel(modelId: string) {
172
178
  }
173
179
 
174
180
  function isNovaEmbeddingModel(modelId: string) {
175
- return modelId.startsWith('amazon.nova-') && modelId.includes('embed');
181
+ return modelId.includes('amazon.nova-') && modelId.includes('embed');
182
+ }
183
+
184
+ function detectEmbeddingModelFamily(
185
+ modelId: string,
186
+ ): NonNullable<AmazonBedrockEmbeddingModelSettings['modelFamily']> {
187
+ return isNovaEmbeddingModel(modelId)
188
+ ? 'nova'
189
+ : isCohereEmbeddingModel(modelId)
190
+ ? 'cohere'
191
+ : 'titan';
176
192
  }
177
193
 
178
194
  const BedrockEmbeddingResponseSchema = z.union([
@@ -7,6 +7,16 @@ export type BedrockEmbeddingModelId =
7
7
  | 'cohere.embed-multilingual-v3'
8
8
  | (string & {});
9
9
 
10
+ export type AmazonBedrockEmbeddingModelSettings = {
11
+ /**
12
+ * The embedding model family.
13
+ *
14
+ * Specify this when the model ID does not identify the underlying model,
15
+ * such as an application inference profile ARN.
16
+ */
17
+ modelFamily?: 'titan' | 'cohere' | 'nova';
18
+ };
19
+
10
20
  export const amazonBedrockEmbeddingModelOptionsSchema = z.object({
11
21
  /**
12
22
  * The number of dimensions the resulting output embeddings should have (defaults to 1024).
@@ -17,7 +17,10 @@ import {
17
17
  import { BedrockChatLanguageModel } from './bedrock-chat-language-model';
18
18
  import type { BedrockChatModelId } from './bedrock-chat-options';
19
19
  import { BedrockEmbeddingModel } from './bedrock-embedding-model';
20
- import type { BedrockEmbeddingModelId } from './bedrock-embedding-options';
20
+ import type {
21
+ BedrockEmbeddingModelId,
22
+ AmazonBedrockEmbeddingModelSettings,
23
+ } from './bedrock-embedding-options';
21
24
  import { BedrockImageModel } from './bedrock-image-model';
22
25
  import type { BedrockImageModelId } from './bedrock-image-settings';
23
26
  import {
@@ -117,22 +120,34 @@ export interface AmazonBedrockProvider extends ProviderV3 {
117
120
  /**
118
121
  * Creates a model for text embeddings.
119
122
  */
120
- embedding(modelId: BedrockEmbeddingModelId): EmbeddingModelV3;
123
+ embedding(
124
+ modelId: BedrockEmbeddingModelId,
125
+ settings?: AmazonBedrockEmbeddingModelSettings,
126
+ ): EmbeddingModelV3;
121
127
 
122
128
  /**
123
129
  * Creates a model for text embeddings.
124
130
  */
125
- embeddingModel(modelId: BedrockEmbeddingModelId): EmbeddingModelV3;
131
+ embeddingModel(
132
+ modelId: BedrockEmbeddingModelId,
133
+ settings?: AmazonBedrockEmbeddingModelSettings,
134
+ ): EmbeddingModelV3;
126
135
 
127
136
  /**
128
137
  * @deprecated Use `embedding` instead.
129
138
  */
130
- textEmbedding(modelId: BedrockEmbeddingModelId): EmbeddingModelV3;
139
+ textEmbedding(
140
+ modelId: BedrockEmbeddingModelId,
141
+ settings?: AmazonBedrockEmbeddingModelSettings,
142
+ ): EmbeddingModelV3;
131
143
 
132
144
  /**
133
145
  * @deprecated Use `embeddingModel` instead.
134
146
  */
135
- textEmbeddingModel(modelId: BedrockEmbeddingModelId): EmbeddingModelV3;
147
+ textEmbeddingModel(
148
+ modelId: BedrockEmbeddingModelId,
149
+ settings?: AmazonBedrockEmbeddingModelSettings,
150
+ ): EmbeddingModelV3;
136
151
 
137
152
  /**
138
153
  * Creates a model for image generation.
@@ -308,11 +323,15 @@ export function createAmazonBedrock(
308
323
  return createChatModel(modelId);
309
324
  };
310
325
 
311
- const createEmbeddingModel = (modelId: BedrockEmbeddingModelId) =>
326
+ const createEmbeddingModel = (
327
+ modelId: BedrockEmbeddingModelId,
328
+ settings: AmazonBedrockEmbeddingModelSettings = {},
329
+ ) =>
312
330
  new BedrockEmbeddingModel(modelId, {
313
331
  baseUrl: getBedrockRuntimeBaseUrl,
314
332
  headers: getHeaders,
315
333
  fetch: fetchFunction,
334
+ modelFamily: settings.modelFamily,
316
335
  });
317
336
 
318
337
  const createImageModel = (modelId: BedrockImageModelId) =>
@@ -460,7 +460,7 @@ export async function convertToBedrockChatMessages(
460
460
  pushCachePoint(bedrockContent, message.providerOptions);
461
461
  }
462
462
 
463
- if (bedrockContent.length > 0) {
463
+ if (bedrockContent.some(block => !('cachePoint' in block))) {
464
464
  messages.push({ role: 'assistant', content: bedrockContent });
465
465
  }
466
466
 
package/src/index.ts CHANGED
@@ -1,6 +1,9 @@
1
1
  export type { AnthropicProviderOptions } from '@ai-sdk/anthropic';
2
2
 
3
- export type { AmazonBedrockEmbeddingModelOptions } from './bedrock-embedding-options';
3
+ export type {
4
+ AmazonBedrockEmbeddingModelOptions,
5
+ AmazonBedrockEmbeddingModelSettings,
6
+ } from './bedrock-embedding-options';
4
7
  export type {
5
8
  AmazonBedrockLanguageModelOptions,
6
9
  /** @deprecated Use `AmazonBedrockLanguageModelOptions` instead. */