tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Generative AI > Large Language Models > Claude API Basics - The Messages API

Claude API Basics - The Messages API

Author: Venkata Sudhakar

The Anthropic Claude API is accessed through the Messages endpoint - a simple, clean interface where you send a list of messages and receive a response. Each message has a role (user or assistant) and content (the text). You can send a single user message for a one-shot query, or build up a full conversation history for multi-turn dialogue. Claude is one of the strongest commercially available LLMs for instruction-following, long-document analysis, and nuanced reasoning - and its API is designed to be straightforward to integrate into any Python application.

The three key parameters for every Claude API call are: model (which Claude version to use - claude-opus-4-5 for maximum intelligence, claude-sonnet-4-5 for the best balance of speed and capability, claude-haiku-4-5 for fast cheap tasks), max_tokens (the maximum length of the response), and messages (the conversation list). The system parameter sets the overall behaviour instruction for the session - equivalent to OpenAI's system message but passed as a top-level parameter rather than inside the messages list.

The below example shows a retail business using the Claude API for three common tasks: answering a product question, classifying a customer complaint, and extracting structured data from a purchase request email.


It gives the following output,

=== Product Q&A ===
Yes, the Dell XPS 15 (9530) includes two Thunderbolt 4 ports, supporting
data transfer up to 40 Gbps, DisplayPort output, and USB4. Battery life
is rated at approximately 13 hours for typical use, though real-world
performance varies between 7-10 hours depending on workload.

Tokens used: 87 in, 68 out

It gives the following output,

Complaint: My order arrived 10 days late and the packaging was d...
Category:  DELIVERY

Complaint: The laptop fan is making a grinding noise after just o...
Category:  PRODUCT_DEFECT

Complaint: I was charged twice for the same order on my credit ca...
Category:  BILLING

=== Multi-turn Sales Chat ===
Customer: I need a laptop for video editing
Claude:   For video editing, you need strong CPU/GPU performance, at least
          16GB RAM, and a colour-accurate display. Are you editing 1080p,
          4K, or higher? And what software do you use - Premiere, DaVinci,
          or Final Cut? Your budget will also help me narrow down the options.

Customer: My budget is around Rs 80,000
Claude:   At Rs 80,000 for video editing, I would recommend the Apple
          MacBook Pro M3 14-inch or the ASUS ProArt Studiobook 16. The MacBook
          excels in DaVinci Resolve and Final Cut with its unified memory
          architecture. The ASUS is better if you prefer Windows and need a
          larger screen. Both handle 4K editing comfortably in this range.

# conversation list grows with each turn - Claude remembers the editing context
# when answering the budget question without being told again

Model selection guide for production use: use claude-haiku-4-5 for classification, extraction, and short factual Q&A where speed and cost matter most. Use claude-sonnet-4-5 for customer-facing conversations, document analysis, and tasks requiring nuanced judgment - it delivers near-opus quality at a fraction of the cost. Reserve claude-opus-4-5 for your most complex reasoning tasks: analysing lengthy legal documents, generating detailed financial reports, and any task where quality is genuinely worth the premium. Always set a realistic max_tokens - an unnecessarily large value does not cost more if unused, but setting it too small truncates responses mid-sentence.


 
  


  
bl  br