11import os
2- import uuid
32from typing import Any
43from typing import AsyncIterator
54from typing import Callable
@@ -94,6 +93,7 @@ def __init__(
9493 http_client : Optional [httpx .Client ] = None ,
9594 api_key : Optional [str ] = None ,
9695 obo_token_getter : Optional [Callable [[], Optional [str ]]] = None ,
96+ streaming : bool = False ,
9797 ** kwargs : Any ,
9898 ) -> None :
9999 prefix , actual_model = self ._parse_identifier (model_name )
@@ -131,11 +131,10 @@ def __init__(
131131
132132 token_env = os .environ .get ('SINGLESTOREDB_USER_TOKEN' )
133133 token = api_key if api_key is not None else token_env
134- # Generate a per-instance client ID for tracing Bedrock calls.
135- self ._client_id = str (uuid .uuid4 ())
136134 self ._client = ChatBedrockConverse (
137135 base_url = info .connection_url ,
138136 model = actual_model ,
137+ streaming = streaming ,
139138 ** kwargs ,
140139 )
141140
@@ -148,8 +147,11 @@ def __init__(
148147 merged_headers .update ({k : v for k , v in provided_headers .items ()})
149148 if token :
150149 merged_headers .setdefault ('Authorization' , f'Bearer { token } ' )
151- # Always include X-ClientID for Bedrock path
152- merged_headers .setdefault ('X-ClientID' , self ._client_id )
150+ # Add Bedrock converse headers based on streaming flag
151+ if streaming :
152+ merged_headers .setdefault ('X-BEDROCK-CONVERSE-STREAMING' , 'true' )
153+ else :
154+ merged_headers .setdefault ('X-BEDROCK-CONVERSE' , 'true' )
153155 if merged_headers :
154156 # Try to set directly if backend exposes default_headers
155157 if (
@@ -180,6 +182,7 @@ def __init__(
180182 base_url = info .connection_url ,
181183 api_key = token ,
182184 model = actual_model ,
185+ streaming = streaming ,
183186 )
184187 if http_client is not None :
185188 # Some versions accept 'http_client' parameter for custom transport.
@@ -198,6 +201,7 @@ def __init__(
198201 # If supplied, a new token will be fetched and injected into the
199202 # 'X-S2-OBO' header for every Bedrock request made via this wrapper.
200203 self ._obo_token_getter = obo_token_getter
204+ self ._streaming = streaming
201205
202206 @classmethod
203207 def _parse_identifier (cls , identifier : str ) -> tuple [str , str ]:
0 commit comments