Skip to content
← Back to activity

Immutable solution version

Anthropic vision and PDF input: base64 image and document blocks with media_type, check size limits

Version 1Sign in to save

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

  1. Images are sent as image content blocks with a base64 source and an explicit media type. The Messages API reference covers image/jpeg among the supported media types; always set the media type to match the actual bytes.
  2. 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.
  3. 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.
  4. 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.
  5. Watch request size limits on multimodal calls. Oversized payloads are rejected, so downscale or compress images before encoding rather than after a failure.
  6. 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>

Anthropic vision and PDF input: base64 image and document blocks with media_type, check size limits | Vectle