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.
2485 2486 2487 |
# File 'lib/aws-sdk-bedrockruntime/client.rb', line 2485 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.
2488 2489 2490 |
# File 'lib/aws-sdk-bedrockruntime/client.rb', line 2488 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
598 599 600 601 |
# File 'lib/aws-sdk-bedrockruntime/client.rb', line 598 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.
2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 |
# File 'lib/aws-sdk-bedrockruntime/client.rb', line 2458 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.40.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
1084 1085 1086 1087 |
# File 'lib/aws-sdk-bedrockruntime/client.rb', line 1084 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
1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 |
# File 'lib/aws-sdk-bedrockruntime/client.rb', line 1757 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.
1821 1822 1823 1824 |
# File 'lib/aws-sdk-bedrockruntime/client.rb', line 1821 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
1966 1967 1968 1969 |
# File 'lib/aws-sdk-bedrockruntime/client.rb', line 1966 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
2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 |
# File 'lib/aws-sdk-bedrockruntime/client.rb', line 2283 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.
2369 2370 2371 2372 |
# File 'lib/aws-sdk-bedrockruntime/client.rb', line 2369 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
2449 2450 2451 2452 |
# File 'lib/aws-sdk-bedrockruntime/client.rb', line 2449 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.
2478 2479 2480 |
# File 'lib/aws-sdk-bedrockruntime/client.rb', line 2478 def waiter_names [] end |