BeClaude
Guide2026-04-30

Getting Started with Claude: Your First API Call and Beyond

Learn how to set up your Anthropic account, get an API key, and make your first call to Claude. This guide covers prerequisites, code examples in Python and TypeScript, and next steps.

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. You'll also learn about the Messages API and next steps for building with Claude.

Claude APIgetting startedAPI keyMessages APIquickstart

Introduction

Welcome to the Claude AI ecosystem! Whether you're a developer building intelligent applications or a hobbyist exploring the capabilities of large language models, Claude's API offers a powerful, flexible way to integrate state-of-the-art AI into your projects. This guide will take you from zero to your first successful API call, covering account setup, authentication, and the fundamental patterns you'll use every time you interact with Claude.

By the end of this article, you'll have a working API key, have made your first request, and understand the core concepts of the Messages API. Let's dive in.

Prerequisites

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

  • An Anthropic Console account – This is your central hub for managing API keys, monitoring usage, and accessing documentation.
  • An API key – A unique token that authenticates your requests to the Claude API.

Step 1: Create an Anthropic Console Account

Navigate to console.anthropic.com and sign up. You can use your Google account, GitHub account, or an email address. Once you've verified your email, you'll land on the Console dashboard.

Step 2: Generate an API Key

  • In the Console, click on API Keys in the left sidebar.
  • Click Create Key.
  • Give your key a descriptive name (e.g., "My First Claude App").
  • Copy the key immediately and store it securely. You won't be able to see it again after you close the dialog.
Security Tip: Never hard-code your API key in client-side code or commit it to version control. Use environment variables or a secrets manager.

Making Your First API Call

Now for the exciting part: sending a message to Claude and getting a response. We'll cover three methods: cURL (for quick testing), Python, and TypeScript.

Using cURL

cURL is the fastest way to test your API key. 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-3-5-sonnet-20241022",
  "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" )

message = client.messages.create( model="claude-3-5-sonnet-20241022", 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 friendly response printed to your console.

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', });

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

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

main();

Run with your TypeScript runner (e.g., ts-node):

ts-node hello_claude.ts

Understanding the Messages API

Your first API call used the Messages API, which is the primary way to interact with Claude. Here's what each parameter does:

  • model: Specifies which Claude model to use. claude-3-5-sonnet-20241022 is the latest Sonnet model, offering a great balance of speed and capability.
  • max_tokens: The maximum number of tokens Claude can generate in its response. One token is roughly 3/4 of a word.
  • messages: An array of message objects, each with a role (either "user" or "assistant") and content. This array represents the conversation history.

Multi-turn Conversations

To continue a conversation, simply append new messages to the array. For example:

messages = [
    {"role": "user", "content": "What is the capital of France?"},
    {"role": "assistant", "content": "The capital of France is Paris."},
    {"role": "user", "content": "What is its population?"}
]

message = client.messages.create( model="claude-3-5-sonnet-20241022", max_tokens=1024, messages=messages )

System Prompts

You can guide Claude's behavior using a system prompt. This is a high-level instruction that sets the context for the entire conversation:

message = client.messages.create(
    model="claude-3-5-sonnet-20241022",
    max_tokens=1024,
    system="You are a helpful assistant that speaks like a pirate.",
    messages=[
        {"role": "user", "content": "Tell me about the weather."}
    ]
)

Stop Reasons

Every response includes a stop_reason field that tells you why Claude stopped generating. Common values:

  • "end_turn": Claude finished naturally.
  • "max_tokens": The response hit the max_tokens limit.
  • "stop_sequence": Claude encountered a custom stop sequence you provided.

Next Steps

Congratulations! You've made your first API call and understand the basics of the Messages API. Here's what to explore next:

  • Features Overview: Dive into Claude's capabilities like tools, context management, structured outputs, and prompt caching.
  • Models Overview: Compare Claude models by capability, cost, and speed to choose the right one for your use case.
  • Client SDKs: Explore the full reference documentation for Python, TypeScript, Java, and other client libraries.
  • Prompt Engineering: Learn best practices for crafting effective prompts that get the best results from Claude.

Key Takeaways

  • Get an API key from the Anthropic Console to authenticate your requests.
  • Use the Messages API with model, max_tokens, and messages parameters for all interactions.
  • Support multi-turn conversations by appending to the messages array, and use system prompts to set behavior.
  • Check stop_reason to understand why Claude stopped generating—it's essential for debugging.
  • Explore further with tools, structured outputs, and prompt engineering to unlock Claude's full potential.