source dump of claude code
at main 94 lines 3.4 kB view raw
1/** 2 * Anthropic API Limits 3 * 4 * These constants define server-side limits enforced by the Anthropic API. 5 * Keep this file dependency-free to prevent circular imports. 6 * 7 * Last verified: 2025-12-22 8 * Source: api/api/schemas/messages/blocks/ and api/api/config.py 9 * 10 * Future: See issue #13240 for dynamic limits fetching from server. 11 */ 12 13// ============================================================================= 14// IMAGE LIMITS 15// ============================================================================= 16 17/** 18 * Maximum base64-encoded image size (API enforced). 19 * The API rejects images where the base64 string length exceeds this value. 20 * Note: This is the base64 length, NOT raw bytes. Base64 increases size by ~33%. 21 */ 22export const API_IMAGE_MAX_BASE64_SIZE = 5 * 1024 * 1024 // 5 MB 23 24/** 25 * Target raw image size to stay under base64 limit after encoding. 26 * Base64 encoding increases size by 4/3, so we derive the max raw size: 27 * raw_size * 4/3 = base64_size → raw_size = base64_size * 3/4 28 */ 29export const IMAGE_TARGET_RAW_SIZE = (API_IMAGE_MAX_BASE64_SIZE * 3) / 4 // 3.75 MB 30 31/** 32 * Client-side maximum dimensions for image resizing. 33 * 34 * Note: The API internally resizes images larger than 1568px (source: 35 * encoding/full_encoding.py), but this is handled server-side and doesn't 36 * cause errors. These client-side limits (2000px) are slightly larger to 37 * preserve quality when beneficial. 38 * 39 * The API_IMAGE_MAX_BASE64_SIZE (5MB) is the actual hard limit that causes 40 * API errors if exceeded. 41 */ 42export const IMAGE_MAX_WIDTH = 2000 43export const IMAGE_MAX_HEIGHT = 2000 44 45// ============================================================================= 46// PDF LIMITS 47// ============================================================================= 48 49/** 50 * Maximum raw PDF file size that fits within the API request limit after encoding. 51 * The API has a 32MB total request size limit. Base64 encoding increases size by 52 * ~33% (4/3), so 20MB raw → ~27MB base64, leaving room for conversation context. 53 */ 54export const PDF_TARGET_RAW_SIZE = 20 * 1024 * 1024 // 20 MB 55 56/** 57 * Maximum number of pages in a PDF accepted by the API. 58 */ 59export const API_PDF_MAX_PAGES = 100 60 61/** 62 * Size threshold above which PDFs are extracted into page images 63 * instead of being sent as base64 document blocks. This applies to 64 * first-party API only; non-first-party always uses extraction. 65 */ 66export const PDF_EXTRACT_SIZE_THRESHOLD = 3 * 1024 * 1024 // 3 MB 67 68/** 69 * Maximum PDF file size for the page extraction path. PDFs larger than 70 * this are rejected to avoid processing extremely large files. 71 */ 72export const PDF_MAX_EXTRACT_SIZE = 100 * 1024 * 1024 // 100 MB 73 74/** 75 * Max pages the Read tool will extract in a single call with the pages parameter. 76 */ 77export const PDF_MAX_PAGES_PER_READ = 20 78 79/** 80 * PDFs with more pages than this get the reference treatment on @ mention 81 * instead of being inlined into context. 82 */ 83export const PDF_AT_MENTION_INLINE_THRESHOLD = 10 84 85// ============================================================================= 86// MEDIA LIMITS 87// ============================================================================= 88 89/** 90 * Maximum number of media items (images + PDFs) allowed per API request. 91 * The API rejects requests exceeding this limit with a confusing error. 92 * We validate client-side to provide a clear error message. 93 */ 94export const API_MAX_MEDIA_PER_REQUEST = 100