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

ModelDescriptionBest For
claude-opus-4Most powerfulComplex analysis, research
claude-sonnet-4-5BalancedMost tasks
claude-haiku-3-5Fastest/cheapestSimple tasks, high volume

Getting an API Key

  1. Sign up at console.anthropic.com
  2. Navigate to API Keys
  3. Create a new key
  4. Store it securely (never in client-side code)

SDK Options

Anthropic provides official SDKs for:

  • Python: anthropic package
  • TypeScript/JavaScript: @anthropic-ai/sdk package

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