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.
478 479 480 |
# File 'lib/aws-sdk-bedrockruntime/client.rb', line 478 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.
2514 2515 2516 |
# File 'lib/aws-sdk-bedrockruntime/client.rb', line 2514 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.
2517 2518 2519 |
# File 'lib/aws-sdk-bedrockruntime/client.rb', line 2517 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
600 601 602 603 |
# File 'lib/aws-sdk-bedrockruntime/client.rb', line 600 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.
2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 |
# File 'lib/aws-sdk-bedrockruntime/client.rb', line 2487 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.42.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
1100 1101 1102 1103 |
# File 'lib/aws-sdk-bedrockruntime/client.rb', line 1100 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
1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 |
# File 'lib/aws-sdk-bedrockruntime/client.rb', line 1786 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.
1850 1851 1852 1853 |
# File 'lib/aws-sdk-bedrockruntime/client.rb', line 1850 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
1995 1996 1997 1998 |
# File 'lib/aws-sdk-bedrockruntime/client.rb', line 1995 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
2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 |
# File 'lib/aws-sdk-bedrockruntime/client.rb', line 2312 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.
2398 2399 2400 2401 |
# File 'lib/aws-sdk-bedrockruntime/client.rb', line 2398 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
2478 2479 2480 2481 |
# File 'lib/aws-sdk-bedrockruntime/client.rb', line 2478 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.
2507 2508 2509 |
# File 'lib/aws-sdk-bedrockruntime/client.rb', line 2507 def waiter_names [] end |