Claude API Basics
Getting Started with the Claude API
Learn how to integrate Anthropic's Claude into your applications with the Messages API.
What is the Claude API?
The Claude API by Anthropic lets you integrate Claude's AI capabilities directly into your applications. Claude is a family of AI assistants known for:
- Strong reasoning — Complex analysis and problem-solving
- Long context — Process entire codebases or documents
- Safety — Designed to be helpful, harmless, and honest
- Tool use — Execute code, call functions, use external tools
Available Models
| Model | Description | Best For |
|---|---|---|
| claude-opus-4 | Most powerful | Complex analysis, research |
| claude-sonnet-4-5 | Balanced | Most tasks |
| claude-haiku-3-5 | Fastest/cheapest | Simple tasks, high volume |
Getting an API Key
- Sign up at console.anthropic.com
- Navigate to API Keys
- Create a new key
- Store it securely (never in client-side code)
SDK Options
Anthropic provides official SDKs for:
- Python:
anthropicpackage - TypeScript/JavaScript:
@anthropic-ai/sdkpackage
Example
typescript
// Install: npm install @anthropic-ai/sdk
import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic({
apiKey: process.env.ANTHROPIC_API_KEY, // from env
});
async function main() {
const message = await client.messages.create({
model: "claude-opus-4-5",
max_tokens: 1024,
messages: [
{
role: "user",
content: "Explain the difference between REST and GraphQL in 3 sentences.",
},
],
});
console.log(message.content[0].text);
}
main();
// Python equivalent:
// import anthropic
// client = anthropic.Anthropic()
// message = client.messages.create(
// model="claude-opus-4-5",
// max_tokens=1024,
// messages=[{"role": "user", "content": "Hello, Claude!"}]
// )
// print(message.content[0].text)Try it yourself — TYPESCRIPT