| 131 | |
| 132 | |
| 133 | class AnthropicBedrock(BaseBedrockClient[httpx.Client, Stream[Any]], SyncAPIClient): |
| 134 | messages: Messages |
| 135 | completions: Completions |
| 136 | beta: Beta |
| 137 | |
| 138 | def __init__( |
| 139 | self, |
| 140 | aws_secret_key: str | None = None, |
| 141 | aws_access_key: str | None = None, |
| 142 | aws_region: str | None = None, |
| 143 | aws_profile: str | None = None, |
| 144 | aws_session_token: str | None = None, |
| 145 | api_key: str | None = None, |
| 146 | base_url: str | httpx.URL | None = None, |
| 147 | timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, |
| 148 | max_retries: int = DEFAULT_MAX_RETRIES, |
| 149 | default_headers: Mapping[str, str] | None = None, |
| 150 | default_query: Mapping[str, object] | None = None, |
| 151 | # Configure a custom httpx client. See the [httpx documentation](https://www.python-httpx.org/api/#client) for more details. |
| 152 | http_client: httpx.Client | None = None, |
| 153 | middleware: Sequence[MiddlewareInput] | None = None, |
| 154 | # Enable or disable schema validation for data returned by the API. |
| 155 | # When enabled an error APIResponseValidationError is raised |
| 156 | # if the API responds with invalid data for the expected schema. |
| 157 | # |
| 158 | # This parameter may be removed or changed in the future. |
| 159 | # If you rely on this feature, please open a GitHub issue |
| 160 | # outlining your use-case to help us decide if it should be |
| 161 | # part of our public interface in the future. |
| 162 | _strict_response_validation: bool = False, |
| 163 | ) -> None: |
| 164 | if api_key is None: |
| 165 | api_key = os.environ.get("AWS_BEARER_TOKEN_BEDROCK") |
| 166 | |
| 167 | has_aws_credentials = ( |
| 168 | aws_access_key is not None |
| 169 | or aws_secret_key is not None |
| 170 | or aws_session_token is not None |
| 171 | or aws_profile is not None |
| 172 | ) |
| 173 | if api_key is not None and has_aws_credentials: |
| 174 | raise ValueError( |
| 175 | "Cannot specify both `api_key` and AWS credentials (`aws_access_key`, `aws_secret_key`, `aws_session_token`, `aws_profile`)" |
| 176 | ) |
| 177 | |
| 178 | self.api_key: str | None = api_key |
| 179 | |
| 180 | self.aws_secret_key = aws_secret_key |
| 181 | |
| 182 | self.aws_access_key = aws_access_key |
| 183 | |
| 184 | self.aws_region = _infer_region() if aws_region is None else aws_region |
| 185 | self.aws_profile = aws_profile |
| 186 | |
| 187 | self.aws_session_token = aws_session_token |
| 188 | |
| 189 | if base_url is None: |
| 190 | base_url = os.environ.get("ANTHROPIC_BEDROCK_BASE_URL") |
no outgoing calls