BeClaude
GuideBeginnerAgents2026-05-22

Your First Steps with the Claude API: From Setup to Production

Learn how to integrate Claude into your applications using the Messages API and Managed Agents. Includes code examples, SDK setup, and best practices for production.

Quick Answer

This guide walks you through getting an API key, installing the Python SDK, making your first API call with the Messages API, and choosing between direct model access and Managed Agents for production.

Claude APIPython SDKMessages APIManaged AgentsQuickstart

Introduction

Claude is more than just a chat interface. Behind the scenes, the Claude API gives developers the power to embed Claude’s reasoning, coding, and creative capabilities directly into their own applications. Whether you’re building a customer support bot, a code review assistant, or a content generation pipeline, the API is your gateway to production-grade AI.

This guide will take you from zero to your first working API call. You’ll learn how to get your API key, install the SDK, send messages, and understand the two main development surfaces: Messages API (direct model access) and Managed Agents (autonomous agent infrastructure). By the end, you’ll have a clear path to building and shipping with Claude.

Prerequisites

Before you start, make sure you have:

  • A Claude API account (sign up for free)
  • Python 3.8+ installed on your machine
  • Basic familiarity with Python or TypeScript (code examples are provided in both)
  • A terminal or command prompt

Step 1: Get Your API Key

  • Log in to the Anthropic Console.
  • Navigate to API Keys in the left sidebar.
  • Click Create API Key and give it a name (e.g., "My First App").
  • Copy the key and store it securely — you won’t be able to see it again.
Security tip: Never hardcode your API key in source code. Use environment variables or a secrets manager.
export ANTHROPIC_API_KEY="sk-ant-..."

Step 2: Install the SDK

Anthropic provides official SDKs for Python, TypeScript, Go, Java, Ruby, PHP, and C#. We’ll use Python here.

pip install anthropic

If you prefer TypeScript:

npm install @anthropic-ai/sdk

Step 3: Make Your First API Call

Create a file called hello_claude.py and paste the following:

import anthropic

client = anthropic.Anthropic()

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

print(message.content[0].text)

Run it:

python hello_claude.py

You should see Claude’s friendly greeting. That’s it — you’ve made your first API call!

Understanding the Code

  • client.messages.create() — the core method for sending a conversation turn.
  • model — choose from the Claude family: claude-opus-4-7 (most capable), claude-sonnet-4-6 (best balance), or claude-haiku-4-5 (fastest).
  • max_tokens — the maximum number of tokens in Claude’s response.
  • messages — an array of message objects, each with a role (user or assistant) and content.

Step 4: Choose Your Development Surface

The Claude API offers two main ways to build:

Messages API (Direct Model Access)

You control every turn, manage conversation state yourself, and write your own tool loop. This is ideal for:

  • Custom chat interfaces
  • Fine-grained control over prompts
  • Integrating Claude into existing workflows
Example — multi-turn conversation:
import anthropic

client = anthropic.Anthropic()

messages = [ {"role": "user", "content": "What is the capital of France?"}, {"role": "assistant", "content": "The capital of France is Paris."}, {"role": "user", "content": "Tell me a fun fact about that city."} ]

response = client.messages.create( model="claude-sonnet-4-6", max_tokens=512, messages=messages )

print(response.content[0].text)

Managed Agents (Autonomous Agent Infrastructure)

For more complex use cases, Managed Agents handle conversation state, tool execution, and event history for you. You define the agent’s behavior and let it run autonomously.

Example — creating a Managed Agent:
import anthropic

client = anthropic.Anthropic()

agent = client.agents.create( name="CustomerSupportBot", model="claude-sonnet-4-6", instructions="You are a helpful customer support agent for a SaaS company. Answer questions politely and escalate if needed.", tools=[ { "type": "function", "function": { "name": "get_order_status", "description": "Retrieve the status of an order by ID", "parameters": { "type": "object", "properties": { "order_id": {"type": "string"} }, "required": ["order_id"] } } } ] )

Start a session

session = client.agents.sessions.create(agent_id=agent.id)

Send a message

response = client.agents.sessions.send_message( agent_id=agent.id, session_id=session.id, message="I need help with order #12345" )

print(response.content)

Managed Agents are perfect for:

  • Long-running autonomous tasks
  • Stateful conversations with tool use
  • Deploying agents that need persistent memory

Step 5: Explore Advanced Features

Once you’re comfortable with the basics, the API offers several powerful capabilities:

Extended Thinking

Enable Claude to reason step-by-step before responding, useful for complex math, logic, or coding tasks.

response = client.messages.create(
    model="claude-opus-4-7",
    max_tokens=2048,
    thinking={"type": "enabled", "budget_tokens": 1024},
    messages=[{"role": "user", "content": "Solve this differential equation: dy/dx = 3x^2 + 2x"}]
)

Vision

Claude can analyze images. Pass image data in the content array:

import base64

with open("chart.png", "rb") as f: image_data = base64.b64encode(f.read()).decode("utf-8")

response = client.messages.create( model="claude-sonnet-4-6", max_tokens=1024, messages=[ { "role": "user", "content": [ {"type": "text", "text": "Describe this chart."}, {"type": "image", "source": {"type": "base64", "media_type": "image/png", "data": image_data}} ] } ] )

Tool Use

Give Claude access to external functions (APIs, databases, etc.):

tools = [
    {
        "name": "get_weather",
        "description": "Get the current weather for a city",
        "input_schema": {
            "type": "object",
            "properties": {
                "city": {"type": "string"}
            },
            "required": ["city"]
        }
    }
]

response = client.messages.create( model="claude-sonnet-4-6", max_tokens=1024, tools=tools, messages=[{"role": "user", "content": "What's the weather in Tokyo?"}] )

Prompt Caching

Reduce latency and cost for repetitive prompts by caching common prefixes.

Streaming

Get responses token-by-token for a real-time experience:

stream = client.messages.create(
    model="claude-sonnet-4-6",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Write a short poem about AI."}],
    stream=True
)

for chunk in stream: if chunk.type == "content_block_delta": print(chunk.delta.text, end="")

Step 6: Evaluate and Ship

Before going to production, consider these best practices:

  • Prompt engineering: Test different phrasings to get reliable outputs.
  • Evaluation: Run batch tests with known inputs and expected outputs.
  • Safety & guardrails: Use content filtering and moderation layers.
  • Rate limits & errors: Handle 429 (rate limit) and 500 (server error) gracefully with retries.
  • Cost optimization: Use claude-haiku-4-5 for high-volume, simple tasks and claude-opus-4-7 only for complex reasoning.

Deployment Options

You can run Claude anywhere:

  • Anthropic API — direct access via the cloud
  • AWS Bedrock — integrate with your AWS infrastructure
  • Google Cloud Vertex AI — deploy within GCP
  • Microsoft Foundry — use with Azure services

Next Steps

  • Explore the Claude Cookbook for ready-made code samples.
  • Try the Workbench to experiment with prompts interactively.
  • Learn about Claude Code — an agentic coding assistant in your terminal.

Key Takeaways

  • Get started in minutes: Sign up, grab your API key, install the SDK, and make your first call with just a few lines of code.
  • Two development surfaces: Use the Messages API for full control over conversation state, or Managed Agents for autonomous, stateful agents.
  • Choose the right model: Opus for complex tasks, Sonnet for balanced performance, Haiku for speed and cost efficiency.
  • Leverage advanced features: Extended thinking, vision, tool use, streaming, and prompt caching unlock powerful applications.
  • Deploy anywhere: Run Claude via the Anthropic API, AWS Bedrock, Google Cloud Vertex AI, or Microsoft Foundry.