anthropics / anthropics/anthropic-sdk-ruby

Unsupported document file format

Đang mở
#128 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Ruby
Star
369
Fork
74
Merge trung bình
1 ngày 22 giờ
Pull request đã merge (30 ngày)
10

Mô tả

# 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."
}
}
}
```

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.