apiLimits.ts
constants/apiLimits.ts
95
Lines
3443
Bytes
11
Exports
0
Imports
10
Keywords
What this is
This page documents one file from the repository and includes its full source so you can read it without leaving the docs site.
Beginner explanation
This file is one piece of the larger system. Its name, directory, imports, and exports show where it fits. Start by reading the exports and related files first.
How it is used
Start from the exports list and related files. Those are the easiest clues for where this file fits into the system.
Expert explanation
Architecturally, this file intersects with integrations. It contains 95 lines, 0 detected imports, and 11 detected exports.
Important relationships
Detected exports
API_IMAGE_MAX_BASE64_SIZEIMAGE_TARGET_RAW_SIZEIMAGE_MAX_WIDTHIMAGE_MAX_HEIGHTPDF_TARGET_RAW_SIZEAPI_PDF_MAX_PAGESPDF_EXTRACT_SIZE_THRESHOLDPDF_MAX_EXTRACT_SIZEPDF_MAX_PAGES_PER_READPDF_AT_MENTION_INLINE_THRESHOLDAPI_MAX_MEDIA_PER_REQUEST
Keywords
sizebase64limitsmaximumlimitencodingimageimagespagespdfs
Detected imports
- No import paths detected.
Source notes
This page embeds the full file contents. Small or leaf files are still indexed honestly instead of being over-explained.
Full source
/**
* Anthropic API Limits
*
* These constants define server-side limits enforced by the Anthropic API.
* Keep this file dependency-free to prevent circular imports.
*
* Last verified: 2025-12-22
* Source: api/api/schemas/messages/blocks/ and api/api/config.py
*
* Future: See issue #13240 for dynamic limits fetching from server.
*/
// =============================================================================
// IMAGE LIMITS
// =============================================================================
/**
* Maximum base64-encoded image size (API enforced).
* The API rejects images where the base64 string length exceeds this value.
* Note: This is the base64 length, NOT raw bytes. Base64 increases size by ~33%.
*/
export const API_IMAGE_MAX_BASE64_SIZE = 5 * 1024 * 1024 // 5 MB
/**
* Target raw image size to stay under base64 limit after encoding.
* Base64 encoding increases size by 4/3, so we derive the max raw size:
* raw_size * 4/3 = base64_size → raw_size = base64_size * 3/4
*/
export const IMAGE_TARGET_RAW_SIZE = (API_IMAGE_MAX_BASE64_SIZE * 3) / 4 // 3.75 MB
/**
* Client-side maximum dimensions for image resizing.
*
* Note: The API internally resizes images larger than 1568px (source:
* encoding/full_encoding.py), but this is handled server-side and doesn't
* cause errors. These client-side limits (2000px) are slightly larger to
* preserve quality when beneficial.
*
* The API_IMAGE_MAX_BASE64_SIZE (5MB) is the actual hard limit that causes
* API errors if exceeded.
*/
export const IMAGE_MAX_WIDTH = 2000
export const IMAGE_MAX_HEIGHT = 2000
// =============================================================================
// PDF LIMITS
// =============================================================================
/**
* Maximum raw PDF file size that fits within the API request limit after encoding.
* The API has a 32MB total request size limit. Base64 encoding increases size by
* ~33% (4/3), so 20MB raw → ~27MB base64, leaving room for conversation context.
*/
export const PDF_TARGET_RAW_SIZE = 20 * 1024 * 1024 // 20 MB
/**
* Maximum number of pages in a PDF accepted by the API.
*/
export const API_PDF_MAX_PAGES = 100
/**
* Size threshold above which PDFs are extracted into page images
* instead of being sent as base64 document blocks. This applies to
* first-party API only; non-first-party always uses extraction.
*/
export const PDF_EXTRACT_SIZE_THRESHOLD = 3 * 1024 * 1024 // 3 MB
/**
* Maximum PDF file size for the page extraction path. PDFs larger than
* this are rejected to avoid processing extremely large files.
*/
export const PDF_MAX_EXTRACT_SIZE = 100 * 1024 * 1024 // 100 MB
/**
* Max pages the Read tool will extract in a single call with the pages parameter.
*/
export const PDF_MAX_PAGES_PER_READ = 20
/**
* PDFs with more pages than this get the reference treatment on @ mention
* instead of being inlined into context.
*/
export const PDF_AT_MENTION_INLINE_THRESHOLD = 10
// =============================================================================
// MEDIA LIMITS
// =============================================================================
/**
* Maximum number of media items (images + PDFs) allowed per API request.
* The API rejects requests exceeding this limit with a confusing error.
* We validate client-side to provide a clear error message.
*/
export const API_MAX_MEDIA_PER_REQUEST = 100