Getting Started with the Claude SDK (Python & TypeScript)

Intro to Claude's official client SDKs: supported languages, installation (pip install anthropic / npm install @anthropic-ai/sdk), first-call examples in Python and TypeScript, streaming and token usage, and client SDK vs Agent SDK — based on official docs.

When calling the Claude API from code, instead of hand-writing raw HTTP requests you can use the official SDKs, which handle authentication, retries, streaming, and typing for you. This guide walks through installing Claude's official client SDK and making your first call. (As of June 2026. Versions and models may change, so check the official docs for the latest.)

Four steps with the SDK 1 Install pip / npm install 2 Create client API key (env var) 3 Create message messages.create 4 Get response content + usage The SDK handles auth, retries, streaming, and types — no raw HTTP needed

What an SDK is and why use one

The Claude API is a REST API at https://api.anthropic.com. Calling it directly means handling headers, auth, JSON bodies, and error handling yourself. An SDK (Software Development Kit) is an official library that wraps this per language; Anthropic states each SDK provides idiomatic interfaces, type safety, and built-in support for streaming, retries, and error handling.

Note: the "client SDK" here is for calling the Claude API. The Agent SDK (claude-agent-sdk) that powers Claude Code has a similar name but is a separate product (distinguished at the end).

Officially supported languages

Anthropic provides official client SDKs for Python, TypeScript, Java, Go, Ruby, C#, PHP, and the command line (CLI). Platform support varies by language, so check each language's docs for specifics.

Official SDK languages Python · pip install anthropic Python 3.9 or later TypeScript · npm i @anthropic-ai/sdk Node.js 20 LTS or later Other official SDKs Java Go Ruby C# PHP CLI

Installation

For the two most common languages:

  • Python: pip install anthropic — requires Python 3.9 or later.
  • TypeScript / JavaScript: npm install @anthropic-ai/sdk — supports Node.js 20 LTS or later and TypeScript 4.9 or later.

Keep your API key out of source code and in an environment variable (ANTHROPIC_API_KEY). The official docs recommend using python-dotenv to place the key in a .env file so it isn't committed to source control.

First call — Python

Create a client, send a message with messages.create, and the model's reply arrives in the response's content.

import os
from anthropic import Anthropic

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

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

First call — TypeScript

The TypeScript SDK includes type definitions for all request params and response fields. Usage is nearly identical to Python.

import Anthropic from "@anthropic-ai/sdk";

const client = new Anthropic({
  apiKey: process.env["ANTHROPIC_API_KEY"],
});

const message = await client.messages.create({
  model: "claude-opus-4-8",
  max_tokens: 1024,
  messages: [{ role: "user", content: "Hello, Claude" }],
});
console.log(message.content);

The model string claude-opus-4-8 above follows the official docs example. The list of available models can change, so check the models overview.

Commonly used features

  • Token usage: the response's usage property shows input and output token counts (e.g. { input_tokens, output_tokens }). Since billing is per token, this is handy for cost tracking.
  • Streaming: the SDK supports streaming responses via Server-Sent Events (SSE), so you can receive long answers token by token.
  • Built-in retries and error handling: retries for transient errors and typed error handling are built into the SDK, reducing what you implement yourself.
  • Beta features: access beta features via the beta namespace in any SDK.

Client SDK vs Agent SDK

Two similarly named things worth separating:

  • Client SDK (this article's topic, anthropic / @anthropic-ai/sdk): a thin wrapper for calling the Claude API. It exposes API features like message creation, streaming, and token usage directly.
  • Agent SDK (claude-agent-sdk / @anthropic-ai/claude-agent-sdk): provides the agent loop, tools, and context management that power Claude Code, as a programmable library. It supports built-in tools like file read/edit, bash execution, and web search, plus custom tools and MCP connections. (Formerly: Claude Code SDK)

For a simple "send a prompt, get a reply" integration, the client SDK is enough; to build an "agent that reads files and runs commands on its own," the Agent SDK is the fit.

Summary

Remember: (1) the SDK is an official library that handles raw HTTP for you; (2) install with Python pip install anthropic (3.9+) or TypeScript npm install @anthropic-ai/sdk (Node 20+); (3) create a client and call messages.create to get a reply in content; (4) the client SDK and Agent SDK are separate. For deeper usage, see the official Claude SDK docs.

Related: see also tool use and API cost optimization (prompt caching, Batch).

This article is an introductory explanation based on Anthropic's official documentation. SDK versions, required runtimes, and the model list may be updated, so verify the latest spec in the official docs before implementing. (Official source: docs.claude.com)

Keep reading

Have a question or want to share how you use Claude?

Join the community to share tips with other users, or explore more guides.