SDKs & Developer Experience

Python SDK Quickstart: Install, Configure, and First Call

Python is the shortest path from "we should evaluate Claude" to a working response on your screen. Here is the whole journey, in order.

Claude 3P 101 · Updated July 2026 · Unofficial guide

The official Python SDK is the package called anthropic on PyPI, maintained by Anthropic. It wraps the Claude Messages API — the HTTP interface every Claude request ultimately goes through — in a typed client, so your team writes ordinary Python instead of hand-rolled HTTP calls. This article gets you from an empty virtual environment to a first response, and shows where the third-party platforms fit in.

Step 1: Install the package

The SDK requires Python 3.9 or newer. Install it the usual way:

pip install anthropic

That base install talks to Anthropic's first-party Claude API. If you plan to reach Claude through a cloud platform instead, the same package carries optional extras — pip install -U "anthropic[bedrock]" for Amazon Bedrock and pip install -U "anthropic[vertex]" for Google Vertex AI — which pull in the cloud-specific authentication dependencies. More on those below.

Step 2: Configure authentication

For the first-party API, authentication is an API key: a long-lived secret starting with sk-ant-api..., created in the Claude Console under Settings → API keys. Workspaces let you scope keys by project or environment, which is worth doing from day one so you can tell dev traffic from production traffic later.

The simplest safe pattern is an environment variable. Set ANTHROPIC_API_KEY and the SDK picks it up automatically — a no-argument Anthropic() constructor reads it from the environment, so the key never appears in your code. API keys have no expiry, so treat them like any other production secret: store them in a secrets manager, rotate periodically, and revoke immediately on a suspected leak. For production workloads on cloud platforms, CI/CD, or Kubernetes, Anthropic recommends Workload Identity Federation (short-lived tokens exchanged from your identity provider) instead of long-lived keys; API keys are the right fit for local development, prototyping, and scripts.

Step 3: Make your first call

import os
from anthropic import Anthropic

client = Anthropic(api_key=os.environ.get("ANTHROPIC_API_KEY"))

message = client.messages.create(
    model="claude-sonnet-5",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Hello, Claude"}],
)
print(message.content)

Three parameters do the work. model selects which Claude model answers — claude-sonnet-5 is the balanced workhorse; claude-opus-4-8 is the recommended starting point for complex enterprise and agentic work. max_tokens caps how long the reply can be (a token is roughly a short word — the unit you are billed in). messages is the conversation so far, as a list of role/content pairs. The response object carries the model's reply plus usage metadata you will want to log.

Rule of thumb: if the call fails immediately, it is almost always authentication. Check that ANTHROPIC_API_KEY is set in the environment your process actually runs in — and beware that a set-but-empty variable still counts as "set" and will be used as an (invalid) key.

The same package, four more doors

What makes the Python SDK notable for 3P readers: one package covers every deployment surface. Each platform gets its own client class with platform-appropriate authentication, and the client.messages.create(...) call shape stays the same.

PlatformClient classAuth
Claude API (1P)Anthropic()ANTHROPIC_API_KEY
Claude Platform on AWSAnthropicAWS()AWS SigV4 + workspace ID
Amazon BedrockAnthropicBedrockMantle(aws_region="us-east-1")Standard AWS credentials
Google Vertex AIAnthropicVertex(project_id="...", region="global")Application Default Credentials
Microsoft FoundryAnthropicFoundry(api_key="...", resource="...")Foundry resource + API key

This is the practical payoff of the SDK approach: your application code is written once against the Messages API, and switching platforms is mostly a matter of swapping the client constructor and the model ID format. The dedicated setup guides cover each: Bedrock, Vertex AI, Foundry, and Claude Platform on AWS.

Where to go next

Once the first call works, read the environment-variable reference and API key authentication in depth, then streaming basics for anything user-facing. The homepage quickstart has the platform-by-platform version of this article.

Sources