Getting started overview

Getting started with Anthropic Claude involves a sequence of steps to configure your development environment and make your first programmatic request. This guide covers account creation, API key generation, and executing a basic interaction with the Claude Messages API using a Python example. The Anthropic Claude API provides access to models like Claude Sonnet 4.5, Claude Haiku 4.5, and Claude Opus 4.7, supporting various applications from long-form content generation to complex agentic workflows Anthropic Claude API documentation.

The primary interface for interaction is the Messages API, designed to handle conversational turns and tool use. Anthropic provides official SDKs for Python, Node.js, Java, and Go, simplifying integration into diverse application stacks.

Quick reference steps

The following table outlines the essential steps to get started with Anthropic Claude:

Step What to do Where
1. Sign up Create an Anthropic account. Anthropic signup page
2. Get API Key Generate a new API key from your account settings. Anthropic API keys page
3. Install SDK Install the official Python, Node.js, Java, or Go SDK. Anthropic developer libraries
4. Configure Environment Set your API key as an environment variable (ANTHROPIC_API_KEY). Local development environment
5. Make First Request Write and execute a simple code snippet using the Messages API. Your preferred code editor

Create an account and get keys

To begin, you will need an Anthropic account and an associated API key. This key authenticates your requests to the Claude API services.

Account creation

  1. Navigate to the Anthropic signup page.
  2. Provide the required information, including your email address and a strong password.
  3. Complete any email verification steps as prompted.
  4. Once registered, you will be directed to your dashboard.

API key generation

After creating your account, generate an API key:

  1. From your Anthropic dashboard, click on API Keys or navigate directly to the Anthropic API keys management page.
  2. Click the Create New Key button.
  3. Optionally, provide a descriptive name for your API key to help manage multiple keys.
  4. The system will generate and display your new API key. Copy this key immediately. For security, Anthropic will only show the full key once. If you lose it, you will need to generate a new one.
  5. Store your API key securely. It is recommended to use environment variables or a secrets management service rather than hardcoding it directly into your application code.

Anthropic handles API key security, but best practices for managing API keys generally apply, such as rotating keys periodically and restricting their scope where possible AWS recommended practices for managing access keys.

Your first request

This section demonstrates how to make a basic request to the Anthropic Claude Messages API using the official Python SDK. This example uses Claude Sonnet 4.5, a model well-suited for general-purpose tasks Anthropic model pricing details.

Prerequisites

  • Python 3.8+ installed.
  • Your Anthropic API key.

Install the Python SDK

Open your terminal or command prompt and run:


pip install anthropic

Set the API key environment variable

Before running your code, set the ANTHROPIC_API_KEY environment variable:

Linux/macOS:


export ANTHROPIC_API_KEY="YOUR_ANTHROPIC_API_KEY"

Windows (Command Prompt):


set ANTHROPIC_API_KEY="YOUR_ANTHROPIC_API_KEY"

Windows (PowerShell):


$env:ANTHROPIC_API_KEY="YOUR_ANTHROPIC_API_KEY"

Replace YOUR_ANTHROPIC_API_KEY with the key you generated.

Python code example

Create a Python file (e.g., first_claude_call.py) and add the following code:


import anthropic
import os

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

message = client.messages.create(
    model="claude-sonnet-4-5",  # Or "claude-opus-4-7", "claude-haiku-4-5"
    max_tokens=1024,
    messages=[
        {
            "role": "user",
            "content": "What is the capital of France?"
        }
    ]
)

print(f"Response from Claude: {message.content[0].text}")

Execute the code

Run the script from your terminal:


python first_claude_call.py

You should see a response similar to: Response from Claude: The capital of France is Paris.

Common next steps

Once you have successfully made your first API call, consider these next steps to further your development with Anthropic Claude:

  • Explore different models: Experiment with claude-opus-4-7 for complex reasoning or claude-haiku-4-5 for faster, more cost-effective tasks Anthropic models overview.
  • Implement Tool Use: Learn how to enable Claude to interact with external tools and APIs, facilitating agentic workflows. This feature allows Claude to call custom functions you define Anthropic tool use guide.
  • Integrate with Computer Use: For advanced use cases, explore Computer Use, where Claude can control a web browser or other applications.
  • Manage Context and Prompt Engineering: Understand how to effectively manage the large context windows (up to 200k tokens default, 1M in beta for Opus 4.7) and engineer prompts to achieve desired outputs Anthropic prompt engineering best practices.
  • Utilize Prompt Caching: For applications with repeated context or system prompts, implement prompt caching to reduce API costs by up to 90% Anthropic prompt caching documentation.
  • Explore Batch API: For non-time-sensitive, high-volume workloads, the Batch API offers a 50% cost discount with a 24-hour SLA.
  • Review Security and Compliance: Familiarize yourself with Anthropic's security posture, including SOC 2 Type II, ISO 42001, and HIPAA BAA availability, especially for sensitive data applications Anthropic security page.
  • Monitor Usage and Costs: Regularly check your API usage and understand the pricing structure for different models to manage your expenses effectively Anthropic pricing information.

Troubleshooting the first call

Encountering issues during your initial API call is common. Here are some troubleshooting steps:

  • API Key Not Set: Ensure the ANTHROPIC_API_KEY environment variable is correctly set and accessible to your script. If running in an IDE, you might need to configure environment variables within the IDE settings.
  • Incorrect API Key: Double-check that you copied the API key correctly and that it hasn't expired or been revoked. Generate a new key if necessary.
  • Network Issues: Verify your internet connection. Proxy settings or firewalls might block outgoing API requests.
  • Rate Limits Exceeded: While less common for a first call, if you're rapidly testing, you might hit the default rate limits (e.g., 50 RPM for Sonnet on Tier 1). Check the API response for rate limit headers.
  • Model Not Found/Invalid: Ensure the model name in your code (e.g., claude-sonnet-4-5) is accurate and available. Refer to the Anthropic models overview for current model identifiers.
  • Invalid JSON or Message Structure: The Messages API expects a specific JSON structure for its messages array. Ensure your role is either user or assistant and content is a string. Review the Anthropic Messages API reference for correct formatting.
  • SDK Version Mismatch: Ensure your installed SDK version is up to date. Outdated SDKs might not support the latest API features or models. Run pip install --upgrade anthropic for Python.
  • Billing Issues: If you are on a paid tier, ensure your billing information is current and there are no outstanding payments.
  • Check Anthropic Status Page: Occasionally, service outages can occur. Check the Anthropic API status page for any reported incidents.