【Claude】Request too large / Image too large / Unable to resize / PDF 报错已解决(4合1)
【Claude】Request too large / Image too large / Unable to resize / PDF 报错已解决(4合1)
关键词:Claude Code、Request too large 30MB、Image was too large、Unable to resize image、PDF too large、粘贴大文件、图片尺寸、双 Esc
报错一:Request too large (max 30 MB)
现象
Request too large (max 30 MB). Double press esc to go back and remove or shrink the attached content.根因
这是HTTP 请求体的大小限制(30 MB),和上下文 Token 数限制(Prompt is too long)是两个独立的限制。
触发场景:
- 向 Claude Code 粘贴了超大的文本内容(比如整个大文件的全部内容);
- 拖入了超大的二进制文件;
- 附加了大量图片。
注意:这是字节大小限制,发生在请求发出之前(客户端预检),不会到达 API。
解法
双按 Esc,回退到添加超大内容之前的那一轮,然后改用以下方式:
# 不要粘贴文件内容,按路径引用 请帮我分析这个文件:/Users/你/project/large-file.ts按路径引用时,Claude Code 会分块读取文件,而不是把整个内容一次性放进请求体。
报错二:Image was too large
现象
Image was too large. Double press esc to go back and try again with a smaller image. API Error: 400 ... image dimensions exceed max allowed sizeAPI 的图片限制
| 场景 | 最长边上限 |
|---|---|
| 单张图片(上下文里图片少) | 8000 像素 |
| 上下文中有多张图片时 | 2000 像素(每张) |
v2.1.142+ 的自动处理
在 v2.1.142 及以后,Claude Code 会自动把无法处理的图片替换为文本占位符并重试,后续消息通常成功。这个错误消息在新版本里基本只会闪一下。
v2.1.142 之前的旧版本:粘贴的图片可能一直留在对话里,每次请求都报这个错。解法:双按 Esc,回退到添加图片之前的那一轮。
解法
在粘贴之前先缩小图片:
# macOS:用 sips 缩小 sips -Z 2000 input.png --out output.png # 最长边缩到 2000px # 或用 ImageMagick convert input.png -resize 2000x2000\> output.png拍屏幕截图时,截相关区域而不是整个屏幕;或者用压缩率更高的 JPEG 代替 PNG。
报错三:Unable to resize image
现象(多种变体)
Unable to resize image — image processing is unavailable and dimensions could not be read from the file header. Please convert the image to PNG, JPEG, GIF, or WebP. Unable to resize image — dimensions exceed the 2000x2000px limit and image processing failed. Please resize the image to reduce its pixel dimensions. Unable to resize image (… raw, … base64). The image exceeds the … API limit and compression failed. Please resize the image manually or use a smaller image. Unable to resize image — could not verify image dimensions are within the 2000x2000px API limit.根因
Claude Code 通常会自动调整大型图片以适应 API 限制,但本机图像处理器(native image processor)加载失败或返回错误时,自动调整就无法完成。
四种变体分别对应:
- 格式不被支持(
dimensions could not be read):图片是不常见的格式(如 BMP、TIFF、WebP 变种),无法读取尺寸; - 超限且处理失败:尺寸超过 2000×2000,但压缩失败;
- 大小超 API 限制且压缩失败:文件字节数超限;
- 无法验证尺寸:不确定是否超限,因此拒绝。
解法
根据消息内容对号入座:
"Please convert the image to PNG, JPEG, GIF, or WebP":
convert input.bmp output.png"dimensions exceed the 2000x2000px limit": 手动缩小到 2000px 以内后重新粘贴。
无法验证尺寸:也转成标准格式(PNG/JPEG)后重试。
报错四:PDF too large / password protected / not valid
现象
PDF too large (max 100 pages, 32 MB). Try splitting it or extracting text first. PDF is password protected. Try removing protection or extracting text first. The PDF file was not valid. Try converting to a different format first.API 对 PDF 的限制
| 限制维度 | 上限 |
|---|---|
| 页数 | 100 页 |
| 文件大小 | 32 MB |
| 密码保护 | 不支持 |
解法
PDF 太大(超过 100 页 / 32 MB):
不要直接附加整个 PDF,用 Claude Code 的 Read 工具按页范围读取:
请用 Read 工具读取这个 PDF 的第 1 到 50 页:/path/to/large.pdf或者先提取文本:
# 使用 pdftotext pdftotext large.pdf output.txt再按路径引用提取出来的output.txt。
PDF 有密码:
先在源应用里导出为无密码版本,或用工具去除密码(需要有合法权限)。
PDF 无效:
在源应用(如 Adobe Acrobat、macOS 预览)里重新导出,或转成图片再处理:
convert -density 150 document.pdf document-%d.jpg总结对照
| 报错 | 限制类型 | 核心解法 |
|---|---|---|
| Request too large (30 MB) | HTTP 请求体字节数 | 双 Esc 回退 + 按路径引用代替粘贴 |
| Image too large | 图片像素尺寸 | 缩至 2000px 以内 |
| Unable to resize image | 图片格式/尺寸验证失败 | 转为 PNG/JPEG + 手动缩小 |
| PDF too large / protected / invalid | PDF 页数/大小/密码/格式 | 按范围读取 / pdftotext / 重新导出 |
所有这类错误的恢复方式都一样:双按 Esc 回退到添加大内容之前,再换一种"轻量"的方式引用内容。
参考:Claude Code 官方《错误参考》"请求错误"章节。
