Skip to main content
Back to Resources

man claude-api

A complete reference for integrating Claude into your applications via the Anthropic API.

overview.md

# Claude API Overview

The Claude API is a REST API provided by Anthropic that lets you integrate Claude's intelligence into any application. Whether you are building a customer support bot, a code review tool, a document analyzer, or a fully agentic system, the API gives you direct access to Claude's capabilities.

The API differs from Claude Code (which is a terminal tool for developers) in that it is meant for programmatic integration — you call it from your backend, your scripts, or your services.

If you are new to Claude, start with our Getting Started guide before diving into the API. Once comfortable, this guide covers everything you need to build production-grade applications.

export ANTHROPIC_API_KEY="..."

authentication.md

All API requests require an API key passed in the x-api-key header. Get your key from the Anthropic Console.

Never expose your API key in client-side code or public repositories. Always store it as an environment variable and access it from your server.

.env

# Store your key securely

ANTHROPIC_API_KEY=sk-ant-...

# Never commit this file to git

echo ".env" >> .gitignore

auth-header.ts

// Correct: server-side only

const apiKey = process.env.ANTHROPIC_API_KEY;

// Request header

"x-api-key": apiKey,

"anthropic-version": "2023-06-01",

"content-type": "application/json"

claude models --list

[Most Capable]

claude-opus-4-5

Best for complex reasoning, analysis, and nuanced tasks. Highest intelligence.

[Best Balance]

claude-sonnet-4-5

Excellent performance with faster speed. Ideal for most production use cases.

[Fastest]

claude-haiku-3-5

Near-instant responses. Perfect for high-volume, latency-sensitive applications.

Check docs.anthropic.com/models for the latest model IDs and context window sizes.

curl https://api.anthropic.com/v1/messages

basic-request.ts

// Using the Anthropic TypeScript SDK

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

const client = new Anthropic({

apiKey: process.env.ANTHROPIC_API_KEY,

});

const message = await client.messages.create({

model: "claude-sonnet-4-5",

max_tokens: 1024,

messages: [

{ role: "user", content: "Explain recursion in simple terms." }

],

});

// Access the response

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

response-structure.json

// Response object

{

"id": "msg_01XFDUDYJgAACzvnptvVoYEL",

"type": "message",

"role": "assistant",

"content": [{

"type": "text",

"text": "Recursion is..."

}],

"model": "claude-sonnet-4-5",

"stop_reason": "end_turn",

"usage": { "input_tokens": 12, "output_tokens": 142 }

}

claude --stream

streaming.md

Streaming lets you display Claude's response as it generates, rather than waiting for the full reply. This is essential for chat interfaces and any experience where responsiveness matters.

The API uses Server-Sent Events (SSE) for streaming. The TypeScript SDK handles this with an async iterator pattern.

streaming.ts

// Stream responses token by token

const stream = client.messages.stream({

model: "claude-sonnet-4-5",

max_tokens: 1024,

messages: [{ role: "user", content: prompt }],

});

// Process each chunk as it arrives

for await (const chunk of stream) {

if (chunk.type === "content_block_delta") {

process.stdout.write(chunk.delta.text);

}

}

// Get the final message

const finalMessage = await stream.finalMessage();

claude --tools

tool-use.md

Tool use (also called function calling) lets Claude invoke functions you define. Claude decides when to call a tool, passes the right parameters, and you execute the function — returning the result for Claude to incorporate into its response.

This is the foundation for building agentic applications: web search, database queries, API calls, file operations, and more.

tool-definition.ts

// Define a tool

const tools = [{

name: "get_weather",

description: "Get current weather for a city",

input_schema: {

type: "object",

properties: {

city: { type: "string", description: "City name" }

},

required: ["city"]

}

}];

// Pass tools to the API

const response = await client.messages.create({

model: "claude-sonnet-4-5",

max_tokens: 1024,

tools,

messages: [{ role: "user", content: "What is the weather in Nairobi?" }]

});

claude --system "You are..."

system-prompts.ts

// System prompt sets Claude's behavior

const response = await client.messages.create({

model: "claude-sonnet-4-5",

max_tokens: 1024,

system: "You are a helpful assistant for Kenyan developers. You provide code examples in TypeScript and Python. Always mention community resources at claudekenya.org",

messages: [{ role: "user", content: userMessage }]

});

claude --rate-limits

rate-limits.md

The API enforces rate limits on requests per minute (RPM) and tokens per minute (TPM). Your limits depend on your account tier. When you hit a limit, the API returns a 429 Too Many Requests response.

For production applications, implement exponential backoff with jitter. Start with a 1-second delay, double on each retry, add random jitter, and cap at 60 seconds. See our Production Guide for complete retry logic.

retry.ts

// Exponential backoff with jitter

async function callWithRetry(fn: () => Promise<unknown>, maxRetries = 3) {

for (let i = 0; i <= maxRetries; i++) {

try {

return await fn();

} catch (err: unknown) {

if (err instanceof Anthropic.RateLimitError && i < maxRetries) {

const delay = Math.min(1000 * 2 ** i + Math.random() * 500, 60000);

await new Promise(r => setTimeout(r, delay));

} else throw err;

}

}

}

npm install @anthropic-ai/sdk

sdk-setup

# TypeScript / JavaScript

npm install @anthropic-ai/sdk

# Python

pip install anthropic

cat ./next-steps.md

Have questions or want to share what you built? Join Claude Community Kenya on Discord — our community members help each other troubleshoot API issues daily. Check out upcoming events for live workshops on Claude API development.