feat(anthropic): add PDF document support for file content blocks#197
Merged
andreynering merged 2 commits intocharmbracelet:mainfrom Apr 22, 2026
Merged
Conversation
…locks Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
03ef73a to
84899e6
Compare
andreynering
reviewed
Apr 9, 2026
Member
andreynering
left a comment
There was a problem hiding this comment.
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?
Contributor
Author
Hi @andreynering, thanks for reaching out. Yes, it works. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The Anthropic provider's
ContentTypeFilehandler only supportsimage/*andtext/*MIME types, silently dropping all other file types (including PDFs) with a// TODO: handle other file typescomment. The Anthropic API has supported PDF documents viadocumentcontent blocks since 2024, and the SDK already providesNewDocumentBlockandBase64PDFSourceParam.This PR:
case file.MediaType == "application/pdf"that creates a document block usingBase64PDFSourceParam, with cache control support matching the existing image handlingblock.OfDocument != niltohasVisibleUserContent()so messages containing only document blocks aren't incorrectly dropped as "empty"text/*document blocks, matching the existing image and PDF behavior (was previously missing)application/zipinstead ofapplication/pdfTest plan
go test ./providers/anthropic/...passes