ModelRefs / Anthropic Python SDK — AI Glossary

Anthropic Python SDK — AI Glossary

The official Python client library for the Anthropic API, providing typed message creation, streaming, and tool use helpers.

Overview

anthropic-python provides: client.messages.create() (sync/async), streaming via with client.messages.stream(), ToolUseBlock parsing helpers, prompt caching parameters (cache_control), and computer use content block types. Similar design to openai-python; migrating between them requires adapting the messages format and role structure.

Reference details

Topicecosystem
Also known asanthropic Python library
Last reviewed2026-06-24

How it works

  1. A client is constructed with credentials and calls the Messages endpoint, which takes an ordered list of user and assistant turns.
  2. The system prompt is a top-level parameter rather than the first message in the list, which is the structural difference that breaks naive ports from other clients.
  3. Streaming yields typed events — content-block deltas rather than raw chunks — so partial tool-call arguments arrive as they are generated.
  4. Tool use returns structured blocks the caller executes and returns as tool-result content in the next user turn, so the loop is explicit in application code.
  5. Cache control is set per content block, marking a prefix as cacheable so a long reused preamble is not reprocessed on every call.

Example: Why prompt caching is a per-block decision

A request carries a 20,000-token document and a 200-token question. Uncached, every follow-up question reprocesses all 20,200 tokens. Marking the document block cacheable means subsequent calls reprocess roughly the 200-token question, about 1% of the input, with the cached prefix billed at a reduced rate. Ten follow-up questions go from 202,000 tokens of input processing to roughly 20,000 plus 10 x 200 = 22,000. The gain comes from the block boundary being where the reusable part ends.

Commonly confused with

The counterpart to the OpenAI client, and not interchangeable with it. The Messages API differs structurally — the system prompt is a top-level field rather than the first message — so porting code between the two is a real change, not a base-URL swap. Gateways translate between them; hand-rolled ports frequently drop the system prompt silently.

When to use it

Reach for it when:

  • Calling Claude models directly from Python with streaming, tool use or caching.
  • Porting code from another provider's client, where the system-prompt and tool-result differences must be handled deliberately.
  • Long shared prefixes make per-block cache control worth configuring.

Reach for something else when:

  • A multi-provider abstraction is wanted, where a gateway or framework normalises the differences.
  • Deploying through a cloud's managed surface, which has its own client and auth.

Continue your research

Use these connected ModelRefs sections to compare alternatives, inspect implementation paths, and review the evidence and governance boundaries relevant to Anthropic Python SDK — AI Glossary.

Frequently asked questions

What is Anthropic Python SDK?

The official Python client library for the Anthropic API, providing typed message creation, streaming, and tool use helpers.

Is Anthropic Python SDK the same as anthropic Python library?

Yes — anthropic Python library are common aliases for Anthropic Python SDK.

What concepts are related to Anthropic Python SDK?

Closely related concepts include openai sdk, sdk, anthropic api.