tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Generative AI > Anthropic Claude API > Claude Messages API Basics - Getting Started with Anthropic SDK

Claude Messages API Basics - Getting Started with Anthropic SDK

Author: Venkata Sudhakar

The Anthropic SDK makes it straightforward to call Claude from Python. For ShopMax India, Claude powers customer support chatbots, product description generators, and review summarizers. Getting the Messages API right from the start - understanding the request structure, response object, and error handling - saves significant debugging time in production integrations.

The Messages API accepts a model name, a maximum token limit, and a messages array where each message has a role (user or assistant) and content. The response contains a content array of blocks - typically a single text block for simple requests. Key fields to understand: stop_reason (end_turn means normal completion), usage (input_tokens and output_tokens for cost tracking), and model (echoes back the exact model version used).

The following example shows ShopMax India integrating with Claude to build a product description generator that takes a product name and specs and returns a customer-facing description:


It gives the following output,

Generated Description:
Experience cinema-quality entertainment at home with the Samsung 55-inch 4K QLED TV,
delivering breathtaking Quantum HDR visuals and seamless Tizen OS smart features -
all at an unbeatable value of Rs 54,990 for Indian households.
With stunning 3840x2160 resolution and vibrant quantum dot technology, this TV
transforms your living room into a premium viewing destination without breaking the budget.

Model used: claude-opus-4-5
Stop reason: end_turn
Input tokens: 89
Output tokens: 72
Estimated cost: Rs 0.5886

For ShopMax India production use, always store the API key in an environment variable using os.getenv rather than hardcoding it. Track input_tokens and output_tokens per request in your logging system - a sudden spike in input tokens usually means a prompt template bug injecting excess context. Set max_tokens conservatively for each use case: 300 for product descriptions, 1024 for support replies, 4096 for document analysis. The stop_reason field is critical in production - if you see max_tokens instead of end_turn, Claude was cut off mid-response and you should increase max_tokens or shorten your prompt.


 
  


  
bl  br