diff --git a/clients/client-bedrock-runtime/.gitignore b/clients/client-bedrock-runtime/.gitignore new file mode 100644 index 0000000000000..54f14c9aef253 --- /dev/null +++ b/clients/client-bedrock-runtime/.gitignore @@ -0,0 +1,9 @@ +/node_modules/ +/build/ +/coverage/ +/docs/ +/dist-* +*.tsbuildinfo +*.tgz +*.log +package-lock.json diff --git a/clients/client-bedrock-runtime/LICENSE b/clients/client-bedrock-runtime/LICENSE new file mode 100644 index 0000000000000..5001cd317c44a --- /dev/null +++ b/clients/client-bedrock-runtime/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "{}" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2018-2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/clients/client-bedrock-runtime/README.md b/clients/client-bedrock-runtime/README.md new file mode 100644 index 0000000000000..fa460be15be44 --- /dev/null +++ b/clients/client-bedrock-runtime/README.md @@ -0,0 +1,221 @@ + + +# @aws-sdk/client-bedrock-runtime + +## Description + +AWS SDK for JavaScript BedrockRuntime Client for Node.js, Browser and React Native. + +
Describes the API operations for running inference using Bedrock models.
+ +## Installing + +To install the this package, simply type add or install @aws-sdk/client-bedrock-runtime +using your favorite package manager: + +- `npm install @aws-sdk/client-bedrock-runtime` +- `yarn add @aws-sdk/client-bedrock-runtime` +- `pnpm add @aws-sdk/client-bedrock-runtime` + +## Getting Started + +### Import + +The AWS SDK is modulized by clients and commands. +To send a request, you only need to import the `BedrockRuntimeClient` and +the commands you need, for example `InvokeModelCommand`: + +```js +// ES5 example +const { BedrockRuntimeClient, InvokeModelCommand } = require("@aws-sdk/client-bedrock-runtime"); +``` + +```ts +// ES6+ example +import { BedrockRuntimeClient, InvokeModelCommand } from "@aws-sdk/client-bedrock-runtime"; +``` + +### Usage + +To send a request, you: + +- Initiate client with configuration (e.g. credentials, region). +- Initiate command with input parameters. +- Call `send` operation on client with command object as input. +- If you are using a custom http handler, you may call `destroy()` to close open connections. + +```js +// a client can be shared by different commands. +const client = new BedrockRuntimeClient({ region: "REGION" }); + +const params = { + /** input parameters */ +}; +const command = new InvokeModelCommand(params); +``` + +#### Async/await + +We recommend using [await](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await) +operator to wait for the promise returned by send operation as follows: + +```js +// async/await. +try { + const data = await client.send(command); + // process data. +} catch (error) { + // error handling. +} finally { + // finally. +} +``` + +Async-await is clean, concise, intuitive, easy to debug and has better error handling +as compared to using Promise chains or callbacks. + +#### Promises + +You can also use [Promise chaining](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises#chaining) +to execute send operation. + +```js +client.send(command).then( + (data) => { + // process data. + }, + (error) => { + // error handling. + } +); +``` + +Promises can also be called using `.catch()` and `.finally()` as follows: + +```js +client + .send(command) + .then((data) => { + // process data. + }) + .catch((error) => { + // error handling. + }) + .finally(() => { + // finally. + }); +``` + +#### Callbacks + +We do not recommend using callbacks because of [callback hell](http://callbackhell.com/), +but they are supported by the send operation. + +```js +// callbacks. +client.send(command, (err, data) => { + // process err and data. +}); +``` + +#### v2 compatible style + +The client can also send requests using v2 compatible style. +However, it results in a bigger bundle size and may be dropped in next major version. More details in the blog post +on [modular packages in AWS SDK for JavaScript](https://aws.amazon.com/blogs/developer/modular-packages-in-aws-sdk-for-javascript/) + +```ts +import * as AWS from "@aws-sdk/client-bedrock-runtime"; +const client = new AWS.BedrockRuntime({ region: "REGION" }); + +// async/await. +try { + const data = await client.invokeModel(params); + // process data. +} catch (error) { + // error handling. +} + +// Promises. +client + .invokeModel(params) + .then((data) => { + // process data. + }) + .catch((error) => { + // error handling. + }); + +// callbacks. +client.invokeModel(params, (err, data) => { + // process err and data. +}); +``` + +### Troubleshooting + +When the service returns an exception, the error will include the exception information, +as well as response metadata (e.g. request id). + +```js +try { + const data = await client.send(command); + // process data. +} catch (error) { + const { requestId, cfId, extendedRequestId } = error.$$metadata; + console.log({ requestId, cfId, extendedRequestId }); + /** + * The keys within exceptions are also parsed. + * You can access them by specifying exception names: + * if (error.name === 'SomeServiceException') { + * const value = error.specialKeyInException; + * } + */ +} +``` + +## Getting Help + +Please use these community resources for getting help. +We use the GitHub issues for tracking bugs and feature requests, but have limited bandwidth to address them. + +- Visit [Developer Guide](https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/welcome.html) + or [API Reference](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/index.html). +- Check out the blog posts tagged with [`aws-sdk-js`](https://aws.amazon.com/blogs/developer/tag/aws-sdk-js/) + on AWS Developer Blog. +- Ask a question on [StackOverflow](https://stackoverflow.com/questions/tagged/aws-sdk-js) and tag it with `aws-sdk-js`. +- Join the AWS JavaScript community on [gitter](https://gitter.im/aws/aws-sdk-js-v3). +- If it turns out that you may have found a bug, please [open an issue](https://github.com/aws/aws-sdk-js-v3/issues/new/choose). + +To test your universal JavaScript code in Node.js, browser and react-native environments, +visit our [code samples repo](https://github.com/aws-samples/aws-sdk-js-tests). + +## Contributing + +This client code is generated automatically. Any modifications will be overwritten the next time the `@aws-sdk/client-bedrock-runtime` package is updated. +To contribute to client you can check our [generate clients scripts](https://github.com/aws/aws-sdk-js-v3/tree/main/scripts/generate-clients). + +## License + +This SDK is distributed under the +[Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0), +see LICENSE for more information. + +## Client Commands (Operations List) + +Describes the API operations for running inference using Bedrock models.
+ */ +export class BedrockRuntime extends BedrockRuntimeClient implements BedrockRuntime {} +createAggregatedClient(commands, BedrockRuntime); diff --git a/clients/client-bedrock-runtime/src/BedrockRuntimeClient.ts b/clients/client-bedrock-runtime/src/BedrockRuntimeClient.ts new file mode 100644 index 0000000000000..819d5f128f636 --- /dev/null +++ b/clients/client-bedrock-runtime/src/BedrockRuntimeClient.ts @@ -0,0 +1,305 @@ +// smithy-typescript generated code +import { + getHostHeaderPlugin, + HostHeaderInputConfig, + HostHeaderResolvedConfig, + resolveHostHeaderConfig, +} from "@aws-sdk/middleware-host-header"; +import { getLoggerPlugin } from "@aws-sdk/middleware-logger"; +import { getRecursionDetectionPlugin } from "@aws-sdk/middleware-recursion-detection"; +import { + AwsAuthInputConfig, + AwsAuthResolvedConfig, + getAwsAuthPlugin, + resolveAwsAuthConfig, +} from "@aws-sdk/middleware-signing"; +import { + getUserAgentPlugin, + resolveUserAgentConfig, + UserAgentInputConfig, + UserAgentResolvedConfig, +} from "@aws-sdk/middleware-user-agent"; +import { Credentials as __Credentials } from "@aws-sdk/types"; +import { RegionInputConfig, RegionResolvedConfig, resolveRegionConfig } from "@smithy/config-resolver"; +import { + EventStreamSerdeInputConfig, + EventStreamSerdeResolvedConfig, + resolveEventStreamSerdeConfig, +} from "@smithy/eventstream-serde-config-resolver"; +import { getContentLengthPlugin } from "@smithy/middleware-content-length"; +import { EndpointInputConfig, EndpointResolvedConfig, resolveEndpointConfig } from "@smithy/middleware-endpoint"; +import { getRetryPlugin, resolveRetryConfig, RetryInputConfig, RetryResolvedConfig } from "@smithy/middleware-retry"; +import { HttpHandler as __HttpHandler } from "@smithy/protocol-http"; +import { + Client as __Client, + DefaultsMode as __DefaultsMode, + SmithyConfiguration as __SmithyConfiguration, + SmithyResolvedConfiguration as __SmithyResolvedConfiguration, +} from "@smithy/smithy-client"; +import { + BodyLengthCalculator as __BodyLengthCalculator, + CheckOptionalClientConfig as __CheckOptionalClientConfig, + Checksum as __Checksum, + ChecksumConstructor as __ChecksumConstructor, + Decoder as __Decoder, + Encoder as __Encoder, + EndpointV2 as __EndpointV2, + EventStreamSerdeProvider as __EventStreamSerdeProvider, + Hash as __Hash, + HashConstructor as __HashConstructor, + HttpHandlerOptions as __HttpHandlerOptions, + Logger as __Logger, + Provider as __Provider, + Provider, + StreamCollector as __StreamCollector, + UrlParser as __UrlParser, + UserAgent as __UserAgent, +} from "@smithy/types"; + +import { InvokeModelCommandInput, InvokeModelCommandOutput } from "./commands/InvokeModelCommand"; +import { + InvokeModelWithResponseStreamCommandInput, + InvokeModelWithResponseStreamCommandOutput, +} from "./commands/InvokeModelWithResponseStreamCommand"; +import { + ClientInputEndpointParameters, + ClientResolvedEndpointParameters, + EndpointParameters, + resolveClientEndpointParameters, +} from "./endpoint/EndpointParameters"; +import { getRuntimeConfig as __getRuntimeConfig } from "./runtimeConfig"; +import { resolveRuntimeExtensions, RuntimeExtension, RuntimeExtensionsConfig } from "./runtimeExtensions"; + +export { __Client }; + +/** + * @public + */ +export type ServiceInputTypes = InvokeModelCommandInput | InvokeModelWithResponseStreamCommandInput; + +/** + * @public + */ +export type ServiceOutputTypes = InvokeModelCommandOutput | InvokeModelWithResponseStreamCommandOutput; + +/** + * @public + */ +export interface ClientDefaults extends Partial<__SmithyResolvedConfiguration<__HttpHandlerOptions>> { + /** + * The HTTP handler to use. Fetch in browser and Https in Nodejs. + */ + requestHandler?: __HttpHandler; + + /** + * A constructor for a class implementing the {@link @smithy/types#ChecksumConstructor} interface + * that computes the SHA-256 HMAC or checksum of a string or binary buffer. + * @internal + */ + sha256?: __ChecksumConstructor | __HashConstructor; + + /** + * The function that will be used to convert strings into HTTP endpoints. + * @internal + */ + urlParser?: __UrlParser; + + /** + * A function that can calculate the length of a request body. + * @internal + */ + bodyLengthChecker?: __BodyLengthCalculator; + + /** + * A function that converts a stream into an array of bytes. + * @internal + */ + streamCollector?: __StreamCollector; + + /** + * The function that will be used to convert a base64-encoded string to a byte array. + * @internal + */ + base64Decoder?: __Decoder; + + /** + * The function that will be used to convert binary data to a base64-encoded string. + * @internal + */ + base64Encoder?: __Encoder; + + /** + * The function that will be used to convert a UTF8-encoded string to a byte array. + * @internal + */ + utf8Decoder?: __Decoder; + + /** + * The function that will be used to convert binary data to a UTF-8 encoded string. + * @internal + */ + utf8Encoder?: __Encoder; + + /** + * The runtime environment. + * @internal + */ + runtime?: string; + + /** + * Disable dynamically changing the endpoint of the client based on the hostPrefix + * trait of an operation. + */ + disableHostPrefix?: boolean; + + /** + * Unique service identifier. + * @internal + */ + serviceId?: string; + + /** + * Enables IPv6/IPv4 dualstack endpoint. + */ + useDualstackEndpoint?: boolean | __ProviderDescribes the API operations for running inference using Bedrock models.
+ */ +export class BedrockRuntimeClient extends __Client< + __HttpHandlerOptions, + ServiceInputTypes, + ServiceOutputTypes, + BedrockRuntimeClientResolvedConfig +> { + /** + * The resolved configuration of BedrockRuntimeClient class. This is resolved and normalized from the {@link BedrockRuntimeClientConfig | constructor configuration interface}. + */ + readonly config: BedrockRuntimeClientResolvedConfig; + + constructor(...[configuration]: __CheckOptionalClientConfigInvokes the specified Bedrock model to run inference using the input provided in the request body. + * You use InvokeModel to run inference for text models, image models, and embedding models.
+ *For more information about invoking models, see Using the API in the Bedrock User Guide.
+ *For example requests, see Examples (after the Errors section).
+ * @example + * Use a bare-bones client and the command you need to make an API call. + * ```javascript + * import { BedrockRuntimeClient, InvokeModelCommand } from "@aws-sdk/client-bedrock-runtime"; // ES Modules import + * // const { BedrockRuntimeClient, InvokeModelCommand } = require("@aws-sdk/client-bedrock-runtime"); // CommonJS import + * const client = new BedrockRuntimeClient(config); + * const input = { // InvokeModelRequest + * body: "BLOB_VALUE", // required + * contentType: "STRING_VALUE", + * accept: "STRING_VALUE", + * modelId: "STRING_VALUE", // required + * }; + * const command = new InvokeModelCommand(input); + * const response = await client.send(command); + * // { // InvokeModelResponse + * // body: "BLOB_VALUE", // required + * // contentType: "STRING_VALUE", // required + * // }; + * + * ``` + * + * @param InvokeModelCommandInput - {@link InvokeModelCommandInput} + * @returns {@link InvokeModelCommandOutput} + * @see {@link InvokeModelCommandInput} for command's `input` shape. + * @see {@link InvokeModelCommandOutput} for command's `response` shape. + * @see {@link BedrockRuntimeClientResolvedConfig | config} for BedrockRuntimeClient's `config` shape. + * + * @throws {@link AccessDeniedException} (client fault) + *The request is denied because of missing access permissions.
+ * + * @throws {@link InternalServerException} (server fault) + *An internal server error occurred. Retry your request.
+ * + * @throws {@link ModelErrorException} (client fault) + *The request failed due to an error while processing the model.
+ * + * @throws {@link ModelNotReadyException} (client fault) + *The model specified in the request is not ready to serve inference requests.
+ * + * @throws {@link ModelTimeoutException} (client fault) + *The request took too long to process. Processing time exceeded the model timeout length.
+ * + * @throws {@link ResourceNotFoundException} (client fault) + *The specified resource ARN was not found. Check the ARN and try your request again.
+ * + * @throws {@link ServiceQuotaExceededException} (client fault) + *The number of requests exceeds the service quota. Resubmit your request later.
+ * + * @throws {@link ThrottlingException} (client fault) + *The number of requests exceeds the limit. Resubmit your request later.
+ * + * @throws {@link ValidationException} (client fault) + *Input validation failed. Check your request parameters and retry the request.
+ * + * @throws {@link BedrockRuntimeServiceException} + *Base exception class for all service exceptions from BedrockRuntime service.
+ * + */ +export class InvokeModelCommand extends $Command< + InvokeModelCommandInput, + InvokeModelCommandOutput, + BedrockRuntimeClientResolvedConfig +> { + // Start section: command_properties + // End section: command_properties + + public static getEndpointParameterInstructions(): EndpointParameterInstructions { + return { + UseFIPS: { type: "builtInParams", name: "useFipsEndpoint" }, + Endpoint: { type: "builtInParams", name: "endpoint" }, + Region: { type: "builtInParams", name: "region" }, + UseDualStack: { type: "builtInParams", name: "useDualstackEndpoint" }, + }; + } + + /** + * @public + */ + constructor(readonly input: InvokeModelCommandInput) { + // Start section: command_constructor + super(); + // End section: command_constructor + } + + /** + * @internal + */ + resolveMiddleware( + clientStack: MiddlewareStackInvoke the specified Bedrock model to run inference using the input provided. + * Return the response in a stream.
+ *For more information about invoking models, see Using the API in the Bedrock User Guide.
+ *For an example request and response, see Examples (after the Errors section).
+ * @example + * Use a bare-bones client and the command you need to make an API call. + * ```javascript + * import { BedrockRuntimeClient, InvokeModelWithResponseStreamCommand } from "@aws-sdk/client-bedrock-runtime"; // ES Modules import + * // const { BedrockRuntimeClient, InvokeModelWithResponseStreamCommand } = require("@aws-sdk/client-bedrock-runtime"); // CommonJS import + * const client = new BedrockRuntimeClient(config); + * const input = { // InvokeModelWithResponseStreamRequest + * body: "BLOB_VALUE", // required + * contentType: "STRING_VALUE", + * accept: "STRING_VALUE", + * modelId: "STRING_VALUE", // required + * }; + * const command = new InvokeModelWithResponseStreamCommand(input); + * const response = await client.send(command); + * // { // InvokeModelWithResponseStreamResponse + * // body: { // ResponseStream Union: only one key present + * // chunk: { // PayloadPart + * // bytes: "BLOB_VALUE", + * // }, + * // internalServerException: { // InternalServerException + * // message: "STRING_VALUE", + * // }, + * // modelStreamErrorException: { // ModelStreamErrorException + * // message: "STRING_VALUE", + * // originalStatusCode: Number("int"), + * // originalMessage: "STRING_VALUE", + * // }, + * // validationException: { // ValidationException + * // message: "STRING_VALUE", + * // }, + * // throttlingException: { // ThrottlingException + * // message: "STRING_VALUE", + * // }, + * // }, + * // contentType: "STRING_VALUE", // required + * // }; + * + * ``` + * + * @param InvokeModelWithResponseStreamCommandInput - {@link InvokeModelWithResponseStreamCommandInput} + * @returns {@link InvokeModelWithResponseStreamCommandOutput} + * @see {@link InvokeModelWithResponseStreamCommandInput} for command's `input` shape. + * @see {@link InvokeModelWithResponseStreamCommandOutput} for command's `response` shape. + * @see {@link BedrockRuntimeClientResolvedConfig | config} for BedrockRuntimeClient's `config` shape. + * + * @throws {@link AccessDeniedException} (client fault) + *The request is denied because of missing access permissions.
+ * + * @throws {@link InternalServerException} (server fault) + *An internal server error occurred. Retry your request.
+ * + * @throws {@link ModelErrorException} (client fault) + *The request failed due to an error while processing the model.
+ * + * @throws {@link ModelNotReadyException} (client fault) + *The model specified in the request is not ready to serve inference requests.
+ * + * @throws {@link ModelStreamErrorException} (client fault) + *An error occurred while streaming the response.
+ * + * @throws {@link ModelTimeoutException} (client fault) + *The request took too long to process. Processing time exceeded the model timeout length.
+ * + * @throws {@link ResourceNotFoundException} (client fault) + *The specified resource ARN was not found. Check the ARN and try your request again.
+ * + * @throws {@link ServiceQuotaExceededException} (client fault) + *The number of requests exceeds the service quota. Resubmit your request later.
+ * + * @throws {@link ThrottlingException} (client fault) + *The number of requests exceeds the limit. Resubmit your request later.
+ * + * @throws {@link ValidationException} (client fault) + *Input validation failed. Check your request parameters and retry the request.
+ * + * @throws {@link BedrockRuntimeServiceException} + *Base exception class for all service exceptions from BedrockRuntime service.
+ * + */ +export class InvokeModelWithResponseStreamCommand extends $Command< + InvokeModelWithResponseStreamCommandInput, + InvokeModelWithResponseStreamCommandOutput, + BedrockRuntimeClientResolvedConfig +> { + // Start section: command_properties + // End section: command_properties + + public static getEndpointParameterInstructions(): EndpointParameterInstructions { + return { + UseFIPS: { type: "builtInParams", name: "useFipsEndpoint" }, + Endpoint: { type: "builtInParams", name: "endpoint" }, + Region: { type: "builtInParams", name: "region" }, + UseDualStack: { type: "builtInParams", name: "useDualstackEndpoint" }, + }; + } + + /** + * @public + */ + constructor(readonly input: InvokeModelWithResponseStreamCommandInput) { + // Start section: command_constructor + super(); + // End section: command_constructor + } + + /** + * @internal + */ + resolveMiddleware( + clientStack: MiddlewareStackDescribes the API operations for running inference using Bedrock models.
+ * + * @packageDocumentation + */ +export * from "./BedrockRuntimeClient"; +export * from "./BedrockRuntime"; +export { ClientInputEndpointParameters } from "./endpoint/EndpointParameters"; +export * from "./commands"; +export * from "./models"; + +export { BedrockRuntimeServiceException } from "./models/BedrockRuntimeServiceException"; diff --git a/clients/client-bedrock-runtime/src/models/BedrockRuntimeServiceException.ts b/clients/client-bedrock-runtime/src/models/BedrockRuntimeServiceException.ts new file mode 100644 index 0000000000000..59f81e38a5416 --- /dev/null +++ b/clients/client-bedrock-runtime/src/models/BedrockRuntimeServiceException.ts @@ -0,0 +1,22 @@ +// smithy-typescript generated code +import { + ServiceException as __ServiceException, + ServiceExceptionOptions as __ServiceExceptionOptions, +} from "@smithy/smithy-client"; + +export { __ServiceException, __ServiceExceptionOptions }; + +/** + * @public + * + * Base exception class for all service exceptions from BedrockRuntime service. + */ +export class BedrockRuntimeServiceException extends __ServiceException { + /** + * @internal + */ + constructor(options: __ServiceExceptionOptions) { + super(options); + Object.setPrototypeOf(this, BedrockRuntimeServiceException.prototype); + } +} diff --git a/clients/client-bedrock-runtime/src/models/index.ts b/clients/client-bedrock-runtime/src/models/index.ts new file mode 100644 index 0000000000000..9eaceb12865f8 --- /dev/null +++ b/clients/client-bedrock-runtime/src/models/index.ts @@ -0,0 +1,2 @@ +// smithy-typescript generated code +export * from "./models_0"; diff --git a/clients/client-bedrock-runtime/src/models/models_0.ts b/clients/client-bedrock-runtime/src/models/models_0.ts new file mode 100644 index 0000000000000..2196b6942119a --- /dev/null +++ b/clients/client-bedrock-runtime/src/models/models_0.ts @@ -0,0 +1,511 @@ +// smithy-typescript generated code +import { ExceptionOptionType as __ExceptionOptionType, SENSITIVE_STRING } from "@smithy/smithy-client"; + +import { BedrockRuntimeServiceException as __BaseException } from "./BedrockRuntimeServiceException"; + +/** + * @public + *The request is denied because of missing access permissions.
+ */ +export class AccessDeniedException extends __BaseException { + readonly name: "AccessDeniedException" = "AccessDeniedException"; + readonly $fault: "client" = "client"; + /** + * @internal + */ + constructor(opts: __ExceptionOptionTypeAn internal server error occurred. Retry your request.
+ */ +export class InternalServerException extends __BaseException { + readonly name: "InternalServerException" = "InternalServerException"; + readonly $fault: "server" = "server"; + /** + * @internal + */ + constructor(opts: __ExceptionOptionTypeInput 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 Inference parameters.
+ */ + body: Uint8Array | undefined; + + /** + * @public + *The MIME type of the input data in the request. The default value is
+ * application/json
.
The desired MIME type of the inference body in the response. The default value is
+ * application/json
.
Identifier of the model.
+ */ + modelId: string | undefined; +} + +/** + * @public + */ +export interface InvokeModelResponse { + /** + * @public + *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 Inference parameters.
+ */ + body: Uint8Array | undefined; + + /** + * @public + *The MIME type of the inference result.
+ */ + contentType: string | undefined; +} + +/** + * @public + *The request failed due to an error while processing the model.
+ */ +export class ModelErrorException extends __BaseException { + readonly name: "ModelErrorException" = "ModelErrorException"; + readonly $fault: "client" = "client"; + /** + * @public + *The original status code.
+ */ + originalStatusCode?: number; + + /** + * @public + *The resource name.
+ */ + resourceName?: string; + + /** + * @internal + */ + constructor(opts: __ExceptionOptionTypeThe model specified in the request is not ready to serve inference requests.
+ */ +export class ModelNotReadyException extends __BaseException { + readonly name: "ModelNotReadyException" = "ModelNotReadyException"; + readonly $fault: "client" = "client"; + /** + * @internal + */ + constructor(opts: __ExceptionOptionTypeThe request took too long to process. Processing time exceeded the model timeout length.
+ */ +export class ModelTimeoutException extends __BaseException { + readonly name: "ModelTimeoutException" = "ModelTimeoutException"; + readonly $fault: "client" = "client"; + /** + * @internal + */ + constructor(opts: __ExceptionOptionTypeThe specified resource ARN was not found. Check the ARN and try your request again.
+ */ +export class ResourceNotFoundException extends __BaseException { + readonly name: "ResourceNotFoundException" = "ResourceNotFoundException"; + readonly $fault: "client" = "client"; + /** + * @internal + */ + constructor(opts: __ExceptionOptionTypeThe number of requests exceeds the service quota. Resubmit your request later.
+ */ +export class ServiceQuotaExceededException extends __BaseException { + readonly name: "ServiceQuotaExceededException" = "ServiceQuotaExceededException"; + readonly $fault: "client" = "client"; + /** + * @internal + */ + constructor(opts: __ExceptionOptionTypeThe number of requests exceeds the limit. Resubmit your request later.
+ */ +export class ThrottlingException extends __BaseException { + readonly name: "ThrottlingException" = "ThrottlingException"; + readonly $fault: "client" = "client"; + /** + * @internal + */ + constructor(opts: __ExceptionOptionTypeInput validation failed. Check your request parameters and retry the request.
+ */ +export class ValidationException extends __BaseException { + readonly name: "ValidationException" = "ValidationException"; + readonly $fault: "client" = "client"; + /** + * @internal + */ + constructor(opts: __ExceptionOptionTypeInference input in the format specified by the + * content-type. To see the format and content of this field for different models, refer to Inference parameters.
+ */ + body: Uint8Array | undefined; + + /** + * @public + *The MIME type of the input data in the request. The default value is
+ * application/json
.
The desired MIME type of the inference body in the response. The default value is
+ * application/json
.
Id of the model to invoke using the streaming request.
+ */ + modelId: string | undefined; +} + +/** + * @public + *Payload content included in the response.
+ */ +export interface PayloadPart { + /** + * @public + *Base64-encoded bytes of payload data.
+ */ + bytes?: Uint8Array; +} + +/** + * @public + *An error occurred while streaming the response.
+ */ +export class ModelStreamErrorException extends __BaseException { + readonly name: "ModelStreamErrorException" = "ModelStreamErrorException"; + readonly $fault: "client" = "client"; + /** + * @public + *The original status code.
+ */ + originalStatusCode?: number; + + /** + * @public + *The original message.
+ */ + originalMessage?: string; + + /** + * @internal + */ + constructor(opts: __ExceptionOptionTypeDefinition of content in the response stream.
+ */ +export type ResponseStream = + | ResponseStream.ChunkMember + | ResponseStream.InternalServerExceptionMember + | ResponseStream.ModelStreamErrorExceptionMember + | ResponseStream.ThrottlingExceptionMember + | ResponseStream.ValidationExceptionMember + | ResponseStream.$UnknownMember; + +/** + * @public + */ +export namespace ResponseStream { + /** + * @public + *Content included in the response.
+ */ + export interface ChunkMember { + chunk: PayloadPart; + internalServerException?: never; + modelStreamErrorException?: never; + validationException?: never; + throttlingException?: never; + $unknown?: never; + } + + /** + * @public + *An internal server error occurred. Retry your request.
+ */ + export interface InternalServerExceptionMember { + chunk?: never; + internalServerException: InternalServerException; + modelStreamErrorException?: never; + validationException?: never; + throttlingException?: never; + $unknown?: never; + } + + /** + * @public + *An error occurred while streaming the response.
+ */ + export interface ModelStreamErrorExceptionMember { + chunk?: never; + internalServerException?: never; + modelStreamErrorException: ModelStreamErrorException; + validationException?: never; + throttlingException?: never; + $unknown?: never; + } + + /** + * @public + *Input validation failed. Check your request parameters and retry the request.
+ */ + export interface ValidationExceptionMember { + chunk?: never; + internalServerException?: never; + modelStreamErrorException?: never; + validationException: ValidationException; + throttlingException?: never; + $unknown?: never; + } + + /** + * @public + *The number of requests exceeds the limit. Resubmit your request later.
+ */ + export interface ThrottlingExceptionMember { + chunk?: never; + internalServerException?: never; + modelStreamErrorException?: never; + validationException?: never; + throttlingException: ThrottlingException; + $unknown?: never; + } + + /** + * @public + */ + export interface $UnknownMember { + chunk?: never; + internalServerException?: never; + modelStreamErrorException?: never; + validationException?: never; + throttlingException?: never; + $unknown: [string, any]; + } + + export interface VisitorInference 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 Inference parameters.
+ */ + body: AsyncIterableThe MIME type of the inference result.
+ */ + contentType: string | undefined; +} + +/** + * @internal + */ +export const InvokeModelRequestFilterSensitiveLog = (obj: InvokeModelRequest): any => ({ + ...obj, + ...(obj.body && { body: SENSITIVE_STRING }), +}); + +/** + * @internal + */ +export const InvokeModelResponseFilterSensitiveLog = (obj: InvokeModelResponse): any => ({ + ...obj, + ...(obj.body && { body: SENSITIVE_STRING }), +}); + +/** + * @internal + */ +export const InvokeModelWithResponseStreamRequestFilterSensitiveLog = ( + obj: InvokeModelWithResponseStreamRequest +): any => ({ + ...obj, + ...(obj.body && { body: SENSITIVE_STRING }), +}); + +/** + * @internal + */ +export const PayloadPartFilterSensitiveLog = (obj: PayloadPart): any => ({ + ...obj, + ...(obj.bytes && { bytes: SENSITIVE_STRING }), +}); + +/** + * @internal + */ +export const ResponseStreamFilterSensitiveLog = (obj: ResponseStream): any => { + if (obj.chunk !== undefined) return { chunk: SENSITIVE_STRING }; + if (obj.internalServerException !== undefined) return { internalServerException: obj.internalServerException }; + if (obj.modelStreamErrorException !== undefined) return { modelStreamErrorException: obj.modelStreamErrorException }; + if (obj.validationException !== undefined) return { validationException: obj.validationException }; + if (obj.throttlingException !== undefined) return { throttlingException: obj.throttlingException }; + if (obj.$unknown !== undefined) return { [obj.$unknown[0]]: "UNKNOWN" }; +}; + +/** + * @internal + */ +export const InvokeModelWithResponseStreamResponseFilterSensitiveLog = ( + obj: InvokeModelWithResponseStreamResponse +): any => ({ + ...obj, + ...(obj.body && { body: "STREAMING_CONTENT" }), +}); diff --git a/clients/client-bedrock-runtime/src/protocols/Aws_restJson1.ts b/clients/client-bedrock-runtime/src/protocols/Aws_restJson1.ts new file mode 100644 index 0000000000000..7f6332d488371 --- /dev/null +++ b/clients/client-bedrock-runtime/src/protocols/Aws_restJson1.ts @@ -0,0 +1,595 @@ +// smithy-typescript generated code +import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; +import { + _json, + collectBody, + decorateServiceException as __decorateServiceException, + expectInt32 as __expectInt32, + expectString as __expectString, + map, + resolvedPath as __resolvedPath, + take, + withBaseException, +} from "@smithy/smithy-client"; +import { + Endpoint as __Endpoint, + EventStreamSerdeContext as __EventStreamSerdeContext, + ResponseMetadata as __ResponseMetadata, + SerdeContext as __SerdeContext, +} from "@smithy/types"; + +import { InvokeModelCommandInput, InvokeModelCommandOutput } from "../commands/InvokeModelCommand"; +import { + InvokeModelWithResponseStreamCommandInput, + InvokeModelWithResponseStreamCommandOutput, +} from "../commands/InvokeModelWithResponseStreamCommand"; +import { BedrockRuntimeServiceException as __BaseException } from "../models/BedrockRuntimeServiceException"; +import { + AccessDeniedException, + InternalServerException, + ModelErrorException, + ModelNotReadyException, + ModelStreamErrorException, + ModelTimeoutException, + PayloadPart, + ResourceNotFoundException, + ResponseStream, + ServiceQuotaExceededException, + ThrottlingException, + ValidationException, +} from "../models/models_0"; + +/** + * serializeAws_restJson1InvokeModelCommand + */ +export const se_InvokeModelCommand = async ( + input: InvokeModelCommandInput, + context: __SerdeContext +): Promise<__HttpRequest> => { + const { hostname, protocol = "https", port, path: basePath } = await context.endpoint(); + const headers: any = map({}, isSerializableHeaderValue, { + "content-type": input.contentType! || "application/octet-stream", + accept: input.accept!, + }); + let resolvedPath = `${basePath?.endsWith("/") ? basePath.slice(0, -1) : basePath || ""}` + "/model/{modelId}/invoke"; + resolvedPath = __resolvedPath(resolvedPath, input, "modelId", () => input.modelId!, "{modelId}", false); + let body: any; + if (input.body !== undefined) { + body = input.body; + } + return new __HttpRequest({ + protocol, + hostname, + port, + method: "POST", + headers, + path: resolvedPath, + body, + }); +}; + +/** + * serializeAws_restJson1InvokeModelWithResponseStreamCommand + */ +export const se_InvokeModelWithResponseStreamCommand = async ( + input: InvokeModelWithResponseStreamCommandInput, + context: __SerdeContext +): Promise<__HttpRequest> => { + const { hostname, protocol = "https", port, path: basePath } = await context.endpoint(); + const headers: any = map({}, isSerializableHeaderValue, { + "content-type": input.contentType! || "application/octet-stream", + "x-amzn-bedrock-accept": input.accept!, + }); + let resolvedPath = + `${basePath?.endsWith("/") ? basePath.slice(0, -1) : basePath || ""}` + + "/model/{modelId}/invoke-with-response-stream"; + resolvedPath = __resolvedPath(resolvedPath, input, "modelId", () => input.modelId!, "{modelId}", false); + let body: any; + if (input.body !== undefined) { + body = input.body; + } + return new __HttpRequest({ + protocol, + hostname, + port, + method: "POST", + headers, + path: resolvedPath, + body, + }); +}; + +/** + * deserializeAws_restJson1InvokeModelCommand + */ +export const de_InvokeModelCommand = async ( + output: __HttpResponse, + context: __SerdeContext +): PromiseThe request is denied because of missing access permissions.
", + "smithy.api#error": "client", + "smithy.api#httpError": 403 + } + }, + "com.amazonaws.bedrockruntime#AmazonBedrockFrontendService": { + "type": "service", + "version": "2023-09-30", + "resources": [ + { + "target": "com.amazonaws.bedrockruntime#InferenceResource" + } + ], + "traits": { + "aws.api#service": { + "sdkId": "Bedrock Runtime", + "endpointPrefix": "bedrock-runtime", + "cloudTrailEventSource": "bedrock.amazonaws.com" + }, + "aws.auth#sigv4": { + "name": "bedrock" + }, + "aws.protocols#restJson1": {}, + "smithy.api#documentation": "Describes the API operations for running inference using Bedrock models.
", + "smithy.api#title": "Amazon Bedrock Runtime", + "smithy.rules#endpointRuleSet": { + "version": "1.0", + "parameters": { + "Region": { + "builtIn": "AWS::Region", + "required": false, + "documentation": "The AWS region used to dispatch the request.", + "type": "String" + }, + "UseDualStack": { + "builtIn": "AWS::UseDualStack", + "required": true, + "default": false, + "documentation": "When true, use the dual-stack endpoint. If the configured endpoint does not support dual-stack, dispatching the request MAY return an error.", + "type": "Boolean" + }, + "UseFIPS": { + "builtIn": "AWS::UseFIPS", + "required": true, + "default": false, + "documentation": "When true, send this request to the FIPS-compliant regional endpoint. If the configured endpoint does not have a FIPS compliant endpoint, dispatching the request will return an error.", + "type": "Boolean" + }, + "Endpoint": { + "builtIn": "SDK::Endpoint", + "required": false, + "documentation": "Override the endpoint used to send this request", + "type": "String" + } + }, + "rules": [ + { + "conditions": [ + { + "fn": "isSet", + "argv": [ + { + "ref": "Endpoint" + } + ] + } + ], + "type": "tree", + "rules": [ + { + "conditions": [ + { + "fn": "booleanEquals", + "argv": [ + { + "ref": "UseFIPS" + }, + true + ] + } + ], + "error": "Invalid Configuration: FIPS and custom endpoint are not supported", + "type": "error" + }, + { + "conditions": [], + "type": "tree", + "rules": [ + { + "conditions": [ + { + "fn": "booleanEquals", + "argv": [ + { + "ref": "UseDualStack" + }, + true + ] + } + ], + "error": "Invalid Configuration: Dualstack and custom endpoint are not supported", + "type": "error" + }, + { + "conditions": [], + "endpoint": { + "url": { + "ref": "Endpoint" + }, + "properties": {}, + "headers": {} + }, + "type": "endpoint" + } + ] + } + ] + }, + { + "conditions": [], + "type": "tree", + "rules": [ + { + "conditions": [ + { + "fn": "isSet", + "argv": [ + { + "ref": "Region" + } + ] + } + ], + "type": "tree", + "rules": [ + { + "conditions": [ + { + "fn": "aws.partition", + "argv": [ + { + "ref": "Region" + } + ], + "assign": "PartitionResult" + } + ], + "type": "tree", + "rules": [ + { + "conditions": [ + { + "fn": "booleanEquals", + "argv": [ + { + "ref": "UseFIPS" + }, + true + ] + }, + { + "fn": "booleanEquals", + "argv": [ + { + "ref": "UseDualStack" + }, + true + ] + } + ], + "type": "tree", + "rules": [ + { + "conditions": [ + { + "fn": "booleanEquals", + "argv": [ + true, + { + "fn": "getAttr", + "argv": [ + { + "ref": "PartitionResult" + }, + "supportsFIPS" + ] + } + ] + }, + { + "fn": "booleanEquals", + "argv": [ + true, + { + "fn": "getAttr", + "argv": [ + { + "ref": "PartitionResult" + }, + "supportsDualStack" + ] + } + ] + } + ], + "type": "tree", + "rules": [ + { + "conditions": [], + "type": "tree", + "rules": [ + { + "conditions": [], + "endpoint": { + "url": "https://bedrock-runtime-fips.{Region}.{PartitionResult#dualStackDnsSuffix}", + "properties": {}, + "headers": {} + }, + "type": "endpoint" + } + ] + } + ] + }, + { + "conditions": [], + "error": "FIPS and DualStack are enabled, but this partition does not support one or both", + "type": "error" + } + ] + }, + { + "conditions": [ + { + "fn": "booleanEquals", + "argv": [ + { + "ref": "UseFIPS" + }, + true + ] + } + ], + "type": "tree", + "rules": [ + { + "conditions": [ + { + "fn": "booleanEquals", + "argv": [ + true, + { + "fn": "getAttr", + "argv": [ + { + "ref": "PartitionResult" + }, + "supportsFIPS" + ] + } + ] + } + ], + "type": "tree", + "rules": [ + { + "conditions": [], + "type": "tree", + "rules": [ + { + "conditions": [], + "endpoint": { + "url": "https://bedrock-runtime-fips.{Region}.{PartitionResult#dnsSuffix}", + "properties": {}, + "headers": {} + }, + "type": "endpoint" + } + ] + } + ] + }, + { + "conditions": [], + "error": "FIPS is enabled but this partition does not support FIPS", + "type": "error" + } + ] + }, + { + "conditions": [ + { + "fn": "booleanEquals", + "argv": [ + { + "ref": "UseDualStack" + }, + true + ] + } + ], + "type": "tree", + "rules": [ + { + "conditions": [ + { + "fn": "booleanEquals", + "argv": [ + true, + { + "fn": "getAttr", + "argv": [ + { + "ref": "PartitionResult" + }, + "supportsDualStack" + ] + } + ] + } + ], + "type": "tree", + "rules": [ + { + "conditions": [], + "type": "tree", + "rules": [ + { + "conditions": [], + "endpoint": { + "url": "https://bedrock-runtime.{Region}.{PartitionResult#dualStackDnsSuffix}", + "properties": {}, + "headers": {} + }, + "type": "endpoint" + } + ] + } + ] + }, + { + "conditions": [], + "error": "DualStack is enabled but this partition does not support DualStack", + "type": "error" + } + ] + }, + { + "conditions": [], + "type": "tree", + "rules": [ + { + "conditions": [], + "endpoint": { + "url": "https://bedrock-runtime.{Region}.{PartitionResult#dnsSuffix}", + "properties": {}, + "headers": {} + }, + "type": "endpoint" + } + ] + } + ] + } + ] + }, + { + "conditions": [], + "error": "Invalid Configuration: Missing Region", + "type": "error" + } + ] + } + ] + }, + "smithy.rules#endpointTests": { + "testCases": [ + { + "documentation": "For region us-east-1 with FIPS enabled and DualStack enabled", + "expect": { + "endpoint": { + "url": "https://bedrock-runtime-fips.us-east-1.api.aws" + } + }, + "params": { + "Region": "us-east-1", + "UseFIPS": true, + "UseDualStack": true + } + }, + { + "documentation": "For region us-east-1 with FIPS enabled and DualStack disabled", + "expect": { + "endpoint": { + "url": "https://bedrock-runtime-fips.us-east-1.amazonaws.com" + } + }, + "params": { + "Region": "us-east-1", + "UseFIPS": true, + "UseDualStack": false + } + }, + { + "documentation": "For region us-east-1 with FIPS disabled and DualStack enabled", + "expect": { + "endpoint": { + "url": "https://bedrock-runtime.us-east-1.api.aws" + } + }, + "params": { + "Region": "us-east-1", + "UseFIPS": false, + "UseDualStack": true + } + }, + { + "documentation": "For region us-east-1 with FIPS disabled and DualStack disabled", + "expect": { + "endpoint": { + "url": "https://bedrock-runtime.us-east-1.amazonaws.com" + } + }, + "params": { + "Region": "us-east-1", + "UseFIPS": false, + "UseDualStack": false + } + }, + { + "documentation": "For region cn-north-1 with FIPS enabled and DualStack enabled", + "expect": { + "endpoint": { + "url": "https://bedrock-runtime-fips.cn-north-1.api.amazonwebservices.com.cn" + } + }, + "params": { + "Region": "cn-north-1", + "UseFIPS": true, + "UseDualStack": true + } + }, + { + "documentation": "For region cn-north-1 with FIPS enabled and DualStack disabled", + "expect": { + "endpoint": { + "url": "https://bedrock-runtime-fips.cn-north-1.amazonaws.com.cn" + } + }, + "params": { + "Region": "cn-north-1", + "UseFIPS": true, + "UseDualStack": false + } + }, + { + "documentation": "For region cn-north-1 with FIPS disabled and DualStack enabled", + "expect": { + "endpoint": { + "url": "https://bedrock-runtime.cn-north-1.api.amazonwebservices.com.cn" + } + }, + "params": { + "Region": "cn-north-1", + "UseFIPS": false, + "UseDualStack": true + } + }, + { + "documentation": "For region cn-north-1 with FIPS disabled and DualStack disabled", + "expect": { + "endpoint": { + "url": "https://bedrock-runtime.cn-north-1.amazonaws.com.cn" + } + }, + "params": { + "Region": "cn-north-1", + "UseFIPS": false, + "UseDualStack": false + } + }, + { + "documentation": "For region us-gov-east-1 with FIPS enabled and DualStack enabled", + "expect": { + "endpoint": { + "url": "https://bedrock-runtime-fips.us-gov-east-1.api.aws" + } + }, + "params": { + "Region": "us-gov-east-1", + "UseFIPS": true, + "UseDualStack": true + } + }, + { + "documentation": "For region us-gov-east-1 with FIPS enabled and DualStack disabled", + "expect": { + "endpoint": { + "url": "https://bedrock-runtime-fips.us-gov-east-1.amazonaws.com" + } + }, + "params": { + "Region": "us-gov-east-1", + "UseFIPS": true, + "UseDualStack": false + } + }, + { + "documentation": "For region us-gov-east-1 with FIPS disabled and DualStack enabled", + "expect": { + "endpoint": { + "url": "https://bedrock-runtime.us-gov-east-1.api.aws" + } + }, + "params": { + "Region": "us-gov-east-1", + "UseFIPS": false, + "UseDualStack": true + } + }, + { + "documentation": "For region us-gov-east-1 with FIPS disabled and DualStack disabled", + "expect": { + "endpoint": { + "url": "https://bedrock-runtime.us-gov-east-1.amazonaws.com" + } + }, + "params": { + "Region": "us-gov-east-1", + "UseFIPS": false, + "UseDualStack": false + } + }, + { + "documentation": "For region us-iso-east-1 with FIPS enabled and DualStack enabled", + "expect": { + "error": "FIPS and DualStack are enabled, but this partition does not support one or both" + }, + "params": { + "Region": "us-iso-east-1", + "UseFIPS": true, + "UseDualStack": true + } + }, + { + "documentation": "For region us-iso-east-1 with FIPS enabled and DualStack disabled", + "expect": { + "endpoint": { + "url": "https://bedrock-runtime-fips.us-iso-east-1.c2s.ic.gov" + } + }, + "params": { + "Region": "us-iso-east-1", + "UseFIPS": true, + "UseDualStack": false + } + }, + { + "documentation": "For region us-iso-east-1 with FIPS disabled and DualStack enabled", + "expect": { + "error": "DualStack is enabled but this partition does not support DualStack" + }, + "params": { + "Region": "us-iso-east-1", + "UseFIPS": false, + "UseDualStack": true + } + }, + { + "documentation": "For region us-iso-east-1 with FIPS disabled and DualStack disabled", + "expect": { + "endpoint": { + "url": "https://bedrock-runtime.us-iso-east-1.c2s.ic.gov" + } + }, + "params": { + "Region": "us-iso-east-1", + "UseFIPS": false, + "UseDualStack": false + } + }, + { + "documentation": "For region us-isob-east-1 with FIPS enabled and DualStack enabled", + "expect": { + "error": "FIPS and DualStack are enabled, but this partition does not support one or both" + }, + "params": { + "Region": "us-isob-east-1", + "UseFIPS": true, + "UseDualStack": true + } + }, + { + "documentation": "For region us-isob-east-1 with FIPS enabled and DualStack disabled", + "expect": { + "endpoint": { + "url": "https://bedrock-runtime-fips.us-isob-east-1.sc2s.sgov.gov" + } + }, + "params": { + "Region": "us-isob-east-1", + "UseFIPS": true, + "UseDualStack": false + } + }, + { + "documentation": "For region us-isob-east-1 with FIPS disabled and DualStack enabled", + "expect": { + "error": "DualStack is enabled but this partition does not support DualStack" + }, + "params": { + "Region": "us-isob-east-1", + "UseFIPS": false, + "UseDualStack": true + } + }, + { + "documentation": "For region us-isob-east-1 with FIPS disabled and DualStack disabled", + "expect": { + "endpoint": { + "url": "https://bedrock-runtime.us-isob-east-1.sc2s.sgov.gov" + } + }, + "params": { + "Region": "us-isob-east-1", + "UseFIPS": false, + "UseDualStack": false + } + }, + { + "documentation": "For custom endpoint with region set and fips disabled and dualstack disabled", + "expect": { + "endpoint": { + "url": "https://example.com" + } + }, + "params": { + "Region": "us-east-1", + "UseFIPS": false, + "UseDualStack": false, + "Endpoint": "https://example.com" + } + }, + { + "documentation": "For custom endpoint with region not set and fips disabled and dualstack disabled", + "expect": { + "endpoint": { + "url": "https://example.com" + } + }, + "params": { + "UseFIPS": false, + "UseDualStack": false, + "Endpoint": "https://example.com" + } + }, + { + "documentation": "For custom endpoint with fips enabled and dualstack disabled", + "expect": { + "error": "Invalid Configuration: FIPS and custom endpoint are not supported" + }, + "params": { + "Region": "us-east-1", + "UseFIPS": true, + "UseDualStack": false, + "Endpoint": "https://example.com" + } + }, + { + "documentation": "For custom endpoint with fips disabled and dualstack enabled", + "expect": { + "error": "Invalid Configuration: Dualstack and custom endpoint are not supported" + }, + "params": { + "Region": "us-east-1", + "UseFIPS": false, + "UseDualStack": true, + "Endpoint": "https://example.com" + } + }, + { + "documentation": "Missing region", + "expect": { + "error": "Invalid Configuration: Missing Region" + } + } + ], + "version": "1.0" + } + } + }, + "com.amazonaws.bedrockruntime#Body": { + "type": "blob", + "traits": { + "smithy.api#length": { + "max": 25000000 + }, + "smithy.api#sensitive": {} + } + }, + "com.amazonaws.bedrockruntime#InferenceResource": { + "type": "resource", + "operations": [ + { + "target": "com.amazonaws.bedrockruntime#InvokeModel" + }, + { + "target": "com.amazonaws.bedrockruntime#InvokeModelWithResponseStream" + } + ] + }, + "com.amazonaws.bedrockruntime#InternalServerException": { + "type": "structure", + "members": { + "message": { + "target": "com.amazonaws.bedrockruntime#NonBlankString" + } + }, + "traits": { + "smithy.api#documentation": "An internal server error occurred. Retry your request.
", + "smithy.api#error": "server", + "smithy.api#httpError": 500 + } + }, + "com.amazonaws.bedrockruntime#InvokeModel": { + "type": "operation", + "input": { + "target": "com.amazonaws.bedrockruntime#InvokeModelRequest" + }, + "output": { + "target": "com.amazonaws.bedrockruntime#InvokeModelResponse" + }, + "errors": [ + { + "target": "com.amazonaws.bedrockruntime#AccessDeniedException" + }, + { + "target": "com.amazonaws.bedrockruntime#InternalServerException" + }, + { + "target": "com.amazonaws.bedrockruntime#ModelErrorException" + }, + { + "target": "com.amazonaws.bedrockruntime#ModelNotReadyException" + }, + { + "target": "com.amazonaws.bedrockruntime#ModelTimeoutException" + }, + { + "target": "com.amazonaws.bedrockruntime#ResourceNotFoundException" + }, + { + "target": "com.amazonaws.bedrockruntime#ServiceQuotaExceededException" + }, + { + "target": "com.amazonaws.bedrockruntime#ThrottlingException" + }, + { + "target": "com.amazonaws.bedrockruntime#ValidationException" + } + ], + "traits": { + "smithy.api#documentation": "Invokes the specified Bedrock model to run inference using the input provided in the request body. \n You use InvokeModel to run inference for text models, image models, and embedding models.
\nFor more information about invoking models, see Using the API in the Bedrock User Guide.
\nFor example requests, see Examples (after the Errors section).
", + "smithy.api#http": { + "code": 200, + "method": "POST", + "uri": "/model/{modelId}/invoke" + } + } + }, + "com.amazonaws.bedrockruntime#InvokeModelIdentifier": { + "type": "string", + "traits": { + "smithy.api#length": { + "min": 1, + "max": 2048 + }, + "smithy.api#pattern": "^(arn:aws(-[^:]+)?:bedrock:[a-z0-9-]{1,20}:(([0-9]{12}:custom-model/[a-z0-9-]{1,63}[.]{1}[a-z0-9-]{1,63}/[a-z0-9]{12})|(:foundation-model/[a-z0-9-]{1,63}[.]{1}[a-z0-9-]{1,63}([.]?[a-z0-9-]{1,63})([:][a-z0-9-]{1,63}){0,2})|([0-9]{12}:provisioned-model/[a-z0-9]{12})))|([a-z0-9-]{1,63}[.]{1}[a-z0-9-]{1,63}([.]?[a-z0-9-]{1,63})([:][a-z0-9-]{1,63}){0,2})|(([0-9a-zA-Z][_-]?)+)$" + } + }, + "com.amazonaws.bedrockruntime#InvokeModelRequest": { + "type": "structure", + "members": { + "body": { + "target": "com.amazonaws.bedrockruntime#Body", + "traits": { + "smithy.api#documentation": "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 Inference parameters.
", + "smithy.api#httpPayload": {}, + "smithy.api#required": {} + } + }, + "contentType": { + "target": "com.amazonaws.bedrockruntime#MimeType", + "traits": { + "smithy.api#documentation": "The MIME type of the input data in the request. The default value is\n application/json
.
The desired MIME type of the inference body in the response. The default value is\n application/json
.
Identifier of the model.
", + "smithy.api#httpLabel": {}, + "smithy.api#required": {} + } + } + }, + "traits": { + "smithy.api#input": {} + } + }, + "com.amazonaws.bedrockruntime#InvokeModelResponse": { + "type": "structure", + "members": { + "body": { + "target": "com.amazonaws.bedrockruntime#Body", + "traits": { + "smithy.api#documentation": "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 Inference parameters.
", + "smithy.api#httpPayload": {}, + "smithy.api#required": {} + } + }, + "contentType": { + "target": "com.amazonaws.bedrockruntime#MimeType", + "traits": { + "smithy.api#documentation": "The MIME type of the inference result.
", + "smithy.api#httpHeader": "Content-Type", + "smithy.api#required": {} + } + } + }, + "traits": { + "smithy.api#output": {} + } + }, + "com.amazonaws.bedrockruntime#InvokeModelWithResponseStream": { + "type": "operation", + "input": { + "target": "com.amazonaws.bedrockruntime#InvokeModelWithResponseStreamRequest" + }, + "output": { + "target": "com.amazonaws.bedrockruntime#InvokeModelWithResponseStreamResponse" + }, + "errors": [ + { + "target": "com.amazonaws.bedrockruntime#AccessDeniedException" + }, + { + "target": "com.amazonaws.bedrockruntime#InternalServerException" + }, + { + "target": "com.amazonaws.bedrockruntime#ModelErrorException" + }, + { + "target": "com.amazonaws.bedrockruntime#ModelNotReadyException" + }, + { + "target": "com.amazonaws.bedrockruntime#ModelStreamErrorException" + }, + { + "target": "com.amazonaws.bedrockruntime#ModelTimeoutException" + }, + { + "target": "com.amazonaws.bedrockruntime#ResourceNotFoundException" + }, + { + "target": "com.amazonaws.bedrockruntime#ServiceQuotaExceededException" + }, + { + "target": "com.amazonaws.bedrockruntime#ThrottlingException" + }, + { + "target": "com.amazonaws.bedrockruntime#ValidationException" + } + ], + "traits": { + "smithy.api#documentation": "Invoke the specified Bedrock model to run inference using the input provided.\n Return the response in a stream.
\nFor more information about invoking models, see Using the API in the Bedrock User Guide.
\nFor an example request and response, see Examples (after the Errors section).
", + "smithy.api#http": { + "code": 200, + "method": "POST", + "uri": "/model/{modelId}/invoke-with-response-stream" + } + } + }, + "com.amazonaws.bedrockruntime#InvokeModelWithResponseStreamRequest": { + "type": "structure", + "members": { + "body": { + "target": "com.amazonaws.bedrockruntime#Body", + "traits": { + "smithy.api#documentation": "Inference input in the format specified by the \n content-type. To see the format and content of this field for different models, refer to Inference parameters.
", + "smithy.api#httpPayload": {}, + "smithy.api#required": {} + } + }, + "contentType": { + "target": "com.amazonaws.bedrockruntime#MimeType", + "traits": { + "smithy.api#documentation": "The MIME type of the input data in the request. The default value is\n application/json
.
The desired MIME type of the inference body in the response. The default value is\n application/json
.
Id of the model to invoke using the streaming request.
", + "smithy.api#httpLabel": {}, + "smithy.api#required": {} + } + } + }, + "traits": { + "smithy.api#input": {} + } + }, + "com.amazonaws.bedrockruntime#InvokeModelWithResponseStreamResponse": { + "type": "structure", + "members": { + "body": { + "target": "com.amazonaws.bedrockruntime#ResponseStream", + "traits": { + "smithy.api#documentation": "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 Inference parameters.
", + "smithy.api#httpPayload": {}, + "smithy.api#required": {} + } + }, + "contentType": { + "target": "com.amazonaws.bedrockruntime#MimeType", + "traits": { + "smithy.api#documentation": "The MIME type of the inference result.
", + "smithy.api#httpHeader": "X-Amzn-Bedrock-Content-Type", + "smithy.api#required": {} + } + } + }, + "traits": { + "smithy.api#output": {} + } + }, + "com.amazonaws.bedrockruntime#MimeType": { + "type": "string" + }, + "com.amazonaws.bedrockruntime#ModelErrorException": { + "type": "structure", + "members": { + "message": { + "target": "com.amazonaws.bedrockruntime#NonBlankString" + }, + "originalStatusCode": { + "target": "com.amazonaws.bedrockruntime#StatusCode", + "traits": { + "smithy.api#documentation": "The original status code.
" + } + }, + "resourceName": { + "target": "com.amazonaws.bedrockruntime#NonBlankString", + "traits": { + "smithy.api#documentation": "The resource name.
" + } + } + }, + "traits": { + "smithy.api#documentation": "The request failed due to an error while processing the model.
", + "smithy.api#error": "client", + "smithy.api#httpError": 424 + } + }, + "com.amazonaws.bedrockruntime#ModelNotReadyException": { + "type": "structure", + "members": { + "message": { + "target": "com.amazonaws.bedrockruntime#NonBlankString" + } + }, + "traits": { + "smithy.api#documentation": "The model specified in the request is not ready to serve inference requests.
", + "smithy.api#error": "client", + "smithy.api#httpError": 429 + } + }, + "com.amazonaws.bedrockruntime#ModelStreamErrorException": { + "type": "structure", + "members": { + "message": { + "target": "com.amazonaws.bedrockruntime#NonBlankString" + }, + "originalStatusCode": { + "target": "com.amazonaws.bedrockruntime#StatusCode", + "traits": { + "smithy.api#documentation": "The original status code.
" + } + }, + "originalMessage": { + "target": "com.amazonaws.bedrockruntime#NonBlankString", + "traits": { + "smithy.api#documentation": "The original message.
" + } + } + }, + "traits": { + "smithy.api#documentation": "An error occurred while streaming the response.
", + "smithy.api#error": "client", + "smithy.api#httpError": 424 + } + }, + "com.amazonaws.bedrockruntime#ModelTimeoutException": { + "type": "structure", + "members": { + "message": { + "target": "com.amazonaws.bedrockruntime#NonBlankString" + } + }, + "traits": { + "smithy.api#documentation": "The request took too long to process. Processing time exceeded the model timeout length.
", + "smithy.api#error": "client", + "smithy.api#httpError": 408 + } + }, + "com.amazonaws.bedrockruntime#NonBlankString": { + "type": "string", + "traits": { + "smithy.api#pattern": "^[\\s\\S]*$" + } + }, + "com.amazonaws.bedrockruntime#PartBody": { + "type": "blob", + "traits": { + "smithy.api#length": { + "max": 1000000 + }, + "smithy.api#sensitive": {} + } + }, + "com.amazonaws.bedrockruntime#PayloadPart": { + "type": "structure", + "members": { + "bytes": { + "target": "com.amazonaws.bedrockruntime#PartBody", + "traits": { + "smithy.api#documentation": "Base64-encoded bytes of payload data.
" + } + } + }, + "traits": { + "smithy.api#documentation": "Payload content included in the response.
", + "smithy.api#sensitive": {} + } + }, + "com.amazonaws.bedrockruntime#ResourceNotFoundException": { + "type": "structure", + "members": { + "message": { + "target": "com.amazonaws.bedrockruntime#NonBlankString" + } + }, + "traits": { + "smithy.api#documentation": "The specified resource ARN was not found. Check the ARN and try your request again.
", + "smithy.api#error": "client", + "smithy.api#httpError": 404 + } + }, + "com.amazonaws.bedrockruntime#ResponseStream": { + "type": "union", + "members": { + "chunk": { + "target": "com.amazonaws.bedrockruntime#PayloadPart", + "traits": { + "smithy.api#documentation": "Content included in the response.
" + } + }, + "internalServerException": { + "target": "com.amazonaws.bedrockruntime#InternalServerException" + }, + "modelStreamErrorException": { + "target": "com.amazonaws.bedrockruntime#ModelStreamErrorException" + }, + "validationException": { + "target": "com.amazonaws.bedrockruntime#ValidationException" + }, + "throttlingException": { + "target": "com.amazonaws.bedrockruntime#ThrottlingException" + } + }, + "traits": { + "smithy.api#documentation": "Definition of content in the response stream.
", + "smithy.api#streaming": {} + } + }, + "com.amazonaws.bedrockruntime#ServiceQuotaExceededException": { + "type": "structure", + "members": { + "message": { + "target": "com.amazonaws.bedrockruntime#NonBlankString" + } + }, + "traits": { + "smithy.api#documentation": "The number of requests exceeds the service quota. Resubmit your request later.
", + "smithy.api#error": "client", + "smithy.api#httpError": 400 + } + }, + "com.amazonaws.bedrockruntime#StatusCode": { + "type": "integer", + "traits": { + "smithy.api#range": { + "min": 100, + "max": 599 + } + } + }, + "com.amazonaws.bedrockruntime#ThrottlingException": { + "type": "structure", + "members": { + "message": { + "target": "com.amazonaws.bedrockruntime#NonBlankString" + } + }, + "traits": { + "smithy.api#documentation": "The number of requests exceeds the limit. Resubmit your request later.
", + "smithy.api#error": "client", + "smithy.api#httpError": 429 + } + }, + "com.amazonaws.bedrockruntime#ValidationException": { + "type": "structure", + "members": { + "message": { + "target": "com.amazonaws.bedrockruntime#NonBlankString" + } + }, + "traits": { + "smithy.api#documentation": "Input validation failed. Check your request parameters and retry the request.
", + "smithy.api#error": "client", + "smithy.api#httpError": 400 + } + } + } +}