Skip to content

Unsupported document file format #128

@dan-jensen

Description

@dan-jensen

Problem

After getting past the "Does not match" error when using a file in messages, there is another error when 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 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 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."
    }
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions