AnthropicBedrock and AnthropicVertex are cloud-specific clients that adapt the SDK to AWS Bedrock and Google Vertex AI respectively, rewriting requests, managing cloud-native auth schemes (SigV4, OAuth), and omitting or unsupporting features unavailable on those platforms. Both clients override request preparation to default the anthropic_version header, translate authentication into request bodies, select base URLs by region, and apply cloud-specific error mappings and wire formats. The AnthropicBetaParam enum in src/anthropic/types/anthropic_beta_param.py defines the set of recognized anthropic-beta header values used across the SDK's beta parameter types. Beta parameter type files beta_cloud_config_params.py, beta_limited_network_params.py, and beta_packages_params.py each declare the corresponding anthropic-beta header values required for cloud execution, sandboxed network access, and package installation respectively.
AnthropicBedrock (in src/anthropic/lib/bedrock/_client.py) exposes messages, completions, and beta as top-level resource attributes, consistent with the main Anthropic client surface.[1] Every POST request body sent by AnthropicBedrock has its anthropic_version field defaulted to "bedrock-2023-05-31" via _prepare_options.[1] _prepare_options rewrites the request URL for /v1/messages and /v1/complete POST calls: streaming requests become /model/{model}/invoke-with-response-stream and non-streaming requests become /model/{model}/invoke, after URL-encoding the model name.[1] The anthropic-beta header value is propagated into the anthropic_beta JSON field as a comma-split list by _prepare_options, so beta feature flags survive the header-to-body translation for Bedrock.[1] _prepare_options raises AnthropicError("The Batch API is not supported in Bedrock yet") for any URL starting with /v1/messages/batches.[1] _prepare_options raises AnthropicError("Token counting is not supported in Bedrock yet") for /v1/messages/count_tokens requests.[1]
AnthropicBedrock supports two mutually exclusive authentication modes: a bearer token via api_key (or the AWS_BEARER_TOKEN_BEDROCK env var) and AWS SigV4 credentials (aws_access_key, aws_secret_key, aws_session_token, aws_profile); specifying both raises ValueError.[1] When api_key is set, _prepare_request authenticates by writing Authorization: Bearer {api_key} and skips AWS SigV4 signing entirely.[1] _infer_region() resolves the AWS region in priority order: the AWS_REGION env var, then the boto3 session region, then falls back to "us-east-1" with a warning.[1] The base URL is taken from the ANTHROPIC_BEDROCK_BASE_URL env var when set; otherwise it defaults to https://bedrock-runtime.{aws_region}.amazonaws.com.[1] Because Bedrock uses the AWS event-stream wire format, AnthropicBedrock overrides the default SSE decoder with AWSEventStreamDecoder.[1] SigV4 (AWS Signature Version 4) is a request-signing protocol that authenticates API calls by cryptographically signing request headers with AWS credentials; AWS Bedrock rejects requests that lack a valid SigV4 signature. The SigV4 signing path in src/anthropic/lib/bedrock/_auth.py, src/anthropic/lib/aws/_auth.py, and src/anthropic/lib/bedrock/_mantle.py operates on raw request body bytes throughout, so binary request bodies such as multipart file uploads authenticate correctly with AWS Bedrock without signature mismatches. In src/anthropic/lib/aws/_client.py, base URL derivation from aws_region is applied correctly when the client is reconfigured via .with_options(aws_region=...) or when skip_auth=True bypasses the SigV4 credential flow.
AnthropicBedrock.copy() creates a new client instance re-using the current client's settings with optional overrides; with_options is an alias for copy intended for fluent inline usage.[1]
AnthropicVertex (in src/anthropic/lib/vertex/_client.py) exposes messages and beta as top-level resource attributes, but does NOT expose completions, unlike AnthropicBedrock.[2] Every request body sent by AnthropicVertex has its anthropic_version defaulted to "vertex-2023-10-16" (the DEFAULT_VERSION constant).[2] A region argument or the CLOUD_ML_REGION environment variable is required; omitting both causes AnthropicVertex.__init__ to raise ValueError.[2] The base URL is taken from ANTHROPIC_VERTEX_BASE_URL when set; otherwise it is selected by region: "global" → https://aiplatform.googleapis.com/v1, "us" → https://aiplatform.us.rep.googleapis.com/v1, "eu" → https://aiplatform.eu.rep.googleapis.com/v1, and any other region → https://{region}-aiplatform.googleapis.com/v1.[2]
AnthropicVertex._ensure_access_token resolves auth in order: an explicit access_token argument → a Google credentials object (loaded via load_auth if not already set) → raises RuntimeError if no token can be resolved.[2] project_id is resolved from the ANTHROPIC_VERTEX_PROJECT_ID environment variable when not passed explicitly.[2] _prepare_request skips auth injection if an Authorization header is already present; otherwise it writes Authorization: Bearer {access_token}, allowing callers to override auth manually.[2] BaseVertexClient maps HTTP 504 to DeadlineExceededError, a Vertex-specific error not present in the Bedrock client's status-error mapping.[2]
AnthropicVertex.with_middleware returns a new client with the given middleware appended after the existing middleware, enabling per-request middleware injection inline — see Middleware system for middleware semantics.[2] AnthropicVertex.with_options is an alias for copy, designed for fluent inline usage such as client.with_options(timeout=10).messages.create(...).[2]
Sources