API Reference
Complete reference for the Claude API and SDK usage
title: API Reference description: Complete reference for the Claude API and SDK usage
The Claude API provides programmatic access to Claude's capabilities. This reference covers authentication, endpoints, and best practices for integrating Claude into your applications.
Overview
The Claude API uses a REST architecture with JSON request and response bodies. All requests require authentication via API key.
Base URL
API Versions
| Version | Status | Notes |
|---------|--------|-------|
| 2024-01-01 | Current | Latest stable version |
| 2023-06-01 | Supported | Previous stable version |
| 2023-01-01 | Deprecated | Will be removed |
Always specify the version in your requests:
Quick Start
Basic Request
Response Format
Available Models
| Model | ID | Best For |
|-------|-----|----------|
| Claude Opus 4.5 | claude-opus-4-5-20251101 | Complex reasoning, research |
| Claude Sonnet 4 | claude-sonnet-4-20250514 | Balanced performance |
| Claude Haiku 3.5 | claude-haiku-3-5-20241022 | Fast, simple tasks |
Core Endpoints
Messages API
The primary endpoint for conversations:
Request Body:
Parameters:
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| model | string | Yes | Model ID to use |
| messages | array | Yes | Conversation messages |
| max_tokens | integer | Yes | Maximum response length |
| system | string | No | System prompt |
| temperature | float | No | Randomness (0-1) |
| stream | boolean | No | Enable streaming |
Streaming Responses
For real-time responses, enable streaming:
Stream events:
SDKs
Python
TypeScript/JavaScript
Error Handling
Error Response Format
Common Error Types
| Type | HTTP Status | Description |
|------|-------------|-------------|
| invalid_request_error | 400 | Invalid parameters |
| authentication_error | 401 | Invalid API key |
| permission_error | 403 | Insufficient permissions |
| not_found_error | 404 | Resource not found |
| rate_limit_error | 429 | Too many requests |
| api_error | 500 | Server error |
| overloaded_error | 529 | API overloaded |
Retry Strategy
Rate Limits
Rate limits vary by tier:
| Tier | Requests/min | Tokens/min | |------|--------------|------------| | Free | 5 | 20,000 | | Build | 50 | 100,000 | | Scale | 1,000 | 400,000 |
Check headers for current usage:
Best Practices
1. Use System Prompts
Set consistent behavior with system prompts:
2. Manage Context Length
Monitor token usage and truncate when needed: