Class: Aws::BedrockRuntime::Client
- Inherits:
-
Seahorse::Client::Base
- Object
- Seahorse::Client::Base
- Aws::BedrockRuntime::Client
- Includes:
- ClientStubs
- Defined in:
- lib/aws-sdk-bedrockruntime/client.rb
Overview
An API client for BedrockRuntime. To construct a client, you need to configure a ‘:region` and `:credentials`.
client = Aws::BedrockRuntime::Client.new(
region: region_name,
credentials: credentials,
# ...
)
For details on configuring region and credentials see the [developer guide](/sdk-for-ruby/v3/developer-guide/setup-config.html).
See #initialize for a full list of supported configuration options.
Class Attribute Summary collapse
- .identifier ⇒ Object readonly private
API Operations collapse
-
#apply_guardrail(params = {}) ⇒ Types::ApplyGuardrailResponse
The action to apply a guardrail.
-
#converse(params = {}) ⇒ Types::ConverseResponse
Sends messages to the specified Amazon Bedrock model.
-
#converse_stream(params = {}) ⇒ Types::ConverseStreamResponse
Sends messages to the specified Amazon Bedrock model and returns the response in a stream.
-
#get_async_invoke(params = {}) ⇒ Types::GetAsyncInvokeResponse
Retrieve information about an asynchronous invocation.
-
#invoke_model(params = {}) ⇒ Types::InvokeModelResponse
Invokes the specified Amazon Bedrock model to run inference using the prompt and inference parameters provided in the request body.
-
#invoke_model_with_response_stream(params = {}) ⇒ Types::InvokeModelWithResponseStreamResponse
Invoke the specified Amazon Bedrock model to run inference using the prompt and inference parameters provided in the request body.
-
#list_async_invokes(params = {}) ⇒ Types::ListAsyncInvokesResponse
Lists asynchronous invocations.
-
#start_async_invoke(params = {}) ⇒ Types::StartAsyncInvokeResponse
Starts an asynchronous invocation.
Class Method Summary collapse
- .errors_module ⇒ Object private
Instance Method Summary collapse
- #build_request(operation_name, params = {}) ⇒ Object private
-
#initialize(options) ⇒ Client
constructor
A new instance of Client.
- #waiter_names ⇒ Object deprecated private Deprecated.
Constructor Details
#initialize(options) ⇒ Client
Returns a new instance of Client.
455 456 457 |
# File 'lib/aws-sdk-bedrockruntime/client.rb', line 455 def initialize(*args) super end |
Class Attribute Details
.identifier ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
2396 2397 2398 |
# File 'lib/aws-sdk-bedrockruntime/client.rb', line 2396 def identifier @identifier end |
Class Method Details
.errors_module ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
2399 2400 2401 |
# File 'lib/aws-sdk-bedrockruntime/client.rb', line 2399 def errors_module Errors end |
Instance Method Details
#apply_guardrail(params = {}) ⇒ Types::ApplyGuardrailResponse
The action to apply a guardrail.
For troubleshooting some of the common errors you might encounter when using the ‘ApplyGuardrail` API, see [Troubleshooting Amazon Bedrock API Error Codes] in the Amazon Bedrock User Guide
[1]: docs.aws.amazon.com/bedrock/latest/userguide/troubleshooting-api-error-codes.html
565 566 567 568 |
# File 'lib/aws-sdk-bedrockruntime/client.rb', line 565 def apply_guardrail(params = {}, = {}) req = build_request(:apply_guardrail, params) req.send_request() end |
#build_request(operation_name, params = {}) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 |
# File 'lib/aws-sdk-bedrockruntime/client.rb', line 2369 def build_request(operation_name, params = {}) handlers = @handlers.for(operation_name) tracer = config.telemetry_provider.tracer_provider.tracer( Aws::Telemetry.module_to_tracer_name('Aws::BedrockRuntime') ) context = Seahorse::Client::RequestContext.new( operation_name: operation_name, operation: config.api.operation(operation_name), client: self, params: params, config: config, tracer: tracer ) context[:gem_name] = 'aws-sdk-bedrockruntime' context[:gem_version] = '1.33.0' Seahorse::Client::Request.new(handlers, context) end |
#converse(params = {}) ⇒ Types::ConverseResponse
Sends messages to the specified Amazon Bedrock model. ‘Converse` provides a consistent interface that works with all models that support messages. This allows you to write code once and use it with different models. If a model has unique inference parameters, you can also pass those unique parameters to the model.
Amazon Bedrock doesn’t store any text, images, or documents that you provide as content. The data is only used to generate the response.
You can submit a prompt by including it in the ‘messages` field, specifying the `modelId` of a foundation model or inference profile to run inference on it, and including any other fields that are relevant to your use case.
You can also submit a prompt from Prompt management by specifying the ARN of the prompt version and including a map of variables to values in the ‘promptVariables` field. You can append more messages to the prompt by using the `messages` field. If you use a prompt from Prompt management, you can’t include the following fields in the request: ‘additionalModelRequestFields`, `inferenceConfig`, `system`, or `toolConfig`. Instead, these fields must be defined through Prompt management. For more information, see [Use a prompt from Prompt management].
For information about the Converse API, see *Use the Converse API* in the *Amazon Bedrock User Guide*. To use a guardrail, see *Use a guardrail with the Converse API* in the *Amazon Bedrock User Guide*. To use a tool with a model, see *Tool use (Function calling)* in the *Amazon Bedrock User Guide*
For example code, see *Converse API examples* in the *Amazon Bedrock User Guide*.
This operation requires permission for the ‘bedrock:InvokeModel` action.
To deny all inference access to resources that you specify in the modelId field, you need to deny access to the ‘bedrock:InvokeModel` and `bedrock:InvokeModelWithResponseStream` actions. Doing this also denies access to the resource through the base inference actions ([InvokeModel] and [InvokeModelWithResponseStream]). For more information see [Deny access for inference on specific models].
For troubleshooting some of the common errors you might encounter when using the ‘Converse` API, see [Troubleshooting Amazon Bedrock API Error Codes] in the Amazon Bedrock User Guide
[1]: docs.aws.amazon.com/bedrock/latest/userguide/prompt-management-use.html [2]: docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_InvokeModel.html [3]: docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_InvokeModelWithResponseStream.html [4]: docs.aws.amazon.com/bedrock/latest/userguide/security_iam_id-based-policy-examples.html#security_iam_id-based-policy-examples-deny-inference [5]: docs.aws.amazon.com/bedrock/latest/userguide/troubleshooting-api-error-codes.html
1022 1023 1024 1025 |
# File 'lib/aws-sdk-bedrockruntime/client.rb', line 1022 def converse(params = {}, = {}) req = build_request(:converse, params) req.send_request() end |
#converse_stream(params = {}) ⇒ Types::ConverseStreamResponse
Sends messages to the specified Amazon Bedrock model and returns the response in a stream. ‘ConverseStream` provides a consistent API that works with all Amazon Bedrock models that support messages. This allows you to write code once and use it with different models. Should a model have unique inference parameters, you can also pass those unique parameters to the model.
To find out if a model supports streaming, call
- GetFoundationModel][1
-
and check the ‘responseStreamingSupported`
field in the response.
<note markdown=“1”> The CLI doesn’t support streaming operations in Amazon Bedrock, including ‘ConverseStream`.
</note>
Amazon Bedrock doesn’t store any text, images, or documents that you provide as content. The data is only used to generate the response.
You can submit a prompt by including it in the ‘messages` field, specifying the `modelId` of a foundation model or inference profile to run inference on it, and including any other fields that are relevant to your use case.
You can also submit a prompt from Prompt management by specifying the ARN of the prompt version and including a map of variables to values in the ‘promptVariables` field. You can append more messages to the prompt by using the `messages` field. If you use a prompt from Prompt management, you can’t include the following fields in the request: ‘additionalModelRequestFields`, `inferenceConfig`, `system`, or `toolConfig`. Instead, these fields must be defined through Prompt management. For more information, see [Use a prompt from Prompt management].
For information about the Converse API, see *Use the Converse API* in the *Amazon Bedrock User Guide*. To use a guardrail, see *Use a guardrail with the Converse API* in the *Amazon Bedrock User Guide*. To use a tool with a model, see *Tool use (Function calling)* in the *Amazon Bedrock User Guide*
For example code, see *Conversation streaming example* in the *Amazon Bedrock User Guide*.
This operation requires permission for the ‘bedrock:InvokeModelWithResponseStream` action.
To deny all inference access to resources that you specify in the modelId field, you need to deny access to the ‘bedrock:InvokeModel` and `bedrock:InvokeModelWithResponseStream` actions. Doing this also denies access to the resource through the base inference actions ([InvokeModel] and [InvokeModelWithResponseStream]). For more information see [Deny access for inference on specific models].
For troubleshooting some of the common errors you might encounter when using the ‘ConverseStream` API, see [Troubleshooting Amazon Bedrock API Error Codes] in the Amazon Bedrock User Guide
[1]: docs.aws.amazon.com/bedrock/latest/APIReference/API_GetFoundationModel.html [2]: docs.aws.amazon.com/bedrock/latest/userguide/prompt-management-use.html [3]: docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_InvokeModel.html [4]: docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_InvokeModelWithResponseStream.html [5]: docs.aws.amazon.com/bedrock/latest/userguide/security_iam_id-based-policy-examples.html#security_iam_id-based-policy-examples-deny-inference [6]: docs.aws.amazon.com/bedrock/latest/userguide/troubleshooting-api-error-codes.html
1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 |
# File 'lib/aws-sdk-bedrockruntime/client.rb', line 1668 def converse_stream(params = {}, = {}, &block) params = params.dup event_stream_handler = case handler = params.delete(:event_stream_handler) when EventStreams::ConverseStreamOutput then handler when Proc then EventStreams::ConverseStreamOutput.new.tap(&handler) when nil then EventStreams::ConverseStreamOutput.new else msg = "expected :event_stream_handler to be a block or "\ "instance of Aws::BedrockRuntime::EventStreams::ConverseStreamOutput"\ ", got `#{handler.inspect}` instead" raise ArgumentError, msg end yield(event_stream_handler) if block_given? req = build_request(:converse_stream, params) req.context[:event_stream_handler] = event_stream_handler req.handlers.add(Aws::Binary::DecodeHandler, priority: 95) req.send_request(, &block) end |
#get_async_invoke(params = {}) ⇒ Types::GetAsyncInvokeResponse
Retrieve information about an asynchronous invocation.
1732 1733 1734 1735 |
# File 'lib/aws-sdk-bedrockruntime/client.rb', line 1732 def get_async_invoke(params = {}, = {}) req = build_request(:get_async_invoke, params) req.send_request() end |
#invoke_model(params = {}) ⇒ Types::InvokeModelResponse
Invokes the specified Amazon Bedrock model to run inference using the prompt and inference parameters provided in the request body. You use model inference to generate text, images, and embeddings.
For example code, see *Invoke model code examples* in the *Amazon Bedrock User Guide*.
This operation requires permission for the ‘bedrock:InvokeModel` action.
To deny all inference access to resources that you specify in the modelId field, you need to deny access to the ‘bedrock:InvokeModel` and `bedrock:InvokeModelWithResponseStream` actions. Doing this also denies access to the resource through the Converse API actions ([Converse] and [ConverseStream]). For more information see [Deny access for inference on specific models].
For troubleshooting some of the common errors you might encounter when using the ‘InvokeModel` API, see [Troubleshooting Amazon Bedrock API Error Codes] in the Amazon Bedrock User Guide
[1]: docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_Converse.html [2]: docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_ConverseStream.html [3]: docs.aws.amazon.com/bedrock/latest/userguide/security_iam_id-based-policy-examples.html#security_iam_id-based-policy-examples-deny-inference [4]: docs.aws.amazon.com/bedrock/latest/userguide/troubleshooting-api-error-codes.html
1877 1878 1879 1880 |
# File 'lib/aws-sdk-bedrockruntime/client.rb', line 1877 def invoke_model(params = {}, = {}) req = build_request(:invoke_model, params) req.send_request() end |
#invoke_model_with_response_stream(params = {}) ⇒ Types::InvokeModelWithResponseStreamResponse
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.
To see if a model supports streaming, call [GetFoundationModel] and check the ‘responseStreamingSupported` field in the response.
<note markdown=“1”> The CLI doesn’t support streaming operations in Amazon Bedrock, including ‘InvokeModelWithResponseStream`.
</note>
For example code, see *Invoke model with streaming code example* in the *Amazon Bedrock User Guide*.
This operation requires permissions to perform the ‘bedrock:InvokeModelWithResponseStream` action.
To deny all inference access to resources that you specify in the modelId field, you need to deny access to the ‘bedrock:InvokeModel` and `bedrock:InvokeModelWithResponseStream` actions. Doing this also denies access to the resource through the Converse API actions ([Converse] and [ConverseStream]). For more information see [Deny access for inference on specific models].
For troubleshooting some of the common errors you might encounter when using the ‘InvokeModelWithResponseStream` API, see [Troubleshooting Amazon Bedrock API Error Codes] in the Amazon Bedrock User Guide
[1]: docs.aws.amazon.com/bedrock/latest/APIReference/API_GetFoundationModel.html [2]: docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_Converse.html [3]: docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_ConverseStream.html [4]: docs.aws.amazon.com/bedrock/latest/userguide/security_iam_id-based-policy-examples.html#security_iam_id-based-policy-examples-deny-inference [5]: docs.aws.amazon.com/bedrock/latest/userguide/troubleshooting-api-error-codes.html
2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 |
# File 'lib/aws-sdk-bedrockruntime/client.rb', line 2194 def invoke_model_with_response_stream(params = {}, = {}, &block) params = params.dup event_stream_handler = case handler = params.delete(:event_stream_handler) when EventStreams::ResponseStream then handler when Proc then EventStreams::ResponseStream.new.tap(&handler) when nil then EventStreams::ResponseStream.new else msg = "expected :event_stream_handler to be a block or "\ "instance of Aws::BedrockRuntime::EventStreams::ResponseStream"\ ", got `#{handler.inspect}` instead" raise ArgumentError, msg end yield(event_stream_handler) if block_given? req = build_request(:invoke_model_with_response_stream, params) req.context[:event_stream_handler] = event_stream_handler req.handlers.add(Aws::Binary::DecodeHandler, priority: 95) req.send_request(, &block) end |
#list_async_invokes(params = {}) ⇒ Types::ListAsyncInvokesResponse
Lists asynchronous invocations.
The returned response is a pageable response and is Enumerable. For details on usage see PageableResponse.
2280 2281 2282 2283 |
# File 'lib/aws-sdk-bedrockruntime/client.rb', line 2280 def list_async_invokes(params = {}, = {}) req = build_request(:list_async_invokes, params) req.send_request() end |
#start_async_invoke(params = {}) ⇒ Types::StartAsyncInvokeResponse
Starts an asynchronous invocation.
This operation requires permission for the ‘bedrock:InvokeModel` action.
To deny all inference access to resources that you specify in the modelId field, you need to deny access to the ‘bedrock:InvokeModel` and `bedrock:InvokeModelWithResponseStream` actions. Doing this also denies access to the resource through the Converse API actions ([Converse] and [ConverseStream]). For more information see [Deny access for inference on specific models].
[1]: docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_Converse.html [2]: docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_ConverseStream.html [3]: docs.aws.amazon.com/bedrock/latest/userguide/security_iam_id-based-policy-examples.html#security_iam_id-based-policy-examples-deny-inference
2360 2361 2362 2363 |
# File 'lib/aws-sdk-bedrockruntime/client.rb', line 2360 def start_async_invoke(params = {}, = {}) req = build_request(:start_async_invoke, params) req.send_request() end |
#waiter_names ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
2389 2390 2391 |
# File 'lib/aws-sdk-bedrockruntime/client.rb', line 2389 def waiter_names [] end |