DEV Community

Said Olano
Said Olano

Posted on

Claude AI: Building with the Latest Models (2026-09-07 23:50)

Claude AI: Building with the Latest Models

Anthropic's Claude family of models has become a go-to choice for developers building AI-powered applications. Whether you're generating code, summarizing documents, or building autonomous agents, understanding how to work effectively with the latest models is key to shipping reliable products.

This post walks through the practical essentials of building with Claude.

Why Claude?

Claude models are designed with a strong emphasis on helpfulness, safety, and reasoning quality. A few characteristics stand out for developers:

  • Large context windows that let you pass extensive documents, codebases, or conversation histories.
  • Strong reasoning and coding performance, making them well-suited for agentic and technical workflows.
  • Tool use support, enabling models to call external functions and APIs.
  • Predictable, structured outputs when guided with clear instructions.

Getting Started with the API

The fastest way to build is through the Messages API. Here's a minimal example using Python:

import anthropic

client = anthropic.Anthropic(api_key="YOUR_API_KEY")

message = client.messages.create(
    model="claude-sonnet-4-20250514",
    max_tokens=1024,
    messages=[
        {"role": "user", "content": "Explain vector databases in two sentences."}
    ],
)

print(message.content[0].text)
Enter fullscreen mode Exit fullscreen mode

The messages array holds the conversation. Each entry has a role (user or assistant) and content. To maintain a conversation, append prior turns back into the array.

Using System Prompts

System prompts steer the model's behavior across the entire conversation. Use them to define tone, role, and constraints:

message = client.messages.create(
    model="claude-sonnet-4-20250514",
    max_tokens=1024,
    system="You are a senior backend engineer. Be concise and prefer code examples.",
    messages=[
        {"role": "user", "content": "How do I add retry logic to an HTTP client?"}
    ],
)
Enter fullscreen mode Exit fullscreen mode

A well-crafted system prompt is often the single highest-leverage improvement you can make.

Working with Tool Use

Tool use lets Claude interact with external systems. You define the tools, and the model decides when to call them.

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

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

When the model wants to use a tool, it returns a tool_use block. Your code executes the function and returns the result with a tool_result message, and the model continues from there.

Best Practices

To get consistent, production-grade results, keep these principles in mind:

  1. Be explicit. Vague prompts produce vague answers. State the format, length, and audience.
  2. Use examples. A few input/output examples dramatically improve reliability for structured tasks.
  3. Control output with XML tags. Ask the model to wrap responses in tags like <answer> for easy parsing.
  4. Stream long responses. Use streaming to improve perceived latency in user-facing apps.
  5. Set sensible token limits. Cap max_tokens to control cost and response length.

Handling Errors and Rate Limits

Production applications should gracefully handle rate limits and transient failures. Implement exponential backoff:

import time

def call_with_retry(client, **kwargs):
    for attempt in range(5):
        try:
            return client.messages.create(**kwargs)
        except anthropic.RateLimitError:
            time.sleep(2 ** attempt)
    raise RuntimeError("Exceeded retry attempts")
Enter fullscreen mode Exit fullscreen mode

Conclusion

Building with Claude comes down to a few fundamentals: choose the right model for your task, write clear system prompts, leverage tool use for real-world actions, and handle errors robustly. Start small with the Messages API, iterate on your prompts, and layer in tools and streaming as your application grows.

With these building blocks, you'll be well-equipped to ship reliable, AI-powered features on top of the latest Claude models.

Top comments (0)