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.
2442 2443 2444 |
# File 'lib/aws-sdk-bedrockruntime/client.rb', line 2442 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.
2445 2446 2447 |
# File 'lib/aws-sdk-bedrockruntime/client.rb', line 2445 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
575 576 577 578 |
# File 'lib/aws-sdk-bedrockruntime/client.rb', line 575 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.
2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 |
# File 'lib/aws-sdk-bedrockruntime/client.rb', line 2415 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.34.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
1051 1052 1053 1054 |
# File 'lib/aws-sdk-bedrockruntime/client.rb', line 1051 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
1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 |
# File 'lib/aws-sdk-bedrockruntime/client.rb', line 1714 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.
1778 1779 1780 1781 |
# File 'lib/aws-sdk-bedrockruntime/client.rb', line 1778 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
1923 1924 1925 1926 |
# File 'lib/aws-sdk-bedrockruntime/client.rb', line 1923 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
2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 |
# File 'lib/aws-sdk-bedrockruntime/client.rb', line 2240 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.
2326 2327 2328 2329 |
# File 'lib/aws-sdk-bedrockruntime/client.rb', line 2326 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
2406 2407 2408 2409 |
# File 'lib/aws-sdk-bedrockruntime/client.rb', line 2406 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.
2435 2436 2437 |
# File 'lib/aws-sdk-bedrockruntime/client.rb', line 2435 def waiter_names [] end |