Interface BedrockRuntimeAsyncClient
- All Superinterfaces:
AutoCloseable,AwsClient,SdkAutoCloseable,SdkClient
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final StringValue for looking up the service's metadata from theServiceMetadataProvider.static final String -
Method Summary
Modifier and TypeMethodDescriptiondefault CompletableFuture<ApplyGuardrailResponse> applyGuardrail(Consumer<ApplyGuardrailRequest.Builder> applyGuardrailRequest) The action to apply a guardrail.default CompletableFuture<ApplyGuardrailResponse> applyGuardrail(ApplyGuardrailRequest applyGuardrailRequest) The action to apply a guardrail.builder()Create a builder that can be used to configure and create aBedrockRuntimeAsyncClient.default CompletableFuture<ConverseResponse> converse(Consumer<ConverseRequest.Builder> converseRequest) Sends messages to the specified Amazon Bedrock model.default CompletableFuture<ConverseResponse> converse(ConverseRequest converseRequest) Sends messages to the specified Amazon Bedrock model.default CompletableFuture<Void> converseStream(Consumer<ConverseStreamRequest.Builder> converseStreamRequest, ConverseStreamResponseHandler asyncResponseHandler) Sends messages to the specified Amazon Bedrock model and returns the response in a stream.default CompletableFuture<Void> converseStream(ConverseStreamRequest converseStreamRequest, ConverseStreamResponseHandler asyncResponseHandler) Sends messages to the specified Amazon Bedrock model and returns the response in a stream.default CompletableFuture<CountTokensResponse> countTokens(Consumer<CountTokensRequest.Builder> countTokensRequest) Returns the token count for a given inference request.default CompletableFuture<CountTokensResponse> countTokens(CountTokensRequest countTokensRequest) Returns the token count for a given inference request.static BedrockRuntimeAsyncClientcreate()Create aBedrockRuntimeAsyncClientwith the region loaded from theDefaultAwsRegionProviderChainand credentials loaded from theDefaultCredentialsProvider.default CompletableFuture<GetAsyncInvokeResponse> getAsyncInvoke(Consumer<GetAsyncInvokeRequest.Builder> getAsyncInvokeRequest) Retrieve information about an asynchronous invocation.default CompletableFuture<GetAsyncInvokeResponse> getAsyncInvoke(GetAsyncInvokeRequest getAsyncInvokeRequest) Retrieve information about an asynchronous invocation.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.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.default CompletableFuture<Void> invokeModelWithBidirectionalStream(Consumer<InvokeModelWithBidirectionalStreamRequest.Builder> invokeModelWithBidirectionalStreamRequest, org.reactivestreams.Publisher<InvokeModelWithBidirectionalStreamInput> requestStream, InvokeModelWithBidirectionalStreamResponseHandler asyncResponseHandler) Invoke the specified Amazon Bedrock model to run inference using the bidirectional stream.default CompletableFuture<Void> invokeModelWithBidirectionalStream(InvokeModelWithBidirectionalStreamRequest invokeModelWithBidirectionalStreamRequest, org.reactivestreams.Publisher<InvokeModelWithBidirectionalStreamInput> requestStream, InvokeModelWithBidirectionalStreamResponseHandler asyncResponseHandler) Invoke the specified Amazon Bedrock model to run inference using the bidirectional stream.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.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.listAsyncInvokes(Consumer<ListAsyncInvokesRequest.Builder> listAsyncInvokesRequest) Lists asynchronous invocations.listAsyncInvokes(ListAsyncInvokesRequest listAsyncInvokesRequest) Lists asynchronous invocations.default ListAsyncInvokesPublisherlistAsyncInvokesPaginator(Consumer<ListAsyncInvokesRequest.Builder> listAsyncInvokesRequest) This is a variant oflistAsyncInvokes(software.amazon.awssdk.services.bedrockruntime.model.ListAsyncInvokesRequest)operation.default ListAsyncInvokesPublisherlistAsyncInvokesPaginator(ListAsyncInvokesRequest listAsyncInvokesRequest) This is a variant oflistAsyncInvokes(software.amazon.awssdk.services.bedrockruntime.model.ListAsyncInvokesRequest)operation.The SDK service client configuration exposes client settings to the user, e.g., ClientOverrideConfigurationstartAsyncInvoke(Consumer<StartAsyncInvokeRequest.Builder> startAsyncInvokeRequest) Starts an asynchronous invocation.startAsyncInvoke(StartAsyncInvokeRequest startAsyncInvokeRequest) Starts an asynchronous invocation.Methods inherited from interface software.amazon.awssdk.utils.SdkAutoCloseable
closeMethods inherited from interface software.amazon.awssdk.core.SdkClient
serviceName
-
Field Details
-
SERVICE_NAME
- See Also:
-
SERVICE_METADATA_ID
Value for looking up the service's metadata from theServiceMetadataProvider.- See Also:
-
-
Method Details
-
applyGuardrail
default CompletableFuture<ApplyGuardrailResponse> applyGuardrail(ApplyGuardrailRequest applyGuardrailRequest) The action to apply a guardrail.
For troubleshooting some of the common errors you might encounter when using the
ApplyGuardrailAPI, see Troubleshooting Amazon Bedrock API Error Codes in the Amazon Bedrock User Guide- Parameters:
applyGuardrailRequest-- Returns:
- A Java Future containing the result of the ApplyGuardrail 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 invokeThrowable.getCause()to retrieve the underlying exception.- AccessDeniedException The request is denied because you do not have sufficient permissions to perform the requested action. For troubleshooting this error, see AccessDeniedException in the Amazon Bedrock User Guide
- ResourceNotFoundException The specified resource ARN was not found. For troubleshooting this error, see ResourceNotFound in the Amazon Bedrock User Guide
- ThrottlingException Your request was denied due to exceeding the account quotas for Amazon Bedrock. For troubleshooting this error, see ThrottlingException in the Amazon Bedrock User Guide
- InternalServerException An internal server error occurred. For troubleshooting this error, see InternalFailure in the Amazon Bedrock User Guide
- ServiceUnavailableException The service isn't currently available. For troubleshooting this error, see ServiceUnavailable in the Amazon Bedrock User Guide
- ValidationException The input fails to satisfy the constraints specified by Amazon Bedrock. For troubleshooting this error, see ValidationError in the Amazon Bedrock User Guide
- ServiceQuotaExceededException Your request exceeds the service quota for your account. You can view your quotas at Viewing service quotas. You can resubmit your request later.
- 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:
-
applyGuardrail
default CompletableFuture<ApplyGuardrailResponse> applyGuardrail(Consumer<ApplyGuardrailRequest.Builder> applyGuardrailRequest) The action to apply a guardrail.
For troubleshooting some of the common errors you might encounter when using the
ApplyGuardrailAPI, see Troubleshooting Amazon Bedrock API Error Codes in the Amazon Bedrock User Guide
This is a convenience which creates an instance of the
ApplyGuardrailRequest.Builderavoiding the need to create one manually viaApplyGuardrailRequest.builder()- Parameters:
applyGuardrailRequest- AConsumerthat will call methods onApplyGuardrailRequest.Builderto create a request.- Returns:
- A Java Future containing the result of the ApplyGuardrail 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 invokeThrowable.getCause()to retrieve the underlying exception.- AccessDeniedException The request is denied because you do not have sufficient permissions to perform the requested action. For troubleshooting this error, see AccessDeniedException in the Amazon Bedrock User Guide
- ResourceNotFoundException The specified resource ARN was not found. For troubleshooting this error, see ResourceNotFound in the Amazon Bedrock User Guide
- ThrottlingException Your request was denied due to exceeding the account quotas for Amazon Bedrock. For troubleshooting this error, see ThrottlingException in the Amazon Bedrock User Guide
- InternalServerException An internal server error occurred. For troubleshooting this error, see InternalFailure in the Amazon Bedrock User Guide
- ServiceUnavailableException The service isn't currently available. For troubleshooting this error, see ServiceUnavailable in the Amazon Bedrock User Guide
- ValidationException The input fails to satisfy the constraints specified by Amazon Bedrock. For troubleshooting this error, see ValidationError in the Amazon Bedrock User Guide
- ServiceQuotaExceededException Your request exceeds the service quota for your account. You can view your quotas at Viewing service quotas. You can resubmit your request later.
- 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:
-
converse
Sends messages to the specified Amazon Bedrock model.
Converseprovides 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
messagesfield, specifying themodelIdof 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
promptVariablesfield. You can append more messages to the prompt by using themessagesfield. If you use a prompt from Prompt management, you can't include the following fields in the request:additionalModelRequestFields,inferenceConfig,system, ortoolConfig. 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:InvokeModelaction.To deny all inference access to resources that you specify in the modelId field, you need to deny access to the
bedrock:InvokeModelandbedrock:InvokeModelWithResponseStreamactions. 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
ConverseAPI, see Troubleshooting Amazon Bedrock API Error Codes in the Amazon Bedrock User Guide- Parameters:
converseRequest-- Returns:
- A Java Future containing the result of the Converse 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 invokeThrowable.getCause()to retrieve the underlying exception.- AccessDeniedException The request is denied because you do not have sufficient permissions to perform the requested action. For troubleshooting this error, see AccessDeniedException in the Amazon Bedrock User Guide
- ThrottlingException Your request was denied due to exceeding the account quotas for Amazon Bedrock. For troubleshooting this error, see ThrottlingException in the Amazon Bedrock User Guide
- ResourceNotFoundException The specified resource ARN was not found. For troubleshooting this error, see ResourceNotFound in the Amazon Bedrock User Guide
- ModelTimeoutException The request took too long to process. Processing time exceeded the model timeout length.
- InternalServerException An internal server error occurred. For troubleshooting this error, see InternalFailure in the Amazon Bedrock User Guide
- ServiceUnavailableException The service isn't currently available. For troubleshooting this error, see ServiceUnavailable in the Amazon Bedrock User Guide
- ValidationException The input fails to satisfy the constraints specified by Amazon Bedrock. For troubleshooting this error, see ValidationError in the Amazon Bedrock User Guide
- ModelNotReadyException The model specified in the request is not ready to serve inference requests. The AWS SDK will automatically retry the operation up to 5 times. For information about configuring automatic retries, see Retry behavior in the AWS SDKs and Tools reference guide.
- 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:
-
converse
default CompletableFuture<ConverseResponse> converse(Consumer<ConverseRequest.Builder> converseRequest) Sends messages to the specified Amazon Bedrock model.
Converseprovides 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
messagesfield, specifying themodelIdof 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
promptVariablesfield. You can append more messages to the prompt by using themessagesfield. If you use a prompt from Prompt management, you can't include the following fields in the request:additionalModelRequestFields,inferenceConfig,system, ortoolConfig. 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:InvokeModelaction.To deny all inference access to resources that you specify in the modelId field, you need to deny access to the
bedrock:InvokeModelandbedrock:InvokeModelWithResponseStreamactions. 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
ConverseAPI, see Troubleshooting Amazon Bedrock API Error Codes in the Amazon Bedrock User Guide
This is a convenience which creates an instance of the
ConverseRequest.Builderavoiding the need to create one manually viaConverseRequest.builder()- Parameters:
converseRequest- AConsumerthat will call methods onConverseRequest.Builderto create a request.- Returns:
- A Java Future containing the result of the Converse 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 invokeThrowable.getCause()to retrieve the underlying exception.- AccessDeniedException The request is denied because you do not have sufficient permissions to perform the requested action. For troubleshooting this error, see AccessDeniedException in the Amazon Bedrock User Guide
- ThrottlingException Your request was denied due to exceeding the account quotas for Amazon Bedrock. For troubleshooting this error, see ThrottlingException in the Amazon Bedrock User Guide
- ResourceNotFoundException The specified resource ARN was not found. For troubleshooting this error, see ResourceNotFound in the Amazon Bedrock User Guide
- ModelTimeoutException The request took too long to process. Processing time exceeded the model timeout length.
- InternalServerException An internal server error occurred. For troubleshooting this error, see InternalFailure in the Amazon Bedrock User Guide
- ServiceUnavailableException The service isn't currently available. For troubleshooting this error, see ServiceUnavailable in the Amazon Bedrock User Guide
- ValidationException The input fails to satisfy the constraints specified by Amazon Bedrock. For troubleshooting this error, see ValidationError in the Amazon Bedrock User Guide
- ModelNotReadyException The model specified in the request is not ready to serve inference requests. The AWS SDK will automatically retry the operation up to 5 times. For information about configuring automatic retries, see Retry behavior in the AWS SDKs and Tools reference guide.
- 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:
-
converseStream
default CompletableFuture<Void> converseStream(ConverseStreamRequest converseStreamRequest, ConverseStreamResponseHandler asyncResponseHandler) Sends messages to the specified Amazon Bedrock model and returns the response in a stream.
ConverseStreamprovides 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 and check the
responseStreamingSupportedfield in the response.The CLI doesn't support streaming operations in Amazon Bedrock, including
ConverseStream.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
messagesfield, specifying themodelIdof 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
promptVariablesfield. You can append more messages to the prompt by using themessagesfield. If you use a prompt from Prompt management, you can't include the following fields in the request:additionalModelRequestFields,inferenceConfig,system, ortoolConfig. 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:InvokeModelWithResponseStreamaction.To deny all inference access to resources that you specify in the modelId field, you need to deny access to the
bedrock:InvokeModelandbedrock:InvokeModelWithResponseStreamactions. 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
ConverseStreamAPI, see Troubleshooting Amazon Bedrock API Error Codes in the Amazon Bedrock User Guide- Parameters:
converseStreamRequest-- Returns:
- A Java Future containing the result of the ConverseStream 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 invokeThrowable.getCause()to retrieve the underlying exception.- AccessDeniedException The request is denied because you do not have sufficient permissions to perform the requested action. For troubleshooting this error, see AccessDeniedException in the Amazon Bedrock User Guide
- ThrottlingException Your request was denied due to exceeding the account quotas for Amazon Bedrock. For troubleshooting this error, see ThrottlingException in the Amazon Bedrock User Guide
- ResourceNotFoundException The specified resource ARN was not found. For troubleshooting this error, see ResourceNotFound in the Amazon Bedrock User Guide
- ModelTimeoutException The request took too long to process. Processing time exceeded the model timeout length.
- InternalServerException An internal server error occurred. For troubleshooting this error, see InternalFailure in the Amazon Bedrock User Guide
- ServiceUnavailableException The service isn't currently available. For troubleshooting this error, see ServiceUnavailable in the Amazon Bedrock User Guide
- ValidationException The input fails to satisfy the constraints specified by Amazon Bedrock. For troubleshooting this error, see ValidationError in the Amazon Bedrock User Guide
- ModelNotReadyException The model specified in the request is not ready to serve inference requests. The AWS SDK will automatically retry the operation up to 5 times. For information about configuring automatic retries, see Retry behavior in the AWS SDKs and Tools reference guide.
- 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:
-
converseStream
default CompletableFuture<Void> converseStream(Consumer<ConverseStreamRequest.Builder> converseStreamRequest, ConverseStreamResponseHandler asyncResponseHandler) Sends messages to the specified Amazon Bedrock model and returns the response in a stream.
ConverseStreamprovides 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 and check the
responseStreamingSupportedfield in the response.The CLI doesn't support streaming operations in Amazon Bedrock, including
ConverseStream.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
messagesfield, specifying themodelIdof 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
promptVariablesfield. You can append more messages to the prompt by using themessagesfield. If you use a prompt from Prompt management, you can't include the following fields in the request:additionalModelRequestFields,inferenceConfig,system, ortoolConfig. 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:InvokeModelWithResponseStreamaction.To deny all inference access to resources that you specify in the modelId field, you need to deny access to the
bedrock:InvokeModelandbedrock:InvokeModelWithResponseStreamactions. 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
ConverseStreamAPI, see Troubleshooting Amazon Bedrock API Error Codes in the Amazon Bedrock User Guide
This is a convenience which creates an instance of the
ConverseStreamRequest.Builderavoiding the need to create one manually viaConverseStreamRequest.builder()- Parameters:
converseStreamRequest- AConsumerthat will call methods onConverseStreamRequest.Builderto create a request.- Returns:
- A Java Future containing the result of the ConverseStream 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 invokeThrowable.getCause()to retrieve the underlying exception.- AccessDeniedException The request is denied because you do not have sufficient permissions to perform the requested action. For troubleshooting this error, see AccessDeniedException in the Amazon Bedrock User Guide
- ThrottlingException Your request was denied due to exceeding the account quotas for Amazon Bedrock. For troubleshooting this error, see ThrottlingException in the Amazon Bedrock User Guide
- ResourceNotFoundException The specified resource ARN was not found. For troubleshooting this error, see ResourceNotFound in the Amazon Bedrock User Guide
- ModelTimeoutException The request took too long to process. Processing time exceeded the model timeout length.
- InternalServerException An internal server error occurred. For troubleshooting this error, see InternalFailure in the Amazon Bedrock User Guide
- ServiceUnavailableException The service isn't currently available. For troubleshooting this error, see ServiceUnavailable in the Amazon Bedrock User Guide
- ValidationException The input fails to satisfy the constraints specified by Amazon Bedrock. For troubleshooting this error, see ValidationError in the Amazon Bedrock User Guide
- ModelNotReadyException The model specified in the request is not ready to serve inference requests. The AWS SDK will automatically retry the operation up to 5 times. For information about configuring automatic retries, see Retry behavior in the AWS SDKs and Tools reference guide.
- 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:
-
countTokens
Returns the token count for a given inference request. This operation helps you estimate token usage before sending requests to foundation models by returning the token count that would be used if the same input were sent to the model in an inference request.
Token counting is model-specific because different models use different tokenization strategies. The token count returned by this operation will match the token count that would be charged if the same input were sent to the model in an
InvokeModelorConverserequest.You can use this operation to:
-
Estimate costs before sending inference requests.
-
Optimize prompts to fit within token limits.
-
Plan for token usage in your applications.
This operation accepts the same input formats as
InvokeModelandConverse, allowing you to count tokens for both raw text inputs and structured conversation formats.The following operations are related to
CountTokens:-
InvokeModel - Sends inference requests to foundation models
-
Converse - Sends conversation-based inference requests to foundation models
- Parameters:
countTokensRequest-- Returns:
- A Java Future containing the result of the CountTokens 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 invokeThrowable.getCause()to retrieve the underlying exception.- AccessDeniedException The request is denied because you do not have sufficient permissions to perform the requested action. For troubleshooting this error, see AccessDeniedException in the Amazon Bedrock User Guide
- ResourceNotFoundException The specified resource ARN was not found. For troubleshooting this error, see ResourceNotFound in the Amazon Bedrock User Guide
- ThrottlingException Your request was denied due to exceeding the account quotas for Amazon Bedrock. For troubleshooting this error, see ThrottlingException in the Amazon Bedrock User Guide
- InternalServerException An internal server error occurred. For troubleshooting this error, see InternalFailure in the Amazon Bedrock User Guide
- ServiceUnavailableException The service isn't currently available. For troubleshooting this error, see ServiceUnavailable in the Amazon Bedrock User Guide
- ValidationException The input fails to satisfy the constraints specified by Amazon Bedrock. For troubleshooting this error, see ValidationError in the Amazon Bedrock User Guide
- 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:
-
-
countTokens
default CompletableFuture<CountTokensResponse> countTokens(Consumer<CountTokensRequest.Builder> countTokensRequest) Returns the token count for a given inference request. This operation helps you estimate token usage before sending requests to foundation models by returning the token count that would be used if the same input were sent to the model in an inference request.
Token counting is model-specific because different models use different tokenization strategies. The token count returned by this operation will match the token count that would be charged if the same input were sent to the model in an
InvokeModelorConverserequest.You can use this operation to:
-
Estimate costs before sending inference requests.
-
Optimize prompts to fit within token limits.
-
Plan for token usage in your applications.
This operation accepts the same input formats as
InvokeModelandConverse, allowing you to count tokens for both raw text inputs and structured conversation formats.The following operations are related to
CountTokens:-
InvokeModel - Sends inference requests to foundation models
-
Converse - Sends conversation-based inference requests to foundation models
This is a convenience which creates an instance of the
CountTokensRequest.Builderavoiding the need to create one manually viaCountTokensRequest.builder()- Parameters:
countTokensRequest- AConsumerthat will call methods onCountTokensRequest.Builderto create a request.- Returns:
- A Java Future containing the result of the CountTokens 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 invokeThrowable.getCause()to retrieve the underlying exception.- AccessDeniedException The request is denied because you do not have sufficient permissions to perform the requested action. For troubleshooting this error, see AccessDeniedException in the Amazon Bedrock User Guide
- ResourceNotFoundException The specified resource ARN was not found. For troubleshooting this error, see ResourceNotFound in the Amazon Bedrock User Guide
- ThrottlingException Your request was denied due to exceeding the account quotas for Amazon Bedrock. For troubleshooting this error, see ThrottlingException in the Amazon Bedrock User Guide
- InternalServerException An internal server error occurred. For troubleshooting this error, see InternalFailure in the Amazon Bedrock User Guide
- ServiceUnavailableException The service isn't currently available. For troubleshooting this error, see ServiceUnavailable in the Amazon Bedrock User Guide
- ValidationException The input fails to satisfy the constraints specified by Amazon Bedrock. For troubleshooting this error, see ValidationError in the Amazon Bedrock User Guide
- 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:
-
-
getAsyncInvoke
default CompletableFuture<GetAsyncInvokeResponse> getAsyncInvoke(GetAsyncInvokeRequest getAsyncInvokeRequest) Retrieve information about an asynchronous invocation.
- Parameters:
getAsyncInvokeRequest-- Returns:
- A Java Future containing the result of the GetAsyncInvoke 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 invokeThrowable.getCause()to retrieve the underlying exception.- AccessDeniedException The request is denied because you do not have sufficient permissions to perform the requested action. For troubleshooting this error, see AccessDeniedException in the Amazon Bedrock User Guide
- ThrottlingException Your request was denied due to exceeding the account quotas for Amazon Bedrock. For troubleshooting this error, see ThrottlingException in the Amazon Bedrock User Guide
- InternalServerException An internal server error occurred. For troubleshooting this error, see InternalFailure in the Amazon Bedrock User Guide
- ValidationException The input fails to satisfy the constraints specified by Amazon Bedrock. For troubleshooting this error, see ValidationError in the Amazon Bedrock User Guide
- 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:
-
getAsyncInvoke
default CompletableFuture<GetAsyncInvokeResponse> getAsyncInvoke(Consumer<GetAsyncInvokeRequest.Builder> getAsyncInvokeRequest) Retrieve information about an asynchronous invocation.
This is a convenience which creates an instance of the
GetAsyncInvokeRequest.Builderavoiding the need to create one manually viaGetAsyncInvokeRequest.builder()- Parameters:
getAsyncInvokeRequest- AConsumerthat will call methods onGetAsyncInvokeRequest.Builderto create a request.- Returns:
- A Java Future containing the result of the GetAsyncInvoke 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 invokeThrowable.getCause()to retrieve the underlying exception.- AccessDeniedException The request is denied because you do not have sufficient permissions to perform the requested action. For troubleshooting this error, see AccessDeniedException in the Amazon Bedrock User Guide
- ThrottlingException Your request was denied due to exceeding the account quotas for Amazon Bedrock. For troubleshooting this error, see ThrottlingException in the Amazon Bedrock User Guide
- InternalServerException An internal server error occurred. For troubleshooting this error, see InternalFailure in the Amazon Bedrock User Guide
- ValidationException The input fails to satisfy the constraints specified by Amazon Bedrock. For troubleshooting this error, see ValidationError in the Amazon Bedrock User Guide
- 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
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:InvokeModelaction.To deny all inference access to resources that you specify in the modelId field, you need to deny access to the
bedrock:InvokeModelandbedrock:InvokeModelWithResponseStreamactions. 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
InvokeModelAPI, see Troubleshooting Amazon Bedrock API Error Codes in the Amazon Bedrock User Guide- 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 invokeThrowable.getCause()to retrieve the underlying exception.- AccessDeniedException The request is denied because you do not have sufficient permissions to perform the requested action. For troubleshooting this error, see AccessDeniedException in the Amazon Bedrock User Guide
- ResourceNotFoundException The specified resource ARN was not found. For troubleshooting this error, see ResourceNotFound in the Amazon Bedrock User Guide
- ThrottlingException Your request was denied due to exceeding the account quotas for Amazon Bedrock. For troubleshooting this error, see ThrottlingException in the Amazon Bedrock User Guide
- ModelTimeoutException The request took too long to process. Processing time exceeded the model timeout length.
- InternalServerException An internal server error occurred. For troubleshooting this error, see InternalFailure in the Amazon Bedrock User Guide
- ServiceUnavailableException The service isn't currently available. For troubleshooting this error, see ServiceUnavailable in the Amazon Bedrock User Guide
- ValidationException The input fails to satisfy the constraints specified by Amazon Bedrock. For troubleshooting this error, see ValidationError in the Amazon Bedrock User Guide
- ServiceQuotaExceededException Your request exceeds the service quota for your account. You can view your quotas at Viewing service quotas. You can resubmit your request later.
- ModelNotReadyException The model specified in the request is not ready to serve inference requests. The AWS SDK will automatically retry the operation up to 5 times. For information about configuring automatic retries, see Retry behavior in the AWS SDKs and Tools reference guide.
- 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:InvokeModelaction.To deny all inference access to resources that you specify in the modelId field, you need to deny access to the
bedrock:InvokeModelandbedrock:InvokeModelWithResponseStreamactions. 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
InvokeModelAPI, see Troubleshooting Amazon Bedrock API Error Codes in the Amazon Bedrock User Guide
This is a convenience which creates an instance of the
InvokeModelRequest.Builderavoiding the need to create one manually viaInvokeModelRequest.builder()- Parameters:
invokeModelRequest- AConsumerthat will call methods onInvokeModelRequest.Builderto 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 invokeThrowable.getCause()to retrieve the underlying exception.- AccessDeniedException The request is denied because you do not have sufficient permissions to perform the requested action. For troubleshooting this error, see AccessDeniedException in the Amazon Bedrock User Guide
- ResourceNotFoundException The specified resource ARN was not found. For troubleshooting this error, see ResourceNotFound in the Amazon Bedrock User Guide
- ThrottlingException Your request was denied due to exceeding the account quotas for Amazon Bedrock. For troubleshooting this error, see ThrottlingException in the Amazon Bedrock User Guide
- ModelTimeoutException The request took too long to process. Processing time exceeded the model timeout length.
- InternalServerException An internal server error occurred. For troubleshooting this error, see InternalFailure in the Amazon Bedrock User Guide
- ServiceUnavailableException The service isn't currently available. For troubleshooting this error, see ServiceUnavailable in the Amazon Bedrock User Guide
- ValidationException The input fails to satisfy the constraints specified by Amazon Bedrock. For troubleshooting this error, see ValidationError in the Amazon Bedrock User Guide
- ServiceQuotaExceededException Your request exceeds the service quota for your account. You can view your quotas at Viewing service quotas. You can resubmit your request later.
- ModelNotReadyException The model specified in the request is not ready to serve inference requests. The AWS SDK will automatically retry the operation up to 5 times. For information about configuring automatic retries, see Retry behavior in the AWS SDKs and Tools reference guide.
- 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:
-
invokeModelWithBidirectionalStream
default CompletableFuture<Void> invokeModelWithBidirectionalStream(InvokeModelWithBidirectionalStreamRequest invokeModelWithBidirectionalStreamRequest, org.reactivestreams.Publisher<InvokeModelWithBidirectionalStreamInput> requestStream, InvokeModelWithBidirectionalStreamResponseHandler asyncResponseHandler) Invoke the specified Amazon Bedrock model to run inference using the bidirectional stream. The response is returned in a stream that remains open for 8 minutes. A single session can contain multiple prompts and responses from the model. The prompts to the model are provided as audio files and the model's responses are spoken back to the user and transcribed.
It is possible for users to interrupt the model's response with a new prompt, which will halt the response speech. The model will retain contextual awareness of the conversation while pivoting to respond to the new prompt.
- Parameters:
invokeModelWithBidirectionalStreamRequest-- Returns:
- A Java Future containing the result of the InvokeModelWithBidirectionalStream 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 invokeThrowable.getCause()to retrieve the underlying exception.- AccessDeniedException The request is denied because you do not have sufficient permissions to perform the requested action. For troubleshooting this error, see AccessDeniedException in the Amazon Bedrock User Guide
- ResourceNotFoundException The specified resource ARN was not found. For troubleshooting this error, see ResourceNotFound in the Amazon Bedrock User Guide
- ThrottlingException Your request was denied due to exceeding the account quotas for Amazon Bedrock. For troubleshooting this error, see ThrottlingException in the Amazon Bedrock User Guide
- ModelTimeoutException The request took too long to process. Processing time exceeded the model timeout length.
- InternalServerException An internal server error occurred. For troubleshooting this error, see InternalFailure in the Amazon Bedrock User Guide
- ServiceUnavailableException The service isn't currently available. For troubleshooting this error, see ServiceUnavailable in the Amazon Bedrock User Guide
- ModelStreamErrorException An error occurred while streaming the response. Retry your request.
- ValidationException The input fails to satisfy the constraints specified by Amazon Bedrock. For troubleshooting this error, see ValidationError in the Amazon Bedrock User Guide
- ServiceQuotaExceededException Your request exceeds the service quota for your account. You can view your quotas at Viewing service quotas. You can resubmit your request later.
- ModelNotReadyException The model specified in the request is not ready to serve inference requests. The AWS SDK will automatically retry the operation up to 5 times. For information about configuring automatic retries, see Retry behavior in the AWS SDKs and Tools reference guide.
- 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:
-
invokeModelWithBidirectionalStream
default CompletableFuture<Void> invokeModelWithBidirectionalStream(Consumer<InvokeModelWithBidirectionalStreamRequest.Builder> invokeModelWithBidirectionalStreamRequest, org.reactivestreams.Publisher<InvokeModelWithBidirectionalStreamInput> requestStream, InvokeModelWithBidirectionalStreamResponseHandler asyncResponseHandler) Invoke the specified Amazon Bedrock model to run inference using the bidirectional stream. The response is returned in a stream that remains open for 8 minutes. A single session can contain multiple prompts and responses from the model. The prompts to the model are provided as audio files and the model's responses are spoken back to the user and transcribed.
It is possible for users to interrupt the model's response with a new prompt, which will halt the response speech. The model will retain contextual awareness of the conversation while pivoting to respond to the new prompt.
This is a convenience which creates an instance of the
InvokeModelWithBidirectionalStreamRequest.Builderavoiding the need to create one manually viaInvokeModelWithBidirectionalStreamRequest.builder()- Parameters:
invokeModelWithBidirectionalStreamRequest- AConsumerthat will call methods onInvokeModelWithBidirectionalStreamRequest.Builderto create a request.- Returns:
- A Java Future containing the result of the InvokeModelWithBidirectionalStream 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 invokeThrowable.getCause()to retrieve the underlying exception.- AccessDeniedException The request is denied because you do not have sufficient permissions to perform the requested action. For troubleshooting this error, see AccessDeniedException in the Amazon Bedrock User Guide
- ResourceNotFoundException The specified resource ARN was not found. For troubleshooting this error, see ResourceNotFound in the Amazon Bedrock User Guide
- ThrottlingException Your request was denied due to exceeding the account quotas for Amazon Bedrock. For troubleshooting this error, see ThrottlingException in the Amazon Bedrock User Guide
- ModelTimeoutException The request took too long to process. Processing time exceeded the model timeout length.
- InternalServerException An internal server error occurred. For troubleshooting this error, see InternalFailure in the Amazon Bedrock User Guide
- ServiceUnavailableException The service isn't currently available. For troubleshooting this error, see ServiceUnavailable in the Amazon Bedrock User Guide
- ModelStreamErrorException An error occurred while streaming the response. Retry your request.
- ValidationException The input fails to satisfy the constraints specified by Amazon Bedrock. For troubleshooting this error, see ValidationError in the Amazon Bedrock User Guide
- ServiceQuotaExceededException Your request exceeds the service quota for your account. You can view your quotas at Viewing service quotas. You can resubmit your request later.
- ModelNotReadyException The model specified in the request is not ready to serve inference requests. The AWS SDK will automatically retry the operation up to 5 times. For information about configuring automatic retries, see Retry behavior in the AWS SDKs and Tools reference guide.
- 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
responseStreamingSupportedfield in the response.The CLI doesn't support streaming operations in Amazon Bedrock, including
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:InvokeModelWithResponseStreamaction.To deny all inference access to resources that you specify in the modelId field, you need to deny access to the
bedrock:InvokeModelandbedrock:InvokeModelWithResponseStreamactions. 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
InvokeModelWithResponseStreamAPI, see Troubleshooting Amazon Bedrock API Error Codes in the Amazon Bedrock User Guide- 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 invokeThrowable.getCause()to retrieve the underlying exception.- AccessDeniedException The request is denied because you do not have sufficient permissions to perform the requested action. For troubleshooting this error, see AccessDeniedException in the Amazon Bedrock User Guide
- ResourceNotFoundException The specified resource ARN was not found. For troubleshooting this error, see ResourceNotFound in the Amazon Bedrock User Guide
- ThrottlingException Your request was denied due to exceeding the account quotas for Amazon Bedrock. For troubleshooting this error, see ThrottlingException in the Amazon Bedrock User Guide
- ModelTimeoutException The request took too long to process. Processing time exceeded the model timeout length.
- InternalServerException An internal server error occurred. For troubleshooting this error, see InternalFailure in the Amazon Bedrock User Guide
- ServiceUnavailableException The service isn't currently available. For troubleshooting this error, see ServiceUnavailable in the Amazon Bedrock User Guide
- ModelStreamErrorException An error occurred while streaming the response. Retry your request.
- ValidationException The input fails to satisfy the constraints specified by Amazon Bedrock. For troubleshooting this error, see ValidationError in the Amazon Bedrock User Guide
- ServiceQuotaExceededException Your request exceeds the service quota for your account. You can view your quotas at Viewing service quotas. You can resubmit your request later.
- ModelNotReadyException The model specified in the request is not ready to serve inference requests. The AWS SDK will automatically retry the operation up to 5 times. For information about configuring automatic retries, see Retry behavior in the AWS SDKs and Tools reference guide.
- 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
responseStreamingSupportedfield in the response.The CLI doesn't support streaming operations in Amazon Bedrock, including
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:InvokeModelWithResponseStreamaction.To deny all inference access to resources that you specify in the modelId field, you need to deny access to the
bedrock:InvokeModelandbedrock:InvokeModelWithResponseStreamactions. 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
InvokeModelWithResponseStreamAPI, see Troubleshooting Amazon Bedrock API Error Codes in the Amazon Bedrock User Guide
This is a convenience which creates an instance of the
InvokeModelWithResponseStreamRequest.Builderavoiding the need to create one manually viaInvokeModelWithResponseStreamRequest.builder()- Parameters:
invokeModelWithResponseStreamRequest- AConsumerthat will call methods onInvokeModelWithResponseStreamRequest.Builderto 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 invokeThrowable.getCause()to retrieve the underlying exception.- AccessDeniedException The request is denied because you do not have sufficient permissions to perform the requested action. For troubleshooting this error, see AccessDeniedException in the Amazon Bedrock User Guide
- ResourceNotFoundException The specified resource ARN was not found. For troubleshooting this error, see ResourceNotFound in the Amazon Bedrock User Guide
- ThrottlingException Your request was denied due to exceeding the account quotas for Amazon Bedrock. For troubleshooting this error, see ThrottlingException in the Amazon Bedrock User Guide
- ModelTimeoutException The request took too long to process. Processing time exceeded the model timeout length.
- InternalServerException An internal server error occurred. For troubleshooting this error, see InternalFailure in the Amazon Bedrock User Guide
- ServiceUnavailableException The service isn't currently available. For troubleshooting this error, see ServiceUnavailable in the Amazon Bedrock User Guide
- ModelStreamErrorException An error occurred while streaming the response. Retry your request.
- ValidationException The input fails to satisfy the constraints specified by Amazon Bedrock. For troubleshooting this error, see ValidationError in the Amazon Bedrock User Guide
- ServiceQuotaExceededException Your request exceeds the service quota for your account. You can view your quotas at Viewing service quotas. You can resubmit your request later.
- ModelNotReadyException The model specified in the request is not ready to serve inference requests. The AWS SDK will automatically retry the operation up to 5 times. For information about configuring automatic retries, see Retry behavior in the AWS SDKs and Tools reference guide.
- 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:
-
listAsyncInvokes
default CompletableFuture<ListAsyncInvokesResponse> listAsyncInvokes(ListAsyncInvokesRequest listAsyncInvokesRequest) Lists asynchronous invocations.
- Parameters:
listAsyncInvokesRequest-- Returns:
- A Java Future containing the result of the ListAsyncInvokes 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 invokeThrowable.getCause()to retrieve the underlying exception.- AccessDeniedException The request is denied because you do not have sufficient permissions to perform the requested action. For troubleshooting this error, see AccessDeniedException in the Amazon Bedrock User Guide
- ThrottlingException Your request was denied due to exceeding the account quotas for Amazon Bedrock. For troubleshooting this error, see ThrottlingException in the Amazon Bedrock User Guide
- InternalServerException An internal server error occurred. For troubleshooting this error, see InternalFailure in the Amazon Bedrock User Guide
- ValidationException The input fails to satisfy the constraints specified by Amazon Bedrock. For troubleshooting this error, see ValidationError in the Amazon Bedrock User Guide
- 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:
-
listAsyncInvokes
default CompletableFuture<ListAsyncInvokesResponse> listAsyncInvokes(Consumer<ListAsyncInvokesRequest.Builder> listAsyncInvokesRequest) Lists asynchronous invocations.
This is a convenience which creates an instance of the
ListAsyncInvokesRequest.Builderavoiding the need to create one manually viaListAsyncInvokesRequest.builder()- Parameters:
listAsyncInvokesRequest- AConsumerthat will call methods onListAsyncInvokesRequest.Builderto create a request.- Returns:
- A Java Future containing the result of the ListAsyncInvokes 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 invokeThrowable.getCause()to retrieve the underlying exception.- AccessDeniedException The request is denied because you do not have sufficient permissions to perform the requested action. For troubleshooting this error, see AccessDeniedException in the Amazon Bedrock User Guide
- ThrottlingException Your request was denied due to exceeding the account quotas for Amazon Bedrock. For troubleshooting this error, see ThrottlingException in the Amazon Bedrock User Guide
- InternalServerException An internal server error occurred. For troubleshooting this error, see InternalFailure in the Amazon Bedrock User Guide
- ValidationException The input fails to satisfy the constraints specified by Amazon Bedrock. For troubleshooting this error, see ValidationError in the Amazon Bedrock User Guide
- 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:
-
listAsyncInvokesPaginator
default ListAsyncInvokesPublisher listAsyncInvokesPaginator(ListAsyncInvokesRequest listAsyncInvokesRequest) This is a variant of
listAsyncInvokes(software.amazon.awssdk.services.bedrockruntime.model.ListAsyncInvokesRequest)operation. The return type is a custom publisher that can be subscribed to request a stream of response pages. SDK will internally handle making service calls for you.When the operation is called, an instance of this class is returned. At this point, no service calls are made yet and so there is no guarantee that the request is valid. If there are errors in your request, you will see the failures only after you start streaming the data. The subscribe method should be called as a request to start streaming data. For more info, see
Publisher.subscribe(org.reactivestreams.Subscriber). Each call to the subscribe method will result in a newSubscriptioni.e., a new contract to stream data from the starting request.The following are few ways to use the response class:
1) Using the subscribe helper method
2) Using a custom subscribersoftware.amazon.awssdk.services.bedrockruntime.paginators.ListAsyncInvokesPublisher publisher = client.listAsyncInvokesPaginator(request); CompletableFuture<Void> future = publisher.subscribe(res -> { // Do something with the response }); future.get();
As the response is a publisher, it can work well with third party reactive streams implementations like RxJava2.software.amazon.awssdk.services.bedrockruntime.paginators.ListAsyncInvokesPublisher publisher = client.listAsyncInvokesPaginator(request); publisher.subscribe(new Subscriber<software.amazon.awssdk.services.bedrockruntime.model.ListAsyncInvokesResponse>() { public void onSubscribe(org.reactivestreams.Subscriber subscription) { //... }; public void onNext(software.amazon.awssdk.services.bedrockruntime.model.ListAsyncInvokesResponse response) { //... }; });Please notice that the configuration of maxResults won't limit the number of results you get with the paginator. It only limits the number of results in each page.
Note: If you prefer to have control on service calls, use the
listAsyncInvokes(software.amazon.awssdk.services.bedrockruntime.model.ListAsyncInvokesRequest)operation.- Parameters:
listAsyncInvokesRequest-- Returns:
- A custom publisher that can be subscribed to request a stream of response pages.
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 invokeThrowable.getCause()to retrieve the underlying exception.- AccessDeniedException The request is denied because you do not have sufficient permissions to perform the requested action. For troubleshooting this error, see AccessDeniedException in the Amazon Bedrock User Guide
- ThrottlingException Your request was denied due to exceeding the account quotas for Amazon Bedrock. For troubleshooting this error, see ThrottlingException in the Amazon Bedrock User Guide
- InternalServerException An internal server error occurred. For troubleshooting this error, see InternalFailure in the Amazon Bedrock User Guide
- ValidationException The input fails to satisfy the constraints specified by Amazon Bedrock. For troubleshooting this error, see ValidationError in the Amazon Bedrock User Guide
- 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:
-
listAsyncInvokesPaginator
default ListAsyncInvokesPublisher listAsyncInvokesPaginator(Consumer<ListAsyncInvokesRequest.Builder> listAsyncInvokesRequest) This is a variant of
listAsyncInvokes(software.amazon.awssdk.services.bedrockruntime.model.ListAsyncInvokesRequest)operation. The return type is a custom publisher that can be subscribed to request a stream of response pages. SDK will internally handle making service calls for you.When the operation is called, an instance of this class is returned. At this point, no service calls are made yet and so there is no guarantee that the request is valid. If there are errors in your request, you will see the failures only after you start streaming the data. The subscribe method should be called as a request to start streaming data. For more info, see
Publisher.subscribe(org.reactivestreams.Subscriber). Each call to the subscribe method will result in a newSubscriptioni.e., a new contract to stream data from the starting request.The following are few ways to use the response class:
1) Using the subscribe helper method
2) Using a custom subscribersoftware.amazon.awssdk.services.bedrockruntime.paginators.ListAsyncInvokesPublisher publisher = client.listAsyncInvokesPaginator(request); CompletableFuture<Void> future = publisher.subscribe(res -> { // Do something with the response }); future.get();
As the response is a publisher, it can work well with third party reactive streams implementations like RxJava2.software.amazon.awssdk.services.bedrockruntime.paginators.ListAsyncInvokesPublisher publisher = client.listAsyncInvokesPaginator(request); publisher.subscribe(new Subscriber<software.amazon.awssdk.services.bedrockruntime.model.ListAsyncInvokesResponse>() { public void onSubscribe(org.reactivestreams.Subscriber subscription) { //... }; public void onNext(software.amazon.awssdk.services.bedrockruntime.model.ListAsyncInvokesResponse response) { //... }; });Please notice that the configuration of maxResults won't limit the number of results you get with the paginator. It only limits the number of results in each page.
Note: If you prefer to have control on service calls, use the
listAsyncInvokes(software.amazon.awssdk.services.bedrockruntime.model.ListAsyncInvokesRequest)operation.
This is a convenience which creates an instance of the
ListAsyncInvokesRequest.Builderavoiding the need to create one manually viaListAsyncInvokesRequest.builder()- Parameters:
listAsyncInvokesRequest- AConsumerthat will call methods onListAsyncInvokesRequest.Builderto create a request.- Returns:
- A custom publisher that can be subscribed to request a stream of response pages.
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 invokeThrowable.getCause()to retrieve the underlying exception.- AccessDeniedException The request is denied because you do not have sufficient permissions to perform the requested action. For troubleshooting this error, see AccessDeniedException in the Amazon Bedrock User Guide
- ThrottlingException Your request was denied due to exceeding the account quotas for Amazon Bedrock. For troubleshooting this error, see ThrottlingException in the Amazon Bedrock User Guide
- InternalServerException An internal server error occurred. For troubleshooting this error, see InternalFailure in the Amazon Bedrock User Guide
- ValidationException The input fails to satisfy the constraints specified by Amazon Bedrock. For troubleshooting this error, see ValidationError in the Amazon Bedrock User Guide
- 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:
-
startAsyncInvoke
default CompletableFuture<StartAsyncInvokeResponse> startAsyncInvoke(StartAsyncInvokeRequest startAsyncInvokeRequest) Starts an asynchronous invocation.
This operation requires permission for the
bedrock:InvokeModelaction.To deny all inference access to resources that you specify in the modelId field, you need to deny access to the
bedrock:InvokeModelandbedrock:InvokeModelWithResponseStreamactions. 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.- Parameters:
startAsyncInvokeRequest-- Returns:
- A Java Future containing the result of the StartAsyncInvoke 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 invokeThrowable.getCause()to retrieve the underlying exception.- AccessDeniedException The request is denied because you do not have sufficient permissions to perform the requested action. For troubleshooting this error, see AccessDeniedException in the Amazon Bedrock User Guide
- ThrottlingException Your request was denied due to exceeding the account quotas for Amazon Bedrock. For troubleshooting this error, see ThrottlingException in the Amazon Bedrock User Guide
- ResourceNotFoundException The specified resource ARN was not found. For troubleshooting this error, see ResourceNotFound in the Amazon Bedrock User Guide
- InternalServerException An internal server error occurred. For troubleshooting this error, see InternalFailure in the Amazon Bedrock User Guide
- ServiceUnavailableException The service isn't currently available. For troubleshooting this error, see ServiceUnavailable in the Amazon Bedrock User Guide
- ValidationException The input fails to satisfy the constraints specified by Amazon Bedrock. For troubleshooting this error, see ValidationError in the Amazon Bedrock User Guide
- ServiceQuotaExceededException Your request exceeds the service quota for your account. You can view your quotas at Viewing service quotas. You can resubmit your request later.
- ConflictException Error occurred because of a conflict while performing an operation.
- 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:
-
startAsyncInvoke
default CompletableFuture<StartAsyncInvokeResponse> startAsyncInvoke(Consumer<StartAsyncInvokeRequest.Builder> startAsyncInvokeRequest) Starts an asynchronous invocation.
This operation requires permission for the
bedrock:InvokeModelaction.To deny all inference access to resources that you specify in the modelId field, you need to deny access to the
bedrock:InvokeModelandbedrock:InvokeModelWithResponseStreamactions. 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.
This is a convenience which creates an instance of the
StartAsyncInvokeRequest.Builderavoiding the need to create one manually viaStartAsyncInvokeRequest.builder()- Parameters:
startAsyncInvokeRequest- AConsumerthat will call methods onStartAsyncInvokeRequest.Builderto create a request.- Returns:
- A Java Future containing the result of the StartAsyncInvoke 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 invokeThrowable.getCause()to retrieve the underlying exception.- AccessDeniedException The request is denied because you do not have sufficient permissions to perform the requested action. For troubleshooting this error, see AccessDeniedException in the Amazon Bedrock User Guide
- ThrottlingException Your request was denied due to exceeding the account quotas for Amazon Bedrock. For troubleshooting this error, see ThrottlingException in the Amazon Bedrock User Guide
- ResourceNotFoundException The specified resource ARN was not found. For troubleshooting this error, see ResourceNotFound in the Amazon Bedrock User Guide
- InternalServerException An internal server error occurred. For troubleshooting this error, see InternalFailure in the Amazon Bedrock User Guide
- ServiceUnavailableException The service isn't currently available. For troubleshooting this error, see ServiceUnavailable in the Amazon Bedrock User Guide
- ValidationException The input fails to satisfy the constraints specified by Amazon Bedrock. For troubleshooting this error, see ValidationError in the Amazon Bedrock User Guide
- ServiceQuotaExceededException Your request exceeds the service quota for your account. You can view your quotas at Viewing service quotas. You can resubmit your request later.
- ConflictException Error occurred because of a conflict while performing an operation.
- 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
Description copied from interface:SdkClientThe SDK service client configuration exposes client settings to the user, e.g., ClientOverrideConfiguration- Specified by:
serviceClientConfigurationin interfaceAwsClient- Specified by:
serviceClientConfigurationin interfaceSdkClient- Returns:
- SdkServiceClientConfiguration
-
create
Create aBedrockRuntimeAsyncClientwith the region loaded from theDefaultAwsRegionProviderChainand credentials loaded from theDefaultCredentialsProvider. -
builder
Create a builder that can be used to configure and create aBedrockRuntimeAsyncClient.
-