Skip to content

"Does not match" error when using a file in messages #127

@dan-jensen

Description

@dan-jensen

Problem

When using a file in messages, this gem causes the Anthropic API to respond with an error: "messages.0.content.1.document.source: Input tag 'file' found using 'type' does not match any of the expected tags: 'base64', 'content', 'text', 'url'". This happens because the API does not support file sources unless the required anthropic-beta header is provided: anthropic-beta: files-api-2025-04-14. This was confirmed by adding the missing header to a gem request via the extra_headers option, which solved the problem.

Proposal

The messages requests should always include the anthropic-beta header, like the the files requests already do.

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.document.source: Input tag 'file' found using 'type' does not match any of the expected tags: 'base64', 'content', 'text', 'url'"
    }
  }
}

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