Skip to content

Commit 7ddf8df

Browse files
author
awstools
committed
feat(client-bedrock-runtime): This release introduces Guardrails for Amazon Bedrock.
1 parent 4fcf9f7 commit 7ddf8df

File tree

9 files changed

+253
-41
lines changed

9 files changed

+253
-41
lines changed

clients/client-bedrock-runtime/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
AWS SDK for JavaScript BedrockRuntime Client for Node.js, Browser and React Native.
88

9-
<p>Describes the API operations for running inference using Bedrock models.</p>
9+
<p>Describes the API operations for running inference using Amazon Bedrock models.</p>
1010

1111
## Installing
1212

clients/client-bedrock-runtime/src/BedrockRuntime.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export interface BedrockRuntime {
4646
}
4747

4848
/**
49-
* <p>Describes the API operations for running inference using Bedrock models.</p>
49+
* <p>Describes the API operations for running inference using Amazon Bedrock models.</p>
5050
* @public
5151
*/
5252
export class BedrockRuntime extends BedrockRuntimeClient implements BedrockRuntime {}

clients/client-bedrock-runtime/src/BedrockRuntimeClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ export type BedrockRuntimeClientResolvedConfigType = __SmithyResolvedConfigurati
264264
export interface BedrockRuntimeClientResolvedConfig extends BedrockRuntimeClientResolvedConfigType {}
265265

266266
/**
267-
* <p>Describes the API operations for running inference using Bedrock models.</p>
267+
* <p>Describes the API operations for running inference using Amazon Bedrock models.</p>
268268
* @public
269269
*/
270270
export class BedrockRuntimeClient extends __Client<

clients/client-bedrock-runtime/src/commands/InvokeModelCommand.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,11 @@ export type InvokeModelCommandOutputType = Omit<InvokeModelResponse, "body"> & {
4747
export interface InvokeModelCommandOutput extends InvokeModelCommandOutputType, __MetadataBearer {}
4848

4949
/**
50-
* <p>Invokes the specified Bedrock model to run inference using the input provided in the request body.
51-
* You use InvokeModel to run inference for text models, image models, and embedding models.</p>
52-
* <p>For more information, see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/api-methods-run.html">Run inference</a> in the Bedrock User Guide.</p>
53-
* <p>For example requests, see Examples (after the Errors section).</p>
50+
* <p>Invokes the specified Amazon Bedrock model to run inference using the prompt and inference parameters provided in the request body.
51+
* You use model inference to generate text, images, and embeddings.</p>
52+
* <p>For example code, see <i>Invoke model code examples</i> in the <i>Amazon Bedrock User Guide</i>.
53+
* </p>
54+
* <p>This operation requires permission for the <code>bedrock:InvokeModel</code> action.</p>
5455
* @example
5556
* Use a bare-bones client and the command you need to make an API call.
5657
* ```javascript
@@ -62,6 +63,9 @@ export interface InvokeModelCommandOutput extends InvokeModelCommandOutputType,
6263
* contentType: "STRING_VALUE",
6364
* accept: "STRING_VALUE",
6465
* modelId: "STRING_VALUE", // required
66+
* trace: "ENABLED" || "DISABLED",
67+
* guardrailIdentifier: "STRING_VALUE",
68+
* guardrailVersion: "STRING_VALUE",
6569
* };
6670
* const command = new InvokeModelCommand(input);
6771
* const response = await client.send(command);

clients/client-bedrock-runtime/src/commands/InvokeModelWithResponseStreamCommand.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,16 @@ export interface InvokeModelWithResponseStreamCommandOutput
4444
__MetadataBearer {}
4545

4646
/**
47-
* <p>Invoke the specified Bedrock model to run inference using the input provided.
48-
* Return the response in a stream.</p>
49-
* <p>For more information, see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/api-methods-run.html">Run inference</a> in the Bedrock User Guide.</p>
50-
* <p>For an example request and response, see Examples (after the Errors section).</p>
47+
* <p>Invoke the specified Amazon Bedrock model to run inference using the prompt and inference parameters provided in the request body. The response is returned in a stream.</p>
48+
* <p>To see if a model supports streaming, call <a href="https://docs.aws.amazon.com/bedrock/latest/APIReference/API_GetFoundationModel.html">GetFoundationModel</a>
49+
* and check the <code>responseStreamingSupported</code> field in the response.</p>
50+
* <note>
51+
* <p>The CLI doesn't support <code>InvokeModelWithResponseStream</code>.</p>
52+
* </note>
53+
* <p>For example code, see <i>Invoke model with streaming code
54+
* example</i> in the <i>Amazon Bedrock User Guide</i>.
55+
* </p>
56+
* <p>This operation requires permissions to perform the <code>bedrock:InvokeModelWithResponseStream</code> action. </p>
5157
* @example
5258
* Use a bare-bones client and the command you need to make an API call.
5359
* ```javascript
@@ -59,6 +65,9 @@ export interface InvokeModelWithResponseStreamCommandOutput
5965
* contentType: "STRING_VALUE",
6066
* accept: "STRING_VALUE",
6167
* modelId: "STRING_VALUE", // required
68+
* trace: "ENABLED" || "DISABLED",
69+
* guardrailIdentifier: "STRING_VALUE",
70+
* guardrailVersion: "STRING_VALUE",
6271
* };
6372
* const command = new InvokeModelWithResponseStreamCommand(input);
6473
* const response = await client.send(command);
@@ -109,7 +118,7 @@ export interface InvokeModelWithResponseStreamCommandOutput
109118
* <p>The model specified in the request is not ready to serve inference requests.</p>
110119
*
111120
* @throws {@link ModelStreamErrorException} (client fault)
112-
* <p>An error occurred while streaming the response.</p>
121+
* <p>An error occurred while streaming the response. Retry your request.</p>
113122
*
114123
* @throws {@link ModelTimeoutException} (client fault)
115124
* <p>The request took too long to process. Processing time exceeded the model timeout length.</p>

clients/client-bedrock-runtime/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// smithy-typescript generated code
22
/* eslint-disable */
33
/**
4-
* <p>Describes the API operations for running inference using Bedrock models.</p>
4+
* <p>Describes the API operations for running inference using Amazon Bedrock models.</p>
55
*
66
* @packageDocumentation
77
*/

clients/client-bedrock-runtime/src/models/models_0.ts

Lines changed: 110 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,26 @@ export class InternalServerException extends __BaseException {
4343
}
4444
}
4545

