Skip to main content

API Reference

1 min read

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

Text

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:

Bash

Quick Start

Basic Request

Bash

Response Format

JSON

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:

Text

Request Body:

JSON

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:

Bash

Stream events:

Text

SDKs

Python

Python

TypeScript/JavaScript

TypeScript

Error Handling

Error Response Format

JSON

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

TypeScript

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:

Text

Best Practices

1. Use System Prompts

Set consistent behavior with system prompts:

JSON

2. Manage Context Length

Monitor token usage and truncate when needed:

TypeScript

3. Handle Streaming Properly

TypeScript

Next Steps

Generated with AI using Claude AI by Anthropic

Model: Claude Opus 4.5 · Generated: 2025-12-20 · Build: v1.21.0-75762dc

Edit this page on GitHub··

Discussion

0/2000

Comments are reviewed before being published