BeClaude
GuideBeginnerAPI2026-05-15

Getting Started with the Claude API: Your First Integration in Minutes

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

Quick Answer

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

Claude APIAPI keyMessages APIPythonTypeScript

Introduction

Claude, Anthropic's powerful AI assistant, is accessible not only through chat interfaces but also through a robust API. Whether you're building a custom chatbot, automating content generation, or integrating AI into your workflow, the Claude API gives you programmatic access to Claude's capabilities.

This guide will take you from zero to your first successful API call. By the end, you'll have a working integration and understand the foundational patterns you'll use in every Claude-powered application.

Prerequisites

Before you start, you'll need two things:

  • An Anthropic Console account – Sign up at console.anthropic.com.
  • An API key – Generate one from the API Keys section of your Console dashboard.
Important: Treat your API key like a password. Never share it, commit it to version control, or expose it in client-side code. Use environment variables or a secrets manager in production.

Step 1: Get Your API Key

  • Log in to the Anthropic Console.
  • Navigate to API Keys in the left sidebar.
  • Click Create Key and give it a descriptive name (e.g., "My First App").
  • Copy the key immediately – you won't be able to see it again.
Store your key securely. For this guide, we'll use an environment variable:
export ANTHROPIC_API_KEY="sk-ant-..."

Step 2: Make Your First API Call

Claude uses the Messages API – a simple, consistent interface for sending conversations and receiving responses. Let's make a call using three popular methods.

Option A: cURL

cURL is the quickest way to test the API from your terminal:

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

You should receive a JSON response containing Claude's greeting.

Option B: Python (with the official SDK)

Install the Anthropic Python SDK:

pip install anthropic

Then create a file hello_claude.py:

import anthropic

client = anthropic.Anthropic()

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

Option C: TypeScript (with the official SDK)

Install the Anthropic TypeScript SDK:

npm install @anthropic-ai/sdk

Create hello_claude.ts:

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

const client = new Anthropic();

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

A successful API call returns a JSON object with the following structure:

{
  "id": "msg_01ABC123...",
  "type": "message",
  "role": "assistant",
  "content": [
    {
      "type": "text",
      "text": "Hello! How can I help you today?"
    }
  ],
  "model": "claude-sonnet-4-20250514",
  "stop_reason": "end_turn",
  "stop_sequence": null,
  "usage": {
    "input_tokens": 10,
    "output_tokens": 12
  }
}

Key fields to note:

  • content: An array of content blocks (usually one text block).
  • stop_reason: Why the response ended – "end_turn" means Claude finished naturally.
  • usage: Token counts for billing and monitoring.

Next Steps: Core API Patterns

Now that you've made your first call, here are the essential patterns you'll use in every integration:

Multi-turn Conversations

Send a conversation history to maintain context:

message = client.messages.create(
    model="claude-sonnet-4-20250514",
    max_tokens=1024,
    messages=[
        {"role": "user", "content": "What's the capital of France?"},
        {"role": "assistant", "content": "The capital of France is Paris."},
        {"role": "user", "content": "What is it known for?"}
    ]
)

System Prompts

Set Claude's behavior with a system prompt:

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

Handling Stop Reasons

The stop_reason field tells you why Claude stopped:

  • "end_turn" – Claude finished naturally.
  • "max_tokens" – The response was cut off; you may need to continue.
  • "stop_sequence" – A custom stop sequence was triggered.
  • "tool_use" – Claude wants to call a tool (advanced).

What's Next?

You've completed the quickstart! Here's what to explore next:

  • Models overview – Compare Claude models by capability, speed, and cost.
  • Features overview – Dive into tools, context management, structured outputs, and more.
  • Client SDKs – Reference docs for Python, TypeScript, Java, and other languages.
  • Messages API guide – Master multi-turn conversations, system prompts, and advanced patterns.

Key Takeaways

  • Get your API key from the Anthropic Console and store it securely as an environment variable.
  • The Messages API is the core interface – send a model, max_tokens, and an array of messages.
  • Use the official SDKs (Python, TypeScript, Java) for cleaner code and built-in error handling.
  • Understand the response – especially content, stop_reason, and usage – to build robust integrations.
  • Start simple with a single-turn call, then layer in system prompts, conversation history, and advanced features.