@@ -89,27 +89,20 @@ def __init__(
8989 Note: The client should not be shared across different asyncio event loops.
9090 client_args: Arguments for the OpenAI client (legacy approach).
9191 For a complete list of supported arguments, see https://pypi.org/project/openai/.
92- May be combined with ``aws_config``; transport-level options like ``http_client``,
93- ``timeout``, or ``default_headers`` are preserved, while ``base_url`` and
94- ``api_key`` are always overridden by ``aws_config`` when both are set.
92+ May be combined with ``aws_config``; when both are set, ``aws_config`` overrides
93+ ``base_url`` and ``api_key`` only.
9594 aws_config: Route requests through Amazon Bedrock's Mantle (OpenAI-compatible)
96- endpoint. Provide ``{"region": "us-east-1"}`` at minimum. Accepts optional
97- ``credentials_provider`` (a botocore ``CredentialProvider``) and ``expiry``
98- (a ``datetime.timedelta`` up to 12h). When set, a fresh bearer token is minted
99- on every request via ``aws-bedrock-token-generator`` and the OpenAI client is
100- pointed at ``https://bedrock-mantle.<region>.api.aws/v1``. Cannot be combined
101- with a pre-built ``client``.
95+ endpoint. See :class:`AwsConfig` for accepted keys. When set, a fresh bearer
96+ token is minted on every request. Cannot be combined with a pre-built ``client``.
10297 **model_config: Configuration options for the OpenAI model.
10398
10499 Raises:
105- ValueError: If ``client`` is combined with ``client_args`` or ``aws_config``,
106- or if ``aws_config`` is missing a region.
100+ ValueError: If ``client`` is combined with ``client_args`` or ``aws_config``.
107101 """
108102 validate_config_keys (model_config , self .OpenAIConfig )
109103 self .config = dict (model_config )
110104
111- # Validate that client configuration methods are mutually exclusive where they conflict.
112- # client_args + aws_config is allowed — aws_config will override base_url / api_key only.
105+ # client_args + aws_config is allowed; aws_config overrides base_url / api_key only.
113106 client_args_provided = client_args is not None and len (client_args ) > 0
114107 if client is not None and client_args_provided :
115108 raise ValueError ("Only one of 'client' or 'client_args' should be provided, not both." )
@@ -125,9 +118,7 @@ def __init__(
125118 def _resolve_client_args (self ) -> dict [str , Any ]:
126119 """Return the kwargs to pass to ``openai.AsyncOpenAI`` for the current request.
127120
128- When ``aws_config`` is set, a fresh Bedrock Mantle bearer token is minted on every
129- call and ``base_url`` / ``api_key`` are overridden. Any other entries from
130- ``client_args`` (e.g. ``http_client``, ``timeout``) are preserved.
121+ Delegates to :func:`resolve_bedrock_client_args` when ``aws_config`` is set.
131122 """
132123 if self ._aws_config is not None :
133124 return resolve_bedrock_client_args (self ._aws_config , self .client_args )
@@ -619,7 +610,6 @@ async def _get_client(self) -> AsyncIterator[Any]:
619610 # Use the injected client (caller manages lifecycle)
620611 yield self ._custom_client
621612 else :
622- # Create a new client from resolved args (static client_args or freshly-minted Bedrock creds).
623613 # We initialize an OpenAI context on every request so as to avoid connection sharing in the underlying
624614 # httpx client. The asyncio event loop does not allow connections to be shared. For more details, please
625615 # refer to https://github.com/encode/httpx/discussions/2959.
0 commit comments