Compatibility client for Amazon Bedrock's OpenAI-compatible endpoint.
| 383 | |
| 384 | |
| 385 | class BedrockOpenAI(OpenAI): |
| 386 | """Compatibility client for Amazon Bedrock's OpenAI-compatible endpoint.""" |
| 387 | |
| 388 | _bedrock_provider: _Provider |
| 389 | _bedrock_state: _LegacyBedrockState |
| 390 | _bedrock_token_provider: BedrockTokenProvider | None |
| 391 | _uses_region_derived_base_url: bool |
| 392 | _bedrock_runtime_signature: _LegacyRuntimeSignature |
| 393 | aws_region: str | None |
| 394 | |
| 395 | def __init__( |
| 396 | self, |
| 397 | *, |
| 398 | api_key: str | None = None, |
| 399 | bedrock_token_provider: BedrockTokenProvider | None = None, |
| 400 | aws_region: str | None = None, |
| 401 | aws_profile: str | None = None, |
| 402 | aws_access_key_id: str | None = None, |
| 403 | aws_secret_access_key: str | None = None, |
| 404 | aws_session_token: str | None = None, |
| 405 | aws_credentials_provider: AwsCredentialsProvider | None = None, |
| 406 | organization: str | None = None, |
| 407 | project: str | None = None, |
| 408 | webhook_secret: str | None = None, |
| 409 | base_url: str | httpx.URL | None = None, |
| 410 | websocket_base_url: str | httpx.URL | None = None, |
| 411 | timeout: float | Timeout | None | NotGiven = NOT_GIVEN, |
| 412 | max_retries: int = DEFAULT_MAX_RETRIES, |
| 413 | default_headers: Mapping[str, str] | None = None, |
| 414 | default_query: Mapping[str, object] | None = None, |
| 415 | http_client: httpx.Client | None = None, |
| 416 | _strict_response_validation: bool = False, |
| 417 | _enforce_credentials: bool = True, |
| 418 | _provider: _Provider | None = None, |
| 419 | _state: _LegacyBedrockState | None = None, |
| 420 | _region_was_explicit: bool | None = None, |
| 421 | ) -> None: |
| 422 | if _provider is None or _state is None: |
| 423 | _provider, _state, public_api_key = _legacy_provider( |
| 424 | api_key=api_key, |
| 425 | token_provider=bedrock_token_provider, |
| 426 | aws_region=aws_region, |
| 427 | aws_profile=aws_profile, |
| 428 | aws_access_key_id=aws_access_key_id, |
| 429 | aws_secret_access_key=aws_secret_access_key, |
| 430 | aws_session_token=aws_session_token, |
| 431 | aws_credentials_provider=aws_credentials_provider, |
| 432 | base_url=base_url, |
| 433 | region_was_explicit=_region_was_explicit, |
| 434 | ) |
| 435 | else: |
| 436 | public_api_key = ( |
| 437 | _state.explicit_api_key |
| 438 | or (_state.environment_bearer_token if _state.uses_environment_bearer else "") |
| 439 | or "" |
| 440 | ) |
| 441 | |
| 442 | super().__init__( |
no outgoing calls