Amazon Bedrock Runtime

2025/04/08 - Amazon Bedrock Runtime - 1 new api methods

Changes  This release introduces our latest bedrock runtime API, InvokeModelWithBidirectionalStream. The API supports both input and output streams and is supported by only HTTP2.0.

InvokeModelWithBidirectionalStream (new) Link ΒΆ

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.

See also: AWS API Documentation

Request Syntax

client.invoke_model_with_bidirectional_stream(
    modelId='string',
    body=EventStream()
)
type modelId:

string

param modelId:

[REQUIRED]

The model ID or ARN of the model ID to use. Currently, only amazon.nova-sonic-v1:0 is supported.

type body:

:class:`.EventStream`

param body:

[REQUIRED]

The prompt and inference parameters in the format specified in the BidirectionalInputPayloadPart in the header. You must provide the body in JSON format. To see the format and content of the request and response bodies for different models, refer to Inference parameters. For more information, see Run inference in the Bedrock User Guide.

rtype:

dict

returns:

The response of this operation contains an :class:`.EventStream` member. When iterated the :class:`.EventStream` will yield events based on the structure below, where only one of the top level keys will be present for any given event.

Response Syntax

{
    'body': EventStream({
        'chunk': {
            'bytes': b'bytes'
        },
        'internalServerException': {
            'message': 'string'
        },
        'modelStreamErrorException': {
            'message': 'string',
            'originalStatusCode': 123,
            'originalMessage': 'string'
        },
        'validationException': {
            'message': 'string'
        },
        'throttlingException': {
            'message': 'string'
        },
        'modelTimeoutException': {
            'message': 'string'
        },
        'serviceUnavailableException': {
            'message': 'string'
        }
    })
}

Response Structure

  • (dict) --

    • body (:class:`.EventStream`) --

      Streaming response from the model in the format specified by the BidirectionalOutputPayloadPart header.

      • chunk (dict) --

        The speech chunk that was provided as output from the invocation step.

        • bytes (bytes) --

          The speech output of the bidirectional stream.

      • internalServerException (dict) --

        The request encountered an unknown internal error.

        • message (string) --

      • modelStreamErrorException (dict) --

        The request encountered an error with the model stream.

        • message (string) --

        • originalStatusCode (integer) --

          The original status code.

        • originalMessage (string) --

          The original message.

      • validationException (dict) --

        The input fails to satisfy the constraints specified by an Amazon Web Services service.

        • message (string) --

      • throttlingException (dict) --

        The request was denied due to request throttling.

        • message (string) --

      • modelTimeoutException (dict) --

        The connection was closed because a request was not received within the timeout period.

        • message (string) --

      • serviceUnavailableException (dict) --

        The request has failed due to a temporary failure of the server.

        • message (string) --