anthropics / anthropics/anthropic-sdk-ruby

Unsupported document file format

Ouverte
#128 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
Langage dominant
Ruby
Étoiles
369
Forks
74
Merge moyen
1 j 22 h
PR mergées (30 j)
10

Description

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

Guide de contribution

Ouvrir le guide de contribution

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.