Claude API Tutorial: Get a Key and Make Your First Call

A beginner Claude API tutorial: create a Console account and API key, send your first Messages request in Python and TypeScript, then add streaming and tools.

Josh Pocock7 min read

Claude API cover

AI Coding

Claude API

Stride AI Academy

The Claude API lets your own code send messages to Claude and get replies back, billed per token. To use it, you create a Claude Console account, make an API key, and send a POST request to https://api.anthropic.com/v1/messages, either directly or through Anthropic's Python or TypeScript SDK. Your first working call takes a few minutes.

This tutorial walks through getting a key, making a first request with cURL, Python and TypeScript, reading the response, then adding streaming and tool use. Everything here was checked against Anthropic's quickstart, models overview, streaming, tool use and pricing docs on November 22, 2026.

What you need before you start

  • A Claude Console account. Sign up at platform.claude.com. This is separate from a Claude Pro or Max subscription, and API usage is billed on its own.
  • Python or Node.js if you want to use an SDK. The quickstart examples use Python 3 with a virtual environment, and Node with npm.
  • A few dollars of budget, or none. The pricing docs say new users get free credits to test the API.

Step 1: Create an API key

  1. Sign in to the Claude Console.
  2. Open the API keys page and create a key.
  3. Copy it somewhere safe. Treat it like a password.

The SDKs read your key from the ANTHROPIC_API_KEY environment variable, so you never paste it into your code. On macOS, Linux or WSL:

Terminal
export ANTHROPIC_API_KEY="your-api-key-here"

In PowerShell on Windows:

PowerShell
$env:ANTHROPIC_API_KEY = "your-api-key-here"

Replace your-api-key-here with your own key, and never commit it to Git or share it in a screenshot.

The quickstart also offers a second way to sign in for local development: Anthropic's ant command-line tool, which you log in with ant auth login. The SDKs and CLI then pick up your credentials automatically. This tutorial uses the API key route.

Step 2: Make your first request with cURL

Every Claude API call is a POST to the Messages endpoint with three headers: your key, the API version and the content type.

Terminal
curl https://api.anthropic.com/v1/messages \
  -H "content-type: application/json" \
  -H "x-api-key: $ANTHROPIC_API_KEY" \
  -H "anthropic-version: 2026-10-21" \
  -d '{
    "model": "claude-opus-5-5",
    "max_tokens": 1000,
    "messages": [
      {
        "role": "user",
        "content": "Give me three names for a dog-walking business."
      }
    ]
  }'

The body needs three fields:

  • model: which Claude model to use. claude-opus-5-5 is what the docs suggest for most work.
  • max_tokens: the most tokens Claude may write in its reply.
  • messages: the conversation so far, as a list of user and assistant turns.

Step 3: Call the Claude API from Python

Create a project, a virtual environment and install the SDK:

Terminal
mkdir claude-quickstart && cd claude-quickstart
python3 -m venv .venv && source .venv/bin/activate
pip install anthropic

Create quickstart.py:

python
import anthropic

client = anthropic.Anthropic()

message = client.messages.create(
    model="claude-opus-5-5",
    max_tokens=1000,
    messages=[
        {
            "role": "user",
            "content": "Give me three names for a dog-walking business.",
        }
    ],
)

for block in message.content:
    if block.type == "text":
        print(block.text)

Run it:

Terminal
python quickstart.py

anthropic.Anthropic() reads ANTHROPIC_API_KEY from your environment, which is why the key isn't in the file.

Step 4: Call the Claude API from TypeScript

Create a project and install the SDK:

Terminal
mkdir claude-quickstart && cd claude-quickstart
npm init -y
npm pkg set type=module
npm install @anthropic-ai/sdk

Create quickstart.ts:

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

const client = new Anthropic();

const message = await client.messages.create({
  model: "claude-opus-5-5",
  max_tokens: 1000,
  messages: [
    {
      role: "user",
      content: "Give me three names for a dog-walking business."
    }
  ]
});

for (const block of message.content) {
  if (block.type === "text") {
    console.log(block.text);
  }
}

Run it:

Terminal
npx tsx quickstart.ts

The quickstart also has examples for C#, Go, Java, PHP and Ruby.

Step 5: Read the response

The API returns JSON shaped like this (from the quickstart, shortened):

JSON
{
  "model": "claude-opus-5-5",
  "type": "message",
  "role": "assistant",
  "content": [
    { "type": "text", "text": "..." }
  ],
  "stop_reason": "end_turn",
  "usage": {
    "input_tokens": 21,
    "output_tokens": 305
  }
}

Three fields matter most:

  • content is a list of blocks. Text replies come as text blocks, which is why the code loops over them.
  • stop_reason tells you why Claude stopped. end_turn means it finished. tool_use means it wants to call a tool.
  • usage shows the tokens you'll be billed for.

To hold a conversation, append Claude's reply as an assistant turn and your next message as a user turn, then send the whole list again. The Messages API guide covers multi-turn chats and system prompts.

Which Claude model to use

From the models overview on November 22, 2026:

Model Model ID Best for
Claude Fable 5.2 claude-fable-5-2 Demanding reasoning and long-horizon agent work
Claude Opus 5.5 claude-opus-5-5 Long-running agentic coding and knowledge work
Claude Sonnet 5.5 claude-sonnet-5-5 Speed and intelligence together
Claude Haiku 5.5 claude-haiku-5-5 High-volume tasks like classification and routing

All four have a 1M-token context window and up to 128K output tokens. If you're unsure, the docs say start with Opus 5.5. Swap the model string to switch. Our Claude API pricing guide shows what each one costs per token, with worked examples.

Stream responses as they're written

For chat apps, you usually want text to appear as Claude writes it. On the raw API you set "stream": true, and the SDKs give you helpers. In Python:

python
import anthropic

client = anthropic.Anthropic()

with client.messages.stream(
    max_tokens=1024,
    messages=[{"role": "user", "content": "Hello"}],
    model="claude-opus-5-5",
) as stream:
    for text in stream.text_stream:
        print(text, end="", flush=True)

In TypeScript:

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

const client = new Anthropic();

await client.messages
  .stream({
    messages: [{ role: "user", content: "Hello" }],
    model: "claude-opus-5-5",
    max_tokens: 1024
  })
  .on("text", (text) => {
    console.log(text);
  });

Give Claude tools

Tool use lets Claude call functions. There are two kinds, per the tool use docs:

  • Client tools run in your code. You define a name, description and input_schema. Claude replies with stop_reason: "tool_use" and a tool_use block, your code runs the function, and you send back a tool_result.
  • Server tools run on Anthropic's side, such as web search, web fetch and code execution. You get results without writing a handler.

A client tool definition in Python:

python
import anthropic

client = anthropic.Anthropic()

tools = [
    {
        "name": "get_weather",
        "description": "Get the current weather for a given location.",
        "input_schema": {
            "type": "object",
            "properties": {
                "location": {
                    "type": "string",
                    "description": "City and state, e.g. San Francisco, CA",
                }
            },
            "required": ["location"],
        },
    }
]

response = client.messages.create(
    model="claude-opus-5-5",
    max_tokens=1024,
    tools=tools,
    messages=[{"role": "user", "content": "What's the weather in San Francisco?"}],
)

if response.stop_reason == "tool_use":
    tool_use = next(b for b in response.content if b.type == "tool_use")
    print(tool_use.name, tool_use.input)

Next, you'd run your weather lookup and send the answer back in a tool_result block with the matching tool_use_id. The docs show that full round trip, and the SDK's tool runner can handle the loop for you. Tool definitions add input tokens, so they show up in usage.

Costs and limits to know

  • You pay per token. On November 22, 2026, Opus 5.5 is $4 per million input tokens and $20 per million output tokens. Set a sensible max_tokens while you're testing.
  • Rate limits cap requests and tokens per minute and rise with your usage tier. See Claude API rate limits for the tiers and the 429 error.
  • Subscription credits are separate. Max, Ultra and Team include monthly API credits you can link to a Console organization; the Claude credits guide explains how.

Where to go next

Once single calls work, most builders move to agents. The Claude Agent SDK tutorial shows how to build an agent that uses tools in a loop, and how to build an MCP server covers giving Claude your own tools in a reusable way.

Learn to build with Claude Code

The Stride AI Coding course teaches Claude Code and Codex for building client tools, written for non-programmers, with weekly live calls to review your builds. Many of the free guides cover Claude Code setups, and the Claude Code community is where members compare theirs.

FAQ

How do I get a Claude API key?

Sign up for a Claude Console account at platform.claude.com, open the API keys page under Settings and create a key. Store it in the ANTHROPIC_API_KEY environment variable rather than in your code.

Is the Claude API free?

Not ongoing. New users get free credits to test the API, then usage is billed per token through the Claude Console.

Does Claude Pro include the Claude API?

No. The API is billed separately from Pro. Max, Ultra and Team plans include monthly API credits that work with a linked Console organization.

What is the Claude API endpoint?

Messages go to https://api.anthropic.com/v1/messages as a POST request with the x-api-key, anthropic-version and content-type headers.

Which model ID should I use?

The docs suggest claude-opus-5-5 for most workloads. Use claude-haiku-5-5 for cheap, high-volume tasks, claude-sonnet-5-5 for speed, and claude-fable-5-2 for the hardest reasoning.

Can I use the Claude API from Python and TypeScript?

Yes. Install anthropic with pip for Python, or @anthropic-ai/sdk with npm for TypeScript. Both SDKs read your key from the environment.

Build it with us in Stride AI Academy

Four courses, weekly live calls and a community of people building and selling AI. Or start with 320+ free guides.

Keep reading

Free AI Coding guides