46+
/**
47+
* @public
48+
* @enum
49+
*/
50+
export const Trace = {
51+
DISABLED: "DISABLED",
52+
ENABLED: "ENABLED",
53+
} as const;
54+
55+
/**
56+
* @public
57+
*/
58+
export type Trace = (typeof Trace)[keyof typeof Trace];
59+
4660
/**
4761
* @public
4862
*/
4963
export interface InvokeModelRequest {
5064
/**
51-
* <p>Input data in the format specified in the content-type request header. To see the format and content of this field for different models, refer to <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters.html">Inference parameters</a>.</p>
65+
* <p>The prompt and inference parameters in the format specified in the <code>contentType</code> in the header. To see the format and content of the request and response bodies for different models, refer to <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters.html">Inference parameters</a>. For more information, see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/api-methods-run.html">Run inference</a> in the Bedrock User Guide.</p>
5266
* @public
5367
*/
5468
body: Uint8Array | undefined;
@@ -61,25 +75,67 @@ export interface InvokeModelRequest {
6175
contentType?: string;
6276

6377
/**
64-
* <p>The desired MIME type of the inference body in the response. The default value is
65-
* <code>application/json</code>.</p>
78+
* <p>The desired MIME type of the inference body in the response. The default value is <code>application/json</code>.</p>
6679
* @public
6780
*/
6881
accept?: string;
6982

7083
/**
71-
* <p>Identifier of the model. </p>
84+
* <p>The unique identifier of the model to invoke to run inference.</p>
85+
* <p>The <code>modelId</code> to provide depends on the type of model that you use:</p>
86+
* <ul>
87+
* <li>
88+
* <p>If you use a base model, specify the model ID or its ARN. For a list of model IDs for base models, see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/model-ids.html#model-ids-arns">Amazon Bedrock base model IDs (on-demand throughput)</a> in the Amazon Bedrock User Guide.</p>
89+
* </li>
90+
* <li>
91+
* <p>If you use a provisioned model, specify the ARN of the Provisioned Throughput. For more information, see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/prov-thru-use.html">Run inference using a Provisioned Throughput</a> in the Amazon Bedrock User Guide.</p>
92+
* </li>
93+
* <li>
94+
* <p>If you use a custom model, first purchase Provisioned Throughput for it. Then specify the ARN of the resulting provisioned model. For more information, see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/model-customization-use.html">Use a custom model in Amazon Bedrock</a> in the Amazon Bedrock User Guide.</p>
95+
* </li>
96+
* </ul>
7297
* @public
7398
*/
7499
modelId: string | undefined;
100+
101+
/**
102+
* <p>Specifies whether to enable or disable the Bedrock trace. If enabled, you can see the full Bedrock trace.</p>
103+
* @public
104+
*/
105+
trace?: Trace;
106+
107+
/**
108+
* <p>The unique identifier of the guardrail that you want to use. If you don't provide a value, no guardrail is applied
109+
* to the invocation.</p>
110+
* <p>An error will be thrown in the following situations.</p>
111+
* <ul>
112+
* <li>
113+
* <p>You don't provide a guardrail identifier but you specify the <code>amazon-bedrock-guardrailConfig</code> field in the request body.</p>
114+
* </li>
115+
* <li>
116+
* <p>You enable the guardrail but the <code>contentType</code> isn't <code>application/json</code>.</p>
117+
* </li>
118+
* <li>
119+
* <p>You provide a guardrail identifier, but <code>guardrailVersion</code> isn't specified.</p>
120+
* </li>
121+
* </ul>
122+
* @public
123+
*/
124+
guardrailIdentifier?: string;
125+
126+
/**
127+
* <p>The version number for the guardrail. The value can also be <code>DRAFT</code>.</p>
128+
* @public
129+
*/
130+
guardrailVersion?: string;
75131
}
76132

77133
/**
78134
* @public
79135
*/
80136
export interface InvokeModelResponse {
81137
/**
82-
* <p>Inference response from the model in the format specified in the content-type header field. To see the format and content of this field for different models, refer to <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters.html">Inference parameters</a>.</p>
138+
* <p>Inference response from the model in the format specified in the <code>contentType</code> header. To see the format and content of the request and response bodies for different models, refer to <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters.html">Inference parameters</a>.</p>
83139
* @public
84140
*/
85141
body: Uint8Array | undefined;
@@ -250,8 +306,7 @@ export class ValidationException extends __BaseException {
250306
*/
251307
export interface InvokeModelWithResponseStreamRequest {
252308
/**
253-
* <p>Inference input in the format specified by the
254-
* content-type. To see the format and content of this field for different models, refer to <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters.html">Inference parameters</a>.</p>
309+
* <p>The prompt and inference parameters in the format specified in the <code>contentType</code> in the header. To see the format and content of the request and response bodies for different models, refer to <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters.html">Inference parameters</a>. For more information, see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/api-methods-run.html">Run inference</a> in the Bedrock User Guide.</p>
255310
* @public
256311
*/
257312
body: Uint8Array | undefined;
@@ -271,10 +326,53 @@ export interface InvokeModelWithResponseStreamRequest {
271326
accept?: string;
272327

273328
/**
274-
* <p>Id of the model to invoke using the streaming request.</p>
329+
* <p>The unique identifier of the model to invoke to run inference.</p>
330+
* <p>The <code>modelId</code> to provide depends on the type of model that you use:</p>
331+
* <ul>
332+
* <li>
333+
* <p>If you use a base model, specify the model ID or its ARN. For a list of model IDs for base models, see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/model-ids.html#model-ids-arns">Amazon Bedrock base model IDs (on-demand throughput)</a> in the Amazon Bedrock User Guide.</p>
334+
* </li>
335+
* <li>
336+
* <p>If you use a provisioned model, specify the ARN of the Provisioned Throughput. For more information, see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/prov-thru-use.html">Run inference using a Provisioned Throughput</a> in the Amazon Bedrock User Guide.</p>
337+
* </li>
338+
* <li>
339+
* <p>If you use a custom model, first purchase Provisioned Throughput for it. Then specify the ARN of the resulting provisioned model. For more information, see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/model-customization-use.html">Use a custom model in Amazon Bedrock</a> in the Amazon Bedrock User Guide.</p>
340+
* </li>
341+
* </ul>
275342
* @public
276343
*/
277344
modelId: string | undefined;
345+
346+
/**
347+
* <p>Specifies whether to enable or disable the Bedrock trace. If enabled, you can see the full Bedrock trace.</p>
348+
* @public
349+
*/
350+
trace?: Trace;
351+
352+
/**
353+
* <p>The unique identifier of the guardrail that you want to use. If you don't provide a value, no guardrail is applied
354+
* to the invocation.</p>
355+
* <p>An error is thrown in the following situations.</p>
356+
* <ul>
357+
* <li>
358+
* <p>You don't provide a guardrail identifier but you specify the <code>amazon-bedrock-guardrailConfig</code> field in the request body.</p>
359+
* </li>
360+
* <li>
361+
* <p>You enable the guardrail but the <code>contentType</code> isn't <code>application/json</code>.</p>
362+
* </li>
363+
* <li>
364+
* <p>You provide a guardrail identifier, but <code>guardrailVersion</code> isn't specified.</p>
365+
* </li>
366+
* </ul>
367+
* @public
368+
*/
369+
guardrailIdentifier?: string;
370+
371+
/**
372+
* <p>The version number for the guardrail. The value can also be <code>DRAFT</code>.</p>
373+
* @public
374+
*/
375+
guardrailVersion?: string;
278376
}
279377

280378
/**
@@ -290,7 +388,7 @@ export interface PayloadPart {
290388
}
291389

292390
/**
293-
* <p>An error occurred while streaming the response.</p>
391+
* <p>An error occurred while streaming the response. Retry your request.</p>
294392
* @public
295393
*/
296394
export class ModelStreamErrorException extends __BaseException {
@@ -369,7 +467,7 @@ export namespace ResponseStream {
369467
}
370468

371469
/**
372-
* <p>An error occurred while streaming the response.</p>
470+
* <p>An error occurred while streaming the response. Retry your request.</p>
373471
* @public
374472
*/
375473
export interface ModelStreamErrorExceptionMember {
@@ -397,7 +495,7 @@ export namespace ResponseStream {
397495
}
398496

399497
/**
400-
* <p>The number of requests exceeds the limit. Resubmit your request later.</p>
498+
* <p>The number or frequency of requests exceeds the limit. Resubmit your request later.</p>
401499
* @public
402500
*/
403501
export interface ThrottlingExceptionMember {
@@ -465,7 +563,7 @@ export namespace ResponseStream {
465563
*/
466564
export interface InvokeModelWithResponseStreamResponse {
467565
/**
468-
* <p>Inference response from the model in the format specified by Content-Type. To see the format and content of this field for different models, refer to <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters.html">Inference parameters</a>.</p>
566+
* <p>Inference response from the model in the format specified by the <code>contentType</code> header. To see the format and content of this field for different models, refer to <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters.html">Inference parameters</a>.</p>
469567
* @public
470568
*/
471569
body: AsyncIterable<ResponseStream> | undefined;

clients/client-bedrock-runtime/src/protocols/Aws_restJson1.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ export const se_InvokeModelCommand = async (
5252
const headers: any = map({}, isSerializableHeaderValue, {
5353
[_ct]: input[_cT]! || "application/octet-stream",
5454
[_a]: input[_a]!,
55+
[_xabt]: input[_t]!,
56+
[_xabg]: input[_gI]!,
57+
[_xabg_]: input[_gV]!,
5558
});
5659
b.bp("/model/{modelId}/invoke");
5760
b.p("modelId", () => input.modelId!, "{modelId}", false);
@@ -74,6 +77,9 @@ export const se_InvokeModelWithResponseStreamCommand = async (
7477
const headers: any = map({}, isSerializableHeaderValue, {
7578
[_ct]: input[_cT]! || "application/octet-stream",
7679
[_xaba]: input[_a]!,
80+
[_xabt]: input[_t]!,
81+
[_xabg]: input[_gI]!,
82+
[_xabg_]: input[_gV]!,
7783
});
7884
b.bp("/model/{modelId}/invoke-with-response-stream");
7985
b.p("modelId", () => input.modelId!, "{modelId}", false);
@@ -491,5 +497,11 @@ const isSerializableHeaderValue = (value: any): boolean =>
491497
const _a = "accept";
492498
const _cT = "contentType";
493499
const _ct = "content-type";
500+
const _gI = "guardrailIdentifier";
501+
const _gV = "guardrailVersion";
502+
const _t = "trace";
494503
const _xaba = "x-amzn-bedrock-accept";
495504
const _xabct = "x-amzn-bedrock-content-type";
505+
const _xabg = "x-amzn-bedrock-guardrailidentifier";
506+
const _xabg_ = "x-amzn-bedrock-guardrailversion";
507+
const _xabt = "x-amzn-bedrock-trace";

0 commit comments

Comments
 (0)