Home About Skills Products
Work
Projects Services Experience
Learn
Tutorials Courses Blogs Resources
Contact
Tutorials · AI & Tools

Building Your First AI App with the Claude API

Building Your First AI App with the Claude API

Claude Code is for the terminal, but if you need AI capability inside your own app (a website, a backend service, a chatbot), you use the Anthropic API directly.

Setup

pip install anthropic

Generate an API key from the Anthropic Console and save it as an environment variable:

export ANTHROPIC_API_KEY="your-api-key-here"

Your First API Call

import anthropic

client = anthropic.Anthropic()  # picks up the API key from the env variable automatically

message = client.messages.create(
    model="claude-sonnet-4-5",  # check your Anthropic dashboard for the latest model ID
    max_tokens=1024,
    messages=[
        {"role": "user", "content": "Write a 3-line poem about the mountains of Nepal."}
    ]
)

print(message.content[0].text)

The messages array is the conversation history — you have to send the full context every time, since the API is stateless (there's no built-in memory between requests).

Controlling Behavior with a System Prompt

message = client.messages.create(
    model="claude-sonnet-4-5",
    max_tokens=1024,
    system="You are a friendly customer support assistant who only replies in short, clear sentences.",
    messages=[
        {"role": "user", "content": "When will my order arrive?"}
    ]
)

The system parameter sets the model's "personality" and rules — it applies to every turn of the conversation.

Just as Simple in JavaScript

import Anthropic from '@anthropic-ai/sdk';

const client = new Anthropic();

const message = await client.messages.create({
  model: 'claude-sonnet-4-5',
  max_tokens: 1024,
  messages: [{ role: 'user', content: 'Hello Claude!' }],
});

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

Key Takeaways

  • The API is stateless — the full conversation history has to be sent with every request.
  • The system parameter controls the model's behavior/personality.
  • Official SDKs exist for both Python and JavaScript, and integration is very similar in both.
What is Claude Code? Introduction to the AI-Powered Coding Assistant

What is Claude Code? Introduction to the AI-Powered Coding Assistant

What Claude Code actually is, how it differs from a normal AI chatbot, and what it can do for developers.

Installing and Setting Up Claude Code

Installing and Setting Up Claude Code

Install Claude Code on your machine, log in, and use it for the first time in a new project.

Exploring a Codebase and Fixing Bugs with Claude Code

Exploring a Codebase and Fixing Bugs with Claude Code

Navigate and understand an unfamiliar codebase with Claude Code, and get real bugs fixed.

Advertisement
Esc