Enterprise Deployment Basics
9 examples to get you started with Enterprise Deployment - 6 basic and 3 intermediate.
Prerequisites
- Install the SDK with the extras for the platforms you plan to use:
pip install anthropicfor the direct API,pip install "anthropic[bedrock]"for Amazon Bedrock,pip install "anthropic[vertex]"for Google Cloud Vertex AI. - For Bedrock, an AWS account with IAM credentials configured (via environment variables, a shared credentials file, or an assumed role) and model access requested in the Bedrock console.
- For Vertex AI, a Google Cloud project with billing enabled, the Vertex AI API turned on, and Application Default Credentials set up via
gcloud auth application-default login. - These examples assume
claude-sonnet-5is available on every platform you provision; confirm model access before running them.
Basic Examples
1. Call Claude via the Direct API
The simplest possible path: an API key and the official SDK, no cloud account required.
import anthropic
client = anthropic.Anthropic() # reads ANTHROPIC_API_KEY from the environment
response = client.messages.create(
model="claude-sonnet-5",
max_tokens=256,
messages=[{"role": "user", "content": "List three benefits of infrastructure as code."}],
)
print(response.content[0].text)anthropic.Anthropic()with no arguments readsANTHROPIC_API_KEYfrom the environment automatically.- There is no IAM role, service account, or region to configure - this is the fastest way to confirm your integration code works before adding a cloud platform layer.
- Every other example on this page targets the same
messages.createcall shape, just through a different client class.
Related: Choosing Between Direct API, Bedrock, and Vertex AI for Claude - the decision this page assumes you've already made.
2. Construct the Bedrock Client
Point the SDK at Amazon Bedrock instead of Anthropic's own endpoint, using AWS credentials instead of an API key.
from anthropic import AnthropicBedrock
client = AnthropicBedrock(
aws_region="us-east-1",
)AnthropicBedrockresolves AWS credentials the same way any AWS SDK does: environment variables, a shared credentials file, or an assumed IAM role.aws_regionis required - Bedrock has no default region fallback, and the model you requested access to must be available in that region.- No API key is passed here at all; authentication is entirely IAM-based.
3. Call Claude on Amazon Bedrock
Once the client is constructed, the request shape is identical to the direct API, aside from the model ID prefix.
from anthropic import AnthropicBedrock
client = AnthropicBedrock(aws_region="us-east-1")
response = client.messages.create(
model="anthropic.claude-sonnet-5",
max_tokens=256,
messages=[{"role": "user", "content": "List three benefits of infrastructure as code."}],
)
print(response.content[0].text)- Bedrock model IDs carry an
anthropic.prefix - passing the bareclaude-sonnet-5ID from the direct API here returns a 404. - A
403at this point almost always means the IAM role lacks the Bedrock invoke permission, or model access was never requested in the console for this model in this region. messages.createis the same method with the same parameters as the direct-API client - only the client class and model ID string differ.
4. Construct the Vertex AI Client
Point the SDK at Google Cloud Vertex AI, authenticating with a GCP project and Application Default Credentials instead of an API key.
from anthropic import AnthropicVertex
client = AnthropicVertex(
project_id="my-gcp-project",
region="us-east5",
)project_idandregionare both required constructor arguments - there is no default project or region.- Authentication uses Google's Application Default Credentials, resolved from
gcloud auth application-default loginlocally or a service account attached to the runtime in production. regioncan be a specific region, a multi-region value, or"global"depending on the model and latency needs.
5. Call Claude on Google Cloud Vertex AI
Vertex AI model IDs for current-generation Claude models are unprefixed, unlike Bedrock's anthropic. prefix.
from anthropic import AnthropicVertex
client = AnthropicVertex(project_id="my-gcp-project", region="us-east5")
response = client.messages.create(
model="claude-sonnet-5",
max_tokens=256,
messages=[{"role": "user", "content": "List three benefits of infrastructure as code."}],
)
print(response.content[0].text)- Current-generation Vertex AI model IDs match the direct API's bare model string - no provider prefix, unlike Bedrock.
- A
403here usually means the service account is missing the Vertex AI User IAM role, or the project has not enabled the Vertex AI API. - A
429or quota error means the project's request or token quota for this model needs to be raised in the Google Cloud console.
Related: Running Claude on Google Cloud Vertex AI: Quotas and Service Accounts - the full service account and quota setup.
6. Handle Platform-Specific Authentication Errors
Wrap the call so a misconfigured IAM role or service account produces a clear message instead of a raw stack trace.
import anthropic
from anthropic import AnthropicBedrock
client = AnthropicBedrock(aws_region="us-east-1")
try:
response = client.messages.create(
model="anthropic.claude-sonnet-5",
max_tokens=256,
messages=[{"role": "user", "content": "Ping."}],
)
print(response.content[0].text)
except anthropic.PermissionDeniedError:
print("IAM role lacks Bedrock invoke permission, or model access was not requested.")
except anthropic.NotFoundError:
print("Model ID or region is wrong - check the anthropic. prefix and region availability.")PermissionDeniedErrorandNotFoundErrorare the same typed exception classes across every client - direct API, Bedrock, and Vertex AI all raise them the same way.- Catching the specific exception class, rather than a bare
except Exception, lets you show a platform-appropriate remediation message instead of a generic failure. - The most common first-run failure on either cloud platform is a permissions or access-request problem, not a code bug - check IAM and model access before debugging the request itself.
Intermediate Examples
7. Request a Cross-Region Inference Profile on Bedrock
Some Bedrock models require an inference profile ID instead of a plain model ID for capacity or latency reasons.
from anthropic import AnthropicBedrock
client = AnthropicBedrock(aws_region="us-east-1")
response = client.messages.create(
model="us.anthropic.claude-sonnet-5", # cross-region inference profile ID
max_tokens=256,
messages=[{"role": "user", "content": "Summarize this quarter's cloud spend trend."}],
)
print(response.content[0].text)- A cross-region inference profile ID (prefixed with a geography code like
us.) routes a single logical request across multiple AWS regions for capacity headroom. - Not every model requires one - check the Bedrock console for whether the model you requested access to needs a profile ID or accepts a plain single-region model ID.
- Provisioning the underlying model access and requesting an inference profile are separate steps; both must be done before this call succeeds.
8. Choose a Regional Endpoint for Vertex AI
Vertex AI lets you pin inference to a specific region, a multi-region value, or route globally for best availability.
from anthropic import AnthropicVertex
# Pin to a specific region for data residency or latency reasons.
regional_client = AnthropicVertex(project_id="my-gcp-project", region="europe-west1")
# Or use "global" for Anthropic to route to the best available region.
global_client = AnthropicVertex(project_id="my-gcp-project", region="global")- A specific region (like
europe-west1) is the right choice when data residency or latency requirements pin where inference must run. region="global"is recommended by default when you have no residency constraint, since it gives Anthropic room to route around regional capacity limits.- Quota is tracked per project and per region, so switching regions later may require a separate quota increase request.
Related: Data Residency and Region-Pinning Checklist for Regulated Workloads - when a specific region is a compliance requirement, not just a preference.
9. Select a Platform Client by Environment Variable
A minimal wrapper that picks the right client class at startup, so application code never has to know which platform is live in a given environment.
import os
import anthropic
from anthropic import AnthropicBedrock, AnthropicVertex
def get_client() -> anthropic.Anthropic:
platform = os.environ.get("CLAUDE_PLATFORM", "direct")
if platform == "bedrock":
return AnthropicBedrock(aws_region=os.environ["AWS_REGION"])
if platform == "vertex":
return AnthropicVertex(
project_id=os.environ["GCP_PROJECT_ID"],
region=os.environ.get("GCP_REGION", "global"),
)
return anthropic.Anthropic()
client = get_client()
response = client.messages.create(
model="claude-sonnet-5",
max_tokens=256,
messages=[{"role": "user", "content": "What changed between staging and prod?"}],
)
print(response.content[0].text)- Every client class exposes the same
messages.createinterface, so switching platforms is a matter of swapping which clientget_client()returns. CLAUDE_PLATFORMas an environment variable lets you run the same code against the direct API in local development and against Bedrock or Vertex AI in a deployed environment without a code change.- This pattern is a lightweight stepping stone toward a full self-hosted gateway - it centralizes the platform choice, but does not yet add caching, failover, or centralized rate limiting.
Related: Building a Self-Hosted Gateway for Routing, Caching, and Fallback - the next step once a simple environment switch isn't enough.
Stack versions: Written against the Claude model lineup current as of ~June 2026 - Claude Fable 5, Claude Opus 4.8, Claude Sonnet 5 (the default), and Claude Haiku 4.5 - and the official
anthropicPython SDK (latest 0.x release). Model names, pricing, and SDK versions move quickly - verify current specifics at platform.claude.com/docs before relying on them.