BeClaude
Guide2026-05-02

Getting Started with Claude: Your Complete Guide to the API and Managed Agents

Learn how to build with Claude AI using the Messages API or Managed Agents. Step-by-step guide covering setup, core features, and best practices for developers.

Quick Answer

This guide walks you through building with Claude—from making your first API call to choosing between the Messages API and Managed Agents. You'll learn the core request/response structure, model selection, and key capabilities like vision, extended thinking, and tool use.

Claude APIMessages APIManaged Agentsdeveloper guideAnthropic

Getting Started with Claude: Your Complete Guide to the API and Managed Agents

Claude by Anthropic represents a new generation of AI assistants designed for complex reasoning, coding, and enterprise workflows. Whether you're building a chatbot, automating tasks, or integrating AI into your product, this guide will help you go from zero to a working Claude integration.

Understanding Your Options: Messages API vs. Managed Agents

Anthropic offers two primary ways to build with Claude, each suited to different use cases:

FeatureMessages APIClaude Managed Agents
What it isDirect model prompting accessPre-built, configurable agent harness
Best forCustom agent loops and fine-grained controlLong-running tasks and asynchronous work
Control levelFull control over prompts and logicManaged infrastructure with configuration
Learning curveSteeper (build from scratch)Gentler (configure, don't code loops)
For most new developers, the Messages API is the recommended starting point because it gives you direct access to Claude's capabilities and full control over the interaction loop.

Step 1: Make Your First API Call

Let's start by setting up your environment and sending your first message to Claude.

Prerequisites

Python Quickstart

import anthropic

client = anthropic.Anthropic(api_key="your-api-key-here")

message = client.messages.create( model="claude-sonnet-4-20250514", max_tokens=1000, temperature=0, system="You are a helpful assistant.", messages=[ {"role": "user", "content": "Hello, Claude! What can you help me with?"} ] )

print(message.content[0].text)

TypeScript/JavaScript Quickstart

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-sonnet-4-20250514', max_tokens: 1000, temperature: 0, system: 'You are a helpful assistant.', messages: [ { role: 'user', content: 'Hello, Claude! What can you help me with?' } ] });

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

main();

Pro tip: Always set temperature to 0 for deterministic tasks like coding or data extraction. Use higher values (0.3–0.7) for creative tasks.

Step 2: Understand the Messages API Structure

The Messages API is the core way to interact with Claude. Here's what you need to know:

Request Components

  • model: Which Claude model to use (e.g., claude-sonnet-4-20250514)
  • messages: An array of conversation turns, each with a role ("user" or "assistant") and content
  • system: An optional system prompt that sets Claude's behavior
  • max_tokens: Maximum tokens in the response
  • temperature: Controls randomness (0–1)

Multi-Turn Conversations

conversation = [
    {"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?"}
]

response = client.messages.create( model="claude-sonnet-4-20250514", max_tokens=500, messages=conversation )

Handling Stop Reasons

When Claude finishes generating, the response includes a stop_reason field. Common values:

  • "end_turn": Claude naturally finished
  • "max_tokens": Hit the token limit—you may need to continue
  • "tool_use": Claude wants to use a tool (more on this later)
response = client.messages.create(...)
if response.stop_reason == "max_tokens":
    # Continue the conversation to get more output
    print("Response was truncated. Consider increasing max_tokens.")

Step 3: Choose the Right Model

Claude comes in several flavors, each optimized for different needs:

ModelBest ForSpeedCost
Claude Opus 4.7Complex reasoning, agentic codingModerateHighest
Claude Sonnet 4.6Coding, agents, enterprise workflowsFastMedium
Claude Haiku 4.5High-throughput, simple tasksFastestLowest
Recommendation: Start with Sonnet for most use cases—it offers the best balance of intelligence, speed, and cost. Upgrade to Opus when you need deep reasoning. Use Haiku for high-volume, low-complexity tasks.

Step 4: Explore Key Features

Claude offers a rich set of capabilities beyond simple text generation:

Extended Thinking

For complex reasoning tasks, enable Claude's extended thinking mode:

response = client.messages.create(
    model="claude-sonnet-4-20250514",
    max_tokens=2000,
    thinking={"type": "enabled", "budget_tokens": 1000},
    messages=[{"role": "user", "content": "Solve this complex math problem step by step..."}]
)

Structured Outputs

Get JSON-formatted responses for easier parsing:

response = client.messages.create(
    model="claude-sonnet-4-20250514",
    messages=[{"role": "user", "content": "List 3 countries and their capitals as JSON."}],
    response_format={"type": "json_object"}
)

Vision (Image Processing)

Claude can analyze images and screenshots:

import base64

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

response = client.messages.create( model="claude-sonnet-4-20250514", messages=[{ "role": "user", "content": [ {"type": "text", "text": "What's in this image?"}, {"type": "image", "source": {"type": "base64", "media_type": "image/png", "data": image_data}} ] }] )

Tool Use

Claude can call external tools and APIs. Here's a minimal example:

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

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

Best Practices for Production

  • Use prompt caching for frequently used system prompts to reduce latency and cost
  • Implement streaming for better user experience with long responses
  • Set appropriate max_tokens to avoid unexpected truncation
  • Handle errors gracefully—API calls can fail due to rate limits or network issues
  • Monitor token usage to control costs

Developer Tools

Anthropic provides several tools to accelerate development:

  • Developer Console: Prototype and test prompts in your browser with the Workbench
  • API Reference: Full documentation for the Claude API and client SDKs
  • Claude Cookbook: Interactive Jupyter notebooks covering PDFs, embeddings, and more

Key Takeaways

  • Choose the right integration path: Use the Messages API for full control, or Managed Agents for hands-off deployment
  • Start with Sonnet: Claude Sonnet 4.6 offers the best balance of intelligence, speed, and cost for most applications
  • Master the Messages API: Understand request structure, stop reasons, and multi-turn conversations to build robust applications
  • Leverage advanced features: Extended thinking, structured outputs, vision, and tool use unlock powerful use cases
  • Follow best practices: Use prompt caching, streaming, and proper error handling for production-ready applications