BeClaude
GuideBeginnerAPI2026-05-13

Your First Steps with the Claude API: A Practical Getting Started Guide

Learn how to set up your Anthropic account, get your API key, and make your first API call to Claude using Python, TypeScript, and cURL.

Quick Answer

This guide walks you through creating an Anthropic Console account, obtaining an API key, and making your first API call to Claude using cURL, Python, or TypeScript.

Claude APIGetting StartedAPI KeyMessages APIQuickstart

Introduction

Welcome to the Claude API! Whether you're building a chatbot, an AI-powered assistant, or integrating advanced reasoning into your application, the first step is always the same: getting started with the API. This guide will take you from zero to your first successful API call in just a few minutes.

By the end of this article, you'll have a working Claude integration and understand the core patterns you'll use in every project.

Prerequisites

Before you can start making API calls, you need two things:

  • An Anthropic Console account – Sign up at console.anthropic.com.
  • An API key – Generate one from the Console dashboard.
Note: The Claude API is a paid service. You'll need to add billing information in the Console to enable API access. However, many models offer a free tier or trial credits to get started.

Step 1: Create Your Account

Step 2: Generate an API Key

  • Log in to the Console.
  • Navigate to API Keys in the left sidebar.
  • Click Create Key.
  • Give your key a descriptive name (e.g., "My First App").
  • Copy the key immediately – you won't be able to see it again!
Security tip: Treat your API key like a password. Never commit it to version control or expose it in client-side code. Use environment variables instead.

Making Your First API Call

Now for the exciting part – let's talk to Claude! We'll show you three ways to make your first call: cURL (command line), Python, and TypeScript.

Using cURL

Open your terminal and run:

curl https://api.anthropic.com/v1/messages \
  --header "x-api-key: $ANTHROPIC_API_KEY" \
  --header "anthropic-version: 2023-06-01" \
  --header "content-type: application/json" \
  --data '{
    "model": "claude-sonnet-4-20250514",
    "max_tokens": 1024,
    "messages": [
      {"role": "user", "content": "Hello, Claude!"}
    ]
  }'

Replace $ANTHROPIC_API_KEY with your actual key or set it as an environment variable. You should receive a JSON response containing Claude's greeting.

Using Python

First, install the Anthropic Python SDK:

pip install anthropic

Then create a file called hello_claude.py:

import anthropic

client = anthropic.Anthropic( api_key="YOUR_API_KEY_HERE" # Better: use env variable )

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

print(message.content[0].text)

Run it:

python hello_claude.py

You'll see Claude's response printed in your terminal.

Using TypeScript

Install the Anthropic TypeScript SDK:

npm install @anthropic-ai/sdk

Create hello_claude.ts:

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

const client = new Anthropic({ apiKey: 'YOUR_API_KEY_HERE', // Better: use env variable });

async function main() { const message = await client.messages.create({ model: 'claude-sonnet-4-20250514', max_tokens: 1024, messages: [{ role: 'user', content: 'Hello, Claude!' }], });

console.log(message.content[0].text); }

main();

Run with:

npx ts-node hello_claude.ts

Understanding the Response

When you make a successful API call, Claude returns a JSON object with several fields. The most important ones are:

  • id – Unique identifier for this message.
  • model – The model that generated the response.
  • role – Always "assistant" for responses.
  • content – An array of content blocks. For text responses, it contains a single block with type: "text" and the text field.
  • stop_reason – Why the model stopped (e.g., "end_turn", "max_tokens", "stop_sequence").
  • usage – Token counts for input and output.
Here's a sample response:
{
  "id": "msg_01ABC123xyz",
  "type": "message",
  "role": "assistant",
  "content": [
    {
      "type": "text",
      "text": "Hello! How can I assist you today?"
    }
  ],
  "model": "claude-sonnet-4-20250514",
  "stop_reason": "end_turn",
  "usage": {
    "input_tokens": 12,
    "output_tokens": 10
  }
}

Next Steps: Core Patterns to Learn

Congratulations – you've made your first API call! Now it's time to build on that foundation. Here are the key patterns you'll use in every Claude integration:

Multi-turn Conversations

Claude can maintain context across multiple messages. Simply add previous messages to the messages array:

messages = [
    {"role": "user", "content": "What's the capital of France?"},
    {"role": "assistant", "content": "The capital of France is Paris."},
    {"role": "user", "content": "What's a famous landmark there?"}
]

System Prompts

Set the behavior and personality of Claude using a system prompt:

message = client.messages.create(
    model="claude-sonnet-4-20250514",
    system="You are a helpful assistant that speaks like a pirate.",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Hello!"}]
)

Handling Stop Reasons

The stop_reason field tells you why Claude stopped generating. Common values:

  • "end_turn" – Claude finished naturally.
  • "max_tokens" – The response hit your max_tokens limit.
  • "stop_sequence" – Claude encountered a custom stop sequence.
  • "tool_use" – Claude wants to call a tool (more on this in advanced guides).

Exploring Further

Once you're comfortable with the basics, dive deeper into Claude's capabilities:

  • Models Overview – Compare Claude models by capability, speed, and cost.
  • Features Overview – Explore tools, context management, structured outputs, and more.
  • Client SDKs – Reference documentation for Python, TypeScript, Java, and other client libraries.
  • Messages API Guide – Learn advanced patterns like streaming, batch processing, and citations.

Key Takeaways

  • Start with the Console – Create your Anthropic account and generate an API key before writing any code.
  • Use environment variables – Never hardcode your API key; store it securely in your environment.
  • Master the Messages API – The messages array is the core of every Claude interaction, supporting multi-turn conversations and system prompts.
  • Check stop reasons – Always inspect stop_reason to understand why Claude stopped and handle edge cases like token limits.
  • Explore the ecosystem – Claude offers tools, streaming, structured outputs, and more – all accessible through the same API pattern you just learned.