anthropics / anthropics/anthropic-sdk-ruby

Unsupported document file format

Abierto
#128 0 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
Ruby
Estrellas
369
Forks
74
Merge medio
1 d 22 h
PR fusionados (30 d)
10

Descripción

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

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.