Skip to content

feat(anthropic): add PDF document support for file content blocks#197

Merged
andreynering merged 2 commits intocharmbracelet:mainfrom
Nic-vdwalt:feat/anthropic-pdf-document-support
Apr 22, 2026
Merged

feat(anthropic): add PDF document support for file content blocks#197
andreynering merged 2 commits intocharmbracelet:mainfrom
Nic-vdwalt:feat/anthropic-pdf-document-support

Conversation

@Nic-vdwalt
Copy link
Copy Markdown
Contributor

@Nic-vdwalt Nic-vdwalt commented Apr 9, 2026

Summary

The Anthropic provider's ContentTypeFile handler only supports image/* and text/* MIME types, silently dropping all other file types (including PDFs) with a // TODO: handle other file types comment. The Anthropic API has supported PDF documents via document content blocks since 2024, and the SDK already provides NewDocumentBlock and Base64PDFSourceParam.

This PR:

  • Adds a case file.MediaType == "application/pdf" that creates a document block using Base64PDFSourceParam, with cache control support matching the existing image handling
  • Adds block.OfDocument != nil to hasVisibleUserContent() so messages containing only document blocks aren't incorrectly dropped as "empty"
  • Adds cache control support for text/* document blocks, matching the existing image and PDF behavior (was previously missing)
  • Updates the existing "drop unsupported content" test to use application/zip instead of application/pdf
  • Adds tests verifying PDF and text document content is retained in messages

Test plan

  • go test ./providers/anthropic/... passes
  • Send a PDF file via an application using the Anthropic provider and verify the model receives and responds to the PDF content

…locks

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Nic-vdwalt Nic-vdwalt force-pushed the feat/anthropic-pdf-document-support branch from 03ef73a to 84899e6 Compare April 9, 2026 12:56
Copy link
Copy Markdown
Member

@andreynering andreynering left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Nic-vdwalt 👋

This looks good overall. I'll try to test it once I can.

That said, can you confim to me that you have tested this yourself and ensures that it works?

@Nic-vdwalt
Copy link
Copy Markdown
Contributor Author

Hi @Nic-vdwalt 👋

This looks good overall. I'll try to test it once I can.

That said, can you confim to me that you have tested this yourself and ensures that it works?

Hi @andreynering, thanks for reaching out. Yes, it works.

@andreynering andreynering enabled auto-merge (squash) April 22, 2026 15:04
Copy link
Copy Markdown
Member

@andreynering andreynering left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@andreynering andreynering merged commit 95dcd6e into charmbracelet:main Apr 22, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants