Interface BedrockRuntimeAsyncClient

All Superinterfaces:
AutoCloseable, AwsClient, SdkAutoCloseable, SdkClient

@Generated("software.amazon.awssdk:codegen") @ThreadSafe public interface BedrockRuntimeAsyncClient extends AwsClient
Service client for accessing Amazon Bedrock Runtime asynchronously. This can be created using the static builder() method.The asynchronous client performs non-blocking I/O when configured with any SdkAsyncHttpClient supported in the SDK. However, full non-blocking is not guaranteed as the async client may perform blocking calls in some cases such as credentials retrieval and endpoint discovery as part of the async API call.

Describes the API operations for running inference using Amazon Bedrock models.

  • Field Details

  • Method Details

    • invokeModel

      default CompletableFuture<InvokeModelResponse> invokeModel(InvokeModelRequest invokeModelRequest)

      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.

      Parameters:
      invokeModelRequest -
      Returns:
      A Java Future containing the result of the InvokeModel operation returned by the service.
      The CompletableFuture returned by this method can be completed exceptionally with the following exceptions. The exception returned is wrapped with CompletionException, so you need to invoke Throwable.getCause() to retrieve the underlying exception.
      • AccessDeniedException The request is denied because of missing access permissions.
      • ResourceNotFoundException The specified resource ARN was not found. Check the ARN and try your request again.
      • ThrottlingException The number of requests exceeds the limit. Resubmit your request later.
      • ModelTimeoutException The request took too long to process. Processing time exceeded the model timeout length.
      • InternalServerException An internal server error occurred. Retry your request.
      • ValidationException Input validation failed. Check your request parameters and retry the request.
      • ModelNotReadyException The model specified in the request is not ready to serve inference requests.
      • ServiceQuotaExceededException The number of requests exceeds the service quota. Resubmit your request later.
      • ModelErrorException The request failed due to an error while processing the model.
      • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for catch all scenarios.
      • SdkClientException If any client side error occurs such as an IO related failure, failure to get credentials, etc.
      • BedrockRuntimeException Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type.
      See Also:
    • invokeModel

      default CompletableFuture<InvokeModelResponse> invokeModel(Consumer<InvokeModelRequest.Builder> invokeModelRequest)

      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.


      This is a convenience which creates an instance of the InvokeModelRequest.Builder avoiding the need to create one manually via InvokeModelRequest.builder()

      Parameters:
      invokeModelRequest - A Consumer that will call methods on InvokeModelRequest.Builder to create a request.
      Returns:
      A Java Future containing the result of the InvokeModel operation returned by the service.
      The CompletableFuture returned by this method can be completed exceptionally with the following exceptions. The exception returned is wrapped with CompletionException, so you need to invoke Throwable.getCause() to retrieve the underlying exception.
      • AccessDeniedException The request is denied because of missing access permissions.
      • ResourceNotFoundException The specified resource ARN was not found. Check the ARN and try your request again.
      • ThrottlingException The number of requests exceeds the limit. Resubmit your request later.
      • ModelTimeoutException The request took too long to process. Processing time exceeded the model timeout length.
      • InternalServerException An internal server error occurred. Retry your request.
      • ValidationException Input validation failed. Check your request parameters and retry the request.
      • ModelNotReadyException The model specified in the request is not ready to serve inference requests.
      • ServiceQuotaExceededException The number of requests exceeds the service quota. Resubmit your request later.
      • ModelErrorException The request failed due to an error while processing the model.
      • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for catch all scenarios.
      • SdkClientException If any client side error occurs such as an IO related failure, failure to get credentials, etc.
      • BedrockRuntimeException Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type.
      See Also:
    • invokeModelWithResponseStream

      default CompletableFuture<Void> invokeModelWithResponseStream(InvokeModelWithResponseStreamRequest invokeModelWithResponseStreamRequest, InvokeModelWithResponseStreamResponseHandler asyncResponseHandler)

      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.

      The CLI doesn't support InvokeModelWithResponseStream.

      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.

      Parameters:
      invokeModelWithResponseStreamRequest -
      Returns:
      A Java Future containing the result of the InvokeModelWithResponseStream operation returned by the service.
      The CompletableFuture returned by this method can be completed exceptionally with the following exceptions. The exception returned is wrapped with CompletionException, so you need to invoke Throwable.getCause() to retrieve the underlying exception.
      • AccessDeniedException The request is denied because of missing access permissions.
      • ResourceNotFoundException The specified resource ARN was not found. Check the ARN and try your request again.
      • ThrottlingException The number of requests exceeds the limit. Resubmit your request later.
      • ModelTimeoutException The request took too long to process. Processing time exceeded the model timeout length.
      • InternalServerException An internal server error occurred. Retry your request.
      • ModelStreamErrorException An error occurred while streaming the response. Retry your request.
      • ValidationException Input validation failed. Check your request parameters and retry the request.
      • ModelNotReadyException The model specified in the request is not ready to serve inference requests.
      • ServiceQuotaExceededException The number of requests exceeds the service quota. Resubmit your request later.
      • ModelErrorException The request failed due to an error while processing the model.
      • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for catch all scenarios.
      • SdkClientException If any client side error occurs such as an IO related failure, failure to get credentials, etc.
      • BedrockRuntimeException Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type.
      See Also:
    • invokeModelWithResponseStream

      default CompletableFuture<Void> invokeModelWithResponseStream(Consumer<InvokeModelWithResponseStreamRequest.Builder> invokeModelWithResponseStreamRequest, InvokeModelWithResponseStreamResponseHandler asyncResponseHandler)

      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.

      The CLI doesn't support InvokeModelWithResponseStream.

      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.


      This is a convenience which creates an instance of the InvokeModelWithResponseStreamRequest.Builder avoiding the need to create one manually via InvokeModelWithResponseStreamRequest.builder()

      Parameters:
      invokeModelWithResponseStreamRequest - A Consumer that will call methods on InvokeModelWithResponseStreamRequest.Builder to create a request.
      Returns:
      A Java Future containing the result of the InvokeModelWithResponseStream operation returned by the service.
      The CompletableFuture returned by this method can be completed exceptionally with the following exceptions. The exception returned is wrapped with CompletionException, so you need to invoke Throwable.getCause() to retrieve the underlying exception.
      • AccessDeniedException The request is denied because of missing access permissions.
      • ResourceNotFoundException The specified resource ARN was not found. Check the ARN and try your request again.
      • ThrottlingException The number of requests exceeds the limit. Resubmit your request later.
      • ModelTimeoutException The request took too long to process. Processing time exceeded the model timeout length.
      • InternalServerException An internal server error occurred. Retry your request.
      • ModelStreamErrorException An error occurred while streaming the response. Retry your request.
      • ValidationException Input validation failed. Check your request parameters and retry the request.
      • ModelNotReadyException The model specified in the request is not ready to serve inference requests.
      • ServiceQuotaExceededException The number of requests exceeds the service quota. Resubmit your request later.
      • ModelErrorException The request failed due to an error while processing the model.
      • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for catch all scenarios.
      • SdkClientException If any client side error occurs such as an IO related failure, failure to get credentials, etc.
      • BedrockRuntimeException Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type.
      See Also:
    • serviceClientConfiguration

      default BedrockRuntimeServiceClientConfiguration serviceClientConfiguration()
      Description copied from interface: SdkClient
      The SDK service client configuration exposes client settings to the user, e.g., ClientOverrideConfiguration
      Specified by:
      serviceClientConfiguration in interface AwsClient
      Specified by:
      serviceClientConfiguration in interface SdkClient
      Returns:
      SdkServiceClientConfiguration
    • create

      static BedrockRuntimeAsyncClient create()
      Create a BedrockRuntimeAsyncClient with the region loaded from the DefaultAwsRegionProviderChain and credentials loaded from the DefaultCredentialsProvider.
    • builder

      Create a builder that can be used to configure and create a BedrockRuntimeAsyncClient.