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.
477 478 479 |
# File 'lib/aws-sdk-bedrockruntime/client.rb', line 477 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.
2615 2616 2617 |
# File 'lib/aws-sdk-bedrockruntime/client.rb', line 2615 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.
2618 2619 2620 |
# File 'lib/aws-sdk-bedrockruntime/client.rb', line 2618 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
619 620 621 622 |
# File 'lib/aws-sdk-bedrockruntime/client.rb', line 619 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.
2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 |
# File 'lib/aws-sdk-bedrockruntime/client.rb', line 2588 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.49.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
1158 1159 1160 1161 |
# File 'lib/aws-sdk-bedrockruntime/client.rb', line 1158 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
1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 |
# File 'lib/aws-sdk-bedrockruntime/client.rb', line 1881 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.
1945 1946 1947 1948 |
# File 'lib/aws-sdk-bedrockruntime/client.rb', line 1945 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
2090 2091 2092 2093 |
# File 'lib/aws-sdk-bedrockruntime/client.rb', line 2090 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
2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 |
# File 'lib/aws-sdk-bedrockruntime/client.rb', line 2413 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.
2499 2500 2501 2502 |
# File 'lib/aws-sdk-bedrockruntime/client.rb', line 2499 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
2579 2580 2581 2582 |
# File 'lib/aws-sdk-bedrockruntime/client.rb', line 2579 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.
2608 2609 2610 |
# File 'lib/aws-sdk-bedrockruntime/client.rb', line 2608 def waiter_names [] end |