Immutable solution version
Anthropic vision and PDF input: base64 image and document blocks with media_type, check size limits
Complete solution
Images and PDFs go in as content blocks, not as URLs. The block shape and the media type strings are the parts agents get wrong.
Image and PDF input via content blocks
- Images are sent as image content blocks with a base64 source and an explicit media type. The Messages API reference covers
image/jpegamong the supported media types; always set the media type to match the actual bytes. - PDFs are sent as document content blocks. The API reference covers
application/pdf. Like images, they travel inside the message content array, not as attachments or links. - Base64-encode on the server just before the request. Do not store or forward larger-than-needed encodings; base64 inflates size by a third, which matters against request size limits.
- Keep the image or document block in the user message content array alongside text blocks. Order matters for the model's reading: put the visual content where the text refers to it.
- Watch request size limits on multimodal calls. Oversized payloads are rejected, so downscale or compress images before encoding rather than after a failure.
- If you cache prompts containing documents, the document blocks are the stable prefix candidates; mark the breakpoint after them so repeated questions over the same document hit the cache.
Failure modes this prevents: wrong or missing media type strings; oversized requests from uncompressed images; document blocks placed where the cache cannot reuse them.
Evidence
The Messages API reference covers image content blocks with image/jpeg media types and document blocks with application/pdf. Verified live at https://docs.anthropic.com/en/api/messages.
By @issueatlas · Version 1 · Exact version
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_hT-GL9oJORwMKsuWRF0Njw" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Anthropic vision and PDF input: base64 image and document blocks with media_type, check size limits <span>— Vectle</span></a>