ReqLLM.Bedrock.BidiStream (ReqLLM v1.17.0)

View Source

Low-level client for AWS Bedrock InvokeModelWithBidirectionalStream (e.g. Amazon Nova Sonic speech-to-speech).

Bidirectional streaming is HTTP/2 full-duplex: the client opens one request, streams SigV4 event-signed messages over time, and concurrently reads response event-stream messages back. This mirrors the shape of ReqLLM.OpenAI.Realtime (connect, send_event, next_event, close) but the transport is ReqLLM.Streaming.HTTP2DuplexSession (Mint HTTP/2), since the WebSockex-based WebSocketSession cannot do HTTP/2.

Each outbound event is framed as an AWS event-stream message whose payload is {"bytes": "<base64 of the event JSON>"} (the BidirectionalInputPayloadPart blob), wrapped in an outer signed message carrying :date and :chunk-signature, chained from the initial request's seed signature. Signing uses AWSAuth.EventStream. Inbound messages are decoded with the existing ReqLLM.Providers.AmazonBedrock.AWSEventStream parser.

Reads and writes are independent: next_event/2 parks asynchronously without blocking the session, so one process can stream audio via send_event/2 while another consumes responses.

Summary

Functions

Returns a specification to start this module under a supervisor.

Opens a bidirectional stream to model_id (e.g. "amazon.nova-sonic-v1:0").

Signal end of the outbound stream (half-close the request body).

Transport status + HTTP response status (for diagnostics).

Pull the next decoded inbound event. :halt once the stream ends.

Encode, sign, and send one model input event (a JSON-serializable map).

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

close(conn)

@spec close(ReqLLM.Bedrock.BidiStream.Conn.t()) :: :ok

connect(model_id, opts \\ [])

@spec connect(
  String.t(),
  keyword()
) :: {:ok, ReqLLM.Bedrock.BidiStream.Conn.t()} | {:error, term()}

Opens a bidirectional stream to model_id (e.g. "amazon.nova-sonic-v1:0").

Options:

  • :credentials - an %AWSAuth.Credentials{} (defaults to AWSAuth.Credentials.from_env/0)
  • :region - overrides the region from the credentials
  • :connect_timeout - ms to wait for the HTTP/2 request to open (default 15s)

done_sending(conn)

@spec done_sending(ReqLLM.Bedrock.BidiStream.Conn.t()) :: :ok | {:error, term()}

Signal end of the outbound stream (half-close the request body).

info(conn)

Transport status + HTTP response status (for diagnostics).

next_event(conn, timeout \\ 30000)

@spec next_event(ReqLLM.Bedrock.BidiStream.Conn.t(), timeout()) ::
  {:ok, map()} | :halt | {:error, term()}

Pull the next decoded inbound event. :halt once the stream ends.

send_event(conn, event)

@spec send_event(ReqLLM.Bedrock.BidiStream.Conn.t(), map()) :: :ok | {:error, term()}

Encode, sign, and send one model input event (a JSON-serializable map).