anthropics / anthropics/anthropic-sdk-ruby
Unsupported document file format
- Lingua principale
- Ruby
- Stelle
- 369
- Fork
- 74
- Merge medio
- 1g 22h
- PR unite (30g)
- 10
Descrizione
# Problem
After getting past the ["Does not match" error when using a file in messages](https://github.com/anthropics/anthropic-sdk-ruby/issues/127), there is another error when [using a file in messages](https://docs.anthropic.com/en/docs/build-with-claude/files#using-a-file-in-messages): "Unsupported document file format: application/octet-stream. Only PDF and plaintext documents are supported." That is caused by this gem [defaulting to content-type `application/octet-stream`](https://github.com/anthropics/anthropic-sdk-ruby/blob/9b9be231a1677c073f1bd6a341f15b56f9a6ec54/lib/anthropic/internal/util.rb#L511) when uploading files.
The workaround is to pass an `Anthropic::FilePart` object with an accurate `content_type`.
# Additional details
The Anthropic API docs for [uploading a file](https://docs.anthropic.com/en/docs/build-with-claude/files#uploading-a-file) show a cURL example with no content-type, but that's because cURL automatically sets that header. The other examples (Python and TypeScript) show the content-type being set explicitly. In other words, an accurate content-type must be provided.
# Proposal
Require that `content_type` is always passed as an argument:
- The `Anthropic::FilePart` should require a `content_type` argument.
- Either the `files.upload()` method should require a `content_type` argument as well, or it should only accept `Anthropic::FilePart` objects.
# Example request
```
message = anthropic.messages.create(
max_tokens: 1024,
messages: [
{
role: "user",
content: [
{
type: "text",
text: "Hello Claude"
},
{
type: "document",
source: {
type: "file",
file_id: "file_011CSoYoHF8saWZ6CPh55555"
}
]
}
],
model: :"claude-sonnet-4-20250514"
)
```
# Example response
```
{
"url": "https://api.anthropic.com/v1/messages",
"status": 400,
"body": {
"type": "error",
"error": {
"type": "invalid_request_error",
"message": "messages.0.content.1.source: Unsupported document file format: application/octet-stream. Only PDF and plaintext documents are supported."
}
}
}
```
Guida per i contributori
Apri la guida per i contributori
Valutazione
Questa issue non è ancora stata valutata